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 KITEMLISTHEADER_H
21 #define KITEMLISTHEADER_H
23 #include <libdolphin_export.h>
24 #include <QGraphicsWidget>
31 * @brief Header for KItemListView that shows the currently used roles.
33 class LIBDOLPHINPRIVATE_EXPORT KItemListHeader
: public QGraphicsWidget
38 KItemListHeader(QGraphicsWidget
* parent
= 0);
39 virtual ~KItemListHeader();
41 void setModel(KItemModelBase
* model
);
42 KItemModelBase
* model() const;
44 void setVisibleRoles(const QList
<QByteArray
>& roles
);
45 QList
<QByteArray
> visibleRoles() const;
47 void setVisibleRolesWidths(const QHash
<QByteArray
, qreal
> rolesWidths
);
48 QHash
<QByteArray
, qreal
> visibleRolesWidths() const;
50 qreal
minimumRoleWidth() const;
52 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
56 * Is emitted if the width of a visible role has been adjusted by the user with the mouse
57 * (no signal is emitted if KItemListHeader::setVisibleRoles() is invoked).
59 void visibleRoleWidthChanged(const QByteArray
& role
,
64 * Is emitted if the user has changed the sort order by clicking on a
65 * header item. The sort order of the model has already been adjusted to
66 * the current sort order. Note that no signal will be emitted if the
67 * sort order of the model has been changed without user interaction.
69 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
72 * Is emitted if the user has changed the sort role by clicking on a
73 * header item. The sort role of the model has already been adjusted to
74 * the current sort role. Note that no signal will be emitted if the
75 * sort role of the model has been changed without user interaction.
77 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
80 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
81 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent
* event
);
82 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
83 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent
* event
);
84 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent
* event
);
85 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent
* event
);
88 void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
89 void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
92 void paintRole(QPainter
* painter
, const QByteArray
& role
, const QRectF
& rect
, int orderIndex
);
94 void updatePressedRoleIndex(const QPointF
& pos
);
95 void updateHoveredRoleIndex(const QPointF
& pos
);
96 int roleIndexAt(const QPointF
& pos
) const;
97 bool isAboveRoleGrip(const QPointF
& pos
, int roleIndex
) const;
107 KItemModelBase
* m_model
;
108 QList
<QByteArray
> m_visibleRoles
;
109 QHash
<QByteArray
, qreal
> m_visibleRolesWidths
;
111 int m_hoveredRoleIndex
;
112 int m_pressedRoleIndex
;
113 RoleOperation m_roleOperation
;
114 QPointF m_pressedMousePos
;