]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistgroupheader.h
GIT_SILENT Sync po/docbooks with svn
[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 void updateSize();
98
99 static QColor mixedColor(const QColor &c1, const QColor &c2, int c1Percent = 50);
100
101 QColor textColor() const;
102 QColor baseColor() const;
103
104 private:
105 bool m_dirtyCache;
106 QByteArray m_role;
107 QVariant m_data;
108 KItemListStyleOption m_styleOption;
109 Qt::Orientation m_scrollOrientation;
110 int m_itemIndex;
111
112 QColor m_separatorColor;
113 QColor m_roleColor;
114 QRectF m_roleBounds;
115 };
116 #endif