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 setSidePadding(qreal width
);
54 qreal
sidePadding() 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
, qreal currentWidth
, qreal previousWidth
);
67 void sidePaddingChanged(qreal width
);
70 * Is emitted if the user has released the mouse button after adjusting the
71 * width of a visible role.
73 void columnWidthChangeFinished(const QByteArray
&role
, qreal currentWidth
);
76 * Is emitted if the position of the column has been changed.
78 void columnMoved(const QByteArray
&role
, int currentIndex
, int previousIndex
);
81 * Is emitted if the user has changed the sort order by clicking on a
82 * header item. The sort order of the model has already been adjusted to
83 * the current sort order. Note that no signal will be emitted if the
84 * sort order of the model has been changed without user interaction.
86 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
89 * Is emitted if the user has changed the sort role by clicking on a
90 * header item. The sort role of the model has already been adjusted to
91 * the current sort role. Note that no signal will be emitted if the
92 * sort role of the model has been changed without user interaction.
94 void sortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
96 void columnUnHovered(int columnIndex
);
97 void columnHovered(int columnIndex
);
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
¤t
, const QByteArray
&previous
);
110 void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
118 void paintRole(QPainter
*painter
, const QByteArray
&role
, const QRectF
&rect
, int orderIndex
, QWidget
*widget
= nullptr) const;
120 void updatePressedRoleIndex(const QPointF
&pos
);
121 void updateHoveredIndex(const QPointF
&pos
);
122 int roleIndexAt(const QPointF
&pos
) const;
123 bool isAboveRoleGrip(const QPointF
&pos
, int roleIndex
) const;
124 bool isAbovePaddingGrip(const QPointF
&pos
, PaddingGrip paddingGrip
) const;
127 * Creates a pixmap of the role with the index \a roleIndex that is shown
128 * during moving a role.
130 QPixmap
createRolePixmap(int roleIndex
) const;
133 * @return Target index of the currently moving visible role based on the current
134 * state of m_movingRole.
136 int targetOfMovingRole() const;
139 * @return x-position of the left border of the role \a role.
141 qreal
roleXPosition(const QByteArray
&role
) const;
144 enum RoleOperation
{ NoRoleOperation
, ResizeRoleOperation
, ResizePaddingColumnOperation
, MoveRoleOperation
};
146 bool m_automaticColumnResizing
;
147 KItemModelBase
*m_model
;
150 QList
<QByteArray
> m_columns
;
151 QHash
<QByteArray
, qreal
> m_columnWidths
;
152 QHash
<QByteArray
, qreal
> m_preferredColumnWidths
;
155 int m_pressedRoleIndex
;
156 RoleOperation m_roleOperation
;
157 QPointF m_pressedMousePos
;
165 MovingRole m_movingRole
;