File indexing completed on 2024-04-28 05:45:07
0001 /* 0002 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KITEMLISTGROUPHEADER_H 0008 #define KITEMLISTGROUPHEADER_H 0009 0010 #include "dolphin_export.h" 0011 #include "kitemviews/kitemliststyleoption.h" 0012 0013 #include <QByteArray> 0014 #include <QGraphicsWidget> 0015 #include <QVariant> 0016 0017 class KItemListView; 0018 0019 /** 0020 * @brief Base class for group headers. 0021 * 0022 * Draws a default header background. Derived classes must reimplement 0023 * the method paint() and draw the role within the given roleBounds() with 0024 * the color roleColor(). 0025 */ 0026 class DOLPHIN_EXPORT KItemListGroupHeader : public QGraphicsWidget 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 explicit KItemListGroupHeader(QGraphicsWidget *parent = nullptr); 0032 ~KItemListGroupHeader() override; 0033 0034 void setRole(const QByteArray &role); 0035 QByteArray role() const; 0036 0037 void setData(const QVariant &data); 0038 QVariant data() const; 0039 0040 void setStyleOption(const KItemListStyleOption &option); 0041 const KItemListStyleOption &styleOption() const; 0042 0043 /** 0044 * Sets the scroll orientation that is used by the KItemListView. 0045 * This allows the group header to use a modified look dependent 0046 * on the orientation. 0047 */ 0048 void setScrollOrientation(Qt::Orientation orientation); 0049 Qt::Orientation scrollOrientation() const; 0050 0051 void setItemIndex(int index); 0052 int itemIndex() const; 0053 0054 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; 0055 0056 protected: 0057 virtual void paintRole(QPainter *painter, const QRectF &roleBounds, const QColor &color) = 0; 0058 virtual void paintSeparator(QPainter *painter, const QColor &color) = 0; 0059 0060 /** 0061 * Is called after the role has been changed and allows the derived class 0062 * to react on this change. 0063 */ 0064 virtual void roleChanged(const QByteArray ¤t, const QByteArray &previous); 0065 0066 /** 0067 * Is called after the role has been changed and allows the derived class 0068 * to react on this change. 0069 */ 0070 virtual void dataChanged(const QVariant ¤t, const QVariant &previous); 0071 0072 /** 0073 * Is called after the style option has been changed and allows the derived class 0074 * to react on this change. 0075 */ 0076 virtual void styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous); 0077 0078 /** 0079 * Is called after the scroll orientation has been changed and allows the derived class 0080 * to react on this change. 0081 */ 0082 virtual void scrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous); 0083 0084 /** 0085 * Is called after the item index has been changed and allows the derived class to react on 0086 * this change. 0087 */ 0088 virtual void itemIndexChanged(int current, int previous); 0089 0090 void resizeEvent(QGraphicsSceneResizeEvent *event) override; 0091 0092 virtual QPalette::ColorRole normalTextColorRole() const; 0093 virtual QPalette::ColorRole normalBaseColorRole() const; 0094 0095 private: 0096 void updateCache(); 0097 void updateSize(); 0098 0099 static QColor mixedColor(const QColor &c1, const QColor &c2, int c1Percent = 50); 0100 0101 QColor textColor() const; 0102 QColor baseColor() const; 0103 0104 private: 0105 bool m_dirtyCache; 0106 QByteArray m_role; 0107 QVariant m_data; 0108 KItemListStyleOption m_styleOption; 0109 Qt::Orientation m_scrollOrientation; 0110 int m_itemIndex; 0111 0112 QColor m_separatorColor; 0113 QColor m_roleColor; 0114 QRectF m_roleBounds; 0115 }; 0116 #endif