]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistgroupheader.h
Merge branch 'release/21.04'
[dolphin.git] / src / kitemviews / kitemlistgroupheader.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KITEMLISTGROUPHEADER_H
8 #define KITEMLISTGROUPHEADER_H
9
10 #include "dolphin_export.h"
11 #include "kitemviews/kitemliststyleoption.h"
12
13 #include <QByteArray>
14 #include <QGraphicsWidget>
15 #include <QVariant>
16
17 class KItemListView;
18
19 /**
20 * @brief Base class for group headers.
21 *
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().
25 */
26 class DOLPHIN_EXPORT KItemListGroupHeader : public QGraphicsWidget
27 {
28 Q_OBJECT
29
30 public:
31 explicit KItemListGroupHeader(QGraphicsWidget* parent = nullptr);
32 ~KItemListGroupHeader() override;
33
34 void setRole(const QByteArray& role);
35 QByteArray role() const;
36
37 void setData(const QVariant& data);
38 QVariant data() const;
39
40 void setStyleOption(const KItemListStyleOption& option);
41 const KItemListStyleOption& styleOption() const;
42
43 /**
44 * Sets the scroll orientation that is used by the KItemListView.
45 * This allows the group header to use a modified look dependent
46 * on the orientation.
47 */
48 void setScrollOrientation(Qt::Orientation orientation);
49 Qt::Orientation scrollOrientation() const;
50
51 void setItemIndex(int index);
52 int itemIndex() const;
53
54 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
55
56 protected:
57 virtual void paintRole(QPainter* painter, const QRectF& roleBounds, const QColor& color) = 0;
58 virtual void paintSeparator(QPainter* painter, const QColor& color) = 0;
59
60 /**
61 * Is called after the role has been changed and allows the derived class
62 * to react on this change.
63 */
64 virtual void roleChanged(const QByteArray& current, const QByteArray& previous);
65
66 /**
67 * Is called after the role has been changed and allows the derived class
68 * to react on this change.
69 */
70 virtual void dataChanged(const QVariant& current, const QVariant& previous);
71
72 /**
73 * Is called after the style option has been changed and allows the derived class
74 * to react on this change.
75 */
76 virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
77
78 /**
79 * Is called after the scroll orientation has been changed and allows the derived class
80 * to react on this change.
81 */
82 virtual void scrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous);
83
84 /**
85 * Is called after the item index has been changed and allows the derived class to react on
86 * this change.
87 */
88 virtual void itemIndexChanged(int current, int previous);
89
90 void resizeEvent(QGraphicsSceneResizeEvent* event) override;
91
92 virtual QPalette::ColorRole normalTextColorRole() const;
93 virtual QPalette::ColorRole normalBaseColorRole() const;
94
95 private:
96 void updateCache();
97
98 static QColor mixedColor(const QColor& c1, const QColor& c2, int c1Percent = 50);
99
100 QColor textColor() const;
101 QColor baseColor() const;
102
103 private:
104 bool m_dirtyCache;
105 QByteArray m_role;
106 QVariant m_data;
107 KItemListStyleOption m_styleOption;
108 Qt::Orientation m_scrollOrientation;
109 int m_itemIndex;
110
111 QColor m_separatorColor;
112 QColor m_roleColor;
113 QRectF m_roleBounds;
114 };
115 #endif
116
117