2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KITEMLISTHEADERWIDGET_H
8 #define KITEMLISTHEADERWIDGET_H
10 #include "dolphin_export.h"
12 #include <QGraphicsWidget>
19 * @brief Widget the implements the header for KItemListView showing the currently used roles.
21 * The widget is an internal API, the user of KItemListView may only access the
22 * class KItemListHeader.
24 class DOLPHIN_EXPORT KItemListHeaderWidget
: public QGraphicsWidget
29 explicit KItemListHeaderWidget(QGraphicsWidget
* parent
= nullptr);
30 ~KItemListHeaderWidget() override
;
32 void setModel(KItemModelBase
* model
);
33 KItemModelBase
* model() const;
35 void setAutomaticColumnResizing(bool automatic
);
36 bool automaticColumnResizing() const;
38 void setColumns(const QList
<QByteArray
>& roles
);
39 QList
<QByteArray
> columns() const;
41 void setColumnWidth(const QByteArray
& role
, qreal width
);
42 qreal
columnWidth(const QByteArray
& role
) const;
45 * Sets the column-width that is required to show the role unclipped.
47 void setPreferredColumnWidth(const QByteArray
& role
, qreal width
);
48 qreal
preferredColumnWidth(const QByteArray
& role
) const;
50 void setOffset(qreal offset
);
53 void setLeadingPadding(qreal width
);
54 qreal
leadingPadding() const;
56 qreal
minimumColumnWidth() const;
58 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
62 * Is emitted if the width of a visible role has been adjusted by the user with the mouse
63 * (no signal is emitted if KItemListHeader::setVisibleRoleWidth() is invoked).
65 void columnWidthChanged(const QByteArray
& role
,
69 void leadingPaddingChanged(qreal width
);
72 * Is emitted if the user has released the mouse button after adjusting the
73 * width of a visible role.
75 void columnWidthChangeFinished(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 void mousePressEvent(QGraphicsSceneMouseEvent
* event
) override
;
101 void mouseReleaseEvent(QGraphicsSceneMouseEvent
* event
) override
;
102 void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
) override
;
103 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent
* event
) override
;
104 void hoverEnterEvent(QGraphicsSceneHoverEvent
* event
) override
;
105 void hoverLeaveEvent(QGraphicsSceneHoverEvent
* event
) override
;
106 void hoverMoveEvent(QGraphicsSceneHoverEvent
* event
) override
;
109 void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
110 void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
120 void paintRole(QPainter
* painter
,
121 const QByteArray
& role
,
124 QWidget
* widget
= nullptr) const;
126 void updatePressedRoleIndex(const QPointF
& pos
);
127 void updateHoveredRoleIndex(const QPointF
& pos
);
128 int roleIndexAt(const QPointF
& pos
) const;
129 bool isAboveRoleGrip(const QPointF
& pos
, int roleIndex
) const;
130 bool isAbovePaddingGrip(const QPointF
& pos
, PaddingGrip paddingGrip
) const;
133 * Creates a pixmap of the role with the index \a roleIndex that is shown
134 * during moving a role.
136 QPixmap
createRolePixmap(int roleIndex
) const;
139 * @return Target index of the currently moving visible role based on the current
140 * state of m_movingRole.
142 int targetOfMovingRole() const;
145 * @return x-position of the left border of the role \a role.
147 qreal
roleXPosition(const QByteArray
& role
) const;
154 ResizeLeadingColumnOperation
,
158 bool m_automaticColumnResizing
;
159 KItemModelBase
* m_model
;
161 qreal m_leadingPadding
;
162 QList
<QByteArray
> m_columns
;
163 QHash
<QByteArray
, qreal
> m_columnWidths
;
164 QHash
<QByteArray
, qreal
> m_preferredColumnWidths
;
166 int m_hoveredRoleIndex
;
167 int m_pressedRoleIndex
;
168 RoleOperation m_roleOperation
;
169 QPointF m_pressedMousePos
;