1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef KITEMLISTHEADERWIDGET_H
21 #define KITEMLISTHEADERWIDGET_H
23 #include "libdolphin_export.h"
24 #include <QGraphicsWidget>
31 * @brief Widget the implements the header for KItemListView showing the currently used roles.
33 * The widget is an internal API, the user of KItemListView may only access the
34 * class KItemListHeader.
36 class LIBDOLPHINPRIVATE_EXPORT KItemListHeaderWidget
: public QGraphicsWidget
41 KItemListHeaderWidget(QGraphicsWidget
* parent
= 0);
42 virtual ~KItemListHeaderWidget();
44 void setModel(KItemModelBase
* model
);
45 KItemModelBase
* model() const;
47 void setAutomaticColumnResizing(bool automatic
);
48 bool automaticColumnResizing() const;
50 void setColumns(const QList
<QByteArray
>& roles
);
51 QList
<QByteArray
> columns() const;
53 void setColumnWidth(const QByteArray
& role
, qreal width
);
54 qreal
columnWidth(const QByteArray
& role
) const;
57 * Sets the column-width that is required to show the role unclipped.
59 void setPreferredColumnWidth(const QByteArray
& role
, qreal width
);
60 qreal
preferredColumnWidth(const QByteArray
& role
) const;
62 void setOffset(qreal offset
);
65 qreal
minimumColumnWidth() const;
67 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
71 * Is emitted if the width of a visible role has been adjusted by the user with the mouse
72 * (no signal is emitted if KItemListHeader::setVisibleRoleWidth() is invoked).
74 void columnWidthChanged(const QByteArray
& role
,
79 * Is emitted if the position of the column has been changed.
81 void columnMoved(const QByteArray
& role
, int currentIndex
, int previousIndex
);
84 * Is emitted if the user has changed the sort order by clicking on a
85 * header item. The sort order of the model has already been adjusted to
86 * the current sort order. Note that no signal will be emitted if the
87 * sort order of the model has been changed without user interaction.
89 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
92 * Is emitted if the user has changed the sort role by clicking on a
93 * header item. The sort role of the model has already been adjusted to
94 * the current sort role. Note that no signal will be emitted if the
95 * sort role of the model has been changed without user interaction.
97 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
100 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
101 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent
* event
);
102 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
103 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent
* event
);
104 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent
* event
);
105 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent
* event
);
106 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent
* event
);
109 void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
110 void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
113 void paintRole(QPainter
* painter
,
114 const QByteArray
& role
,
117 QWidget
* widget
= 0) const;
119 void updatePressedRoleIndex(const QPointF
& pos
);
120 void updateHoveredRoleIndex(const QPointF
& pos
);
121 int roleIndexAt(const QPointF
& pos
) const;
122 bool isAboveRoleGrip(const QPointF
& pos
, int roleIndex
) const;
125 * Creates a pixmap of the role with the index \a roleIndex that is shown
126 * during moving a role.
128 QPixmap
createRolePixmap(int roleIndex
) const;
131 * @return Target index of the currently moving visible role based on the current
132 * state of m_movingRole.
134 int targetOfMovingRole() const;
137 * @return x-position of the left border of the role \a role.
139 qreal
roleXPosition(const QByteArray
& role
) const;
149 bool m_automaticColumnResizing
;
150 KItemModelBase
* m_model
;
152 QList
<QByteArray
> m_columns
;
153 QHash
<QByteArray
, qreal
> m_columnWidths
;
154 QHash
<QByteArray
, qreal
> m_preferredColumnWidths
;
156 int m_hoveredRoleIndex
;
157 int m_pressedRoleIndex
;
158 RoleOperation m_roleOperation
;
159 QPointF m_pressedMousePos
;