2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KITEMLISTGROUPHEADER_H
8 #define KITEMLISTGROUPHEADER_H
10 #include "dolphin_export.h"
11 #include "kitemviews/kitemliststyleoption.h"
14 #include <QGraphicsWidget>
20 * @brief Base class for group headers.
22 * Draws a default header background. Derived classes must reimplement
23 * the method paint() and draw the role within the given roleBounds() with
24 * the color roleColor().
26 class DOLPHIN_EXPORT KItemListGroupHeader
: public QGraphicsWidget
31 explicit KItemListGroupHeader(QGraphicsWidget
*parent
= nullptr);
32 ~KItemListGroupHeader() override
;
34 void setRole(const QByteArray
&role
);
35 QByteArray
role() const;
37 void setData(const QVariant
&data
);
38 QVariant
data() const;
40 void setStyleOption(const KItemListStyleOption
&option
);
41 const KItemListStyleOption
&styleOption() const;
44 * Sets the scroll orientation that is used by the KItemListView.
45 * This allows the group header to use a modified look dependent
48 void setScrollOrientation(Qt::Orientation orientation
);
49 Qt::Orientation
scrollOrientation() const;
51 void setItemIndex(int index
);
52 int itemIndex() const;
54 void paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
= nullptr) override
;
57 virtual void paintRole(QPainter
*painter
, const QRectF
&roleBounds
, const QColor
&color
) = 0;
58 virtual void paintSeparator(QPainter
*painter
, const QColor
&color
) = 0;
61 * Is called after the role has been changed and allows the derived class
62 * to react on this change.
64 virtual void roleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
67 * Is called after the role has been changed and allows the derived class
68 * to react on this change.
70 virtual void dataChanged(const QVariant
¤t
, const QVariant
&previous
);
73 * Is called after the style option has been changed and allows the derived class
74 * to react on this change.
76 virtual void styleOptionChanged(const KItemListStyleOption
¤t
, const KItemListStyleOption
&previous
);
79 * Is called after the scroll orientation has been changed and allows the derived class
80 * to react on this change.
82 virtual void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
85 * Is called after the item index has been changed and allows the derived class to react on
88 virtual void itemIndexChanged(int current
, int previous
);
90 void resizeEvent(QGraphicsSceneResizeEvent
*event
) override
;
92 virtual QPalette::ColorRole
normalTextColorRole() const;
93 virtual QPalette::ColorRole
normalBaseColorRole() const;
99 static QColor
mixedColor(const QColor
&c1
, const QColor
&c2
, int c1Percent
= 50);
101 QColor
textColor() const;
102 QColor
baseColor() const;
108 KItemListStyleOption m_styleOption
;
109 Qt::Orientation m_scrollOrientation
;
112 QColor m_separatorColor
;