Debian Codegraph @

paletteeditor/paletteeditor.h

raw symbols SCIP
1 #ifndef WIDGETS_PALETTEEDITOR_H
2 #define WIDGETS_PALETTEEDITOR_H
3
4 #include "../global.h"
5
6 #include <QDialog>
7 #include <QItemDelegate>
8
9 #include <memory>
10
11 QT_FORWARD_DECLARE_CLASS(QListView)
12 QT_FORWARD_DECLARE_CLASS(QLabel)
13
14 namespace QtUtilities {
15
16 class ColorButton;
17
18 namespace Ui {
19 class PaletteEditor;
20 }
21
22 /*!
23 * \brief The PaletteEditor class provides a dialog to customize a QPalette.
24 *
25 * This is taken from
26 * qttools/src/designer/src/components/propertyeditor/paletteeditor.cpp.
27 * In contrast to the original version this version doesn't provide a preview.
28 */
29 class QT_UTILITIES_EXPORT PaletteEditor : public QDialog {
30 Q_OBJECT
31 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
32 public:
33 PaletteEditor(QWidget *parent);
34 ~PaletteEditor() override;
35
36 static QPalette getPalette(QWidget *parent, const QPalette &init = QPalette(), const QPalette &parentPal = QPalette(), int *result = nullptr);
37
38 QPalette palette() const;
39 void setPalette(const QPalette &palette);
40 void setPalette(const QPalette &palette, const QPalette &parentPalette);
41
42 protected:
43 bool event(QEvent *event) override;
44
45 private Q_SLOTS:
46 void buildPalette();
47 void paletteChanged(const QPalette &palette);
48 void handleComputeRadioClicked();
49 void handleDetailsRadioClicked();
50 void load();
51 void save();
52
53 private:
54 void updateStyledButton();
55
56 QPalette::ColorGroup currentColorGroup() const
57 {
58 return m_currentColorGroup;
59 }
60
61 std::unique_ptr<Ui::PaletteEditor> m_ui;
62 QPalette m_editPalette;
63 QPalette m_parentPalette;
64 QPalette::ColorGroup m_currentColorGroup;
65 class PaletteModel *m_paletteModel;
66 bool m_modelUpdated;
67 bool m_paletteUpdated;
68 bool m_compute;
69 };
70
71 /*!
72 * \brief The PaletteModel class is used by PaletteEditor.
73 */
74 class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
75 Q_OBJECT
76 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
77 public:
78 explicit PaletteModel(QObject *parent = nullptr);
79
80 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
81 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
82 QVariant data(const QModelIndex &index, int role) const override;
83 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
84 Qt::ItemFlags flags(const QModelIndex &index) const override;
85 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
86
87 QPalette getPalette() const;
88 void setPalette(const QPalette &palette, const QPalette &parentPalette);
89
90 QPalette::ColorRole colorRole() const
91 {
92 return QPalette::NoRole;
93 }
94 void setCompute(bool on)
95 {
96 m_compute = on;
97 }
98
99 Q_SIGNALS:
100 void paletteChanged(const QPalette &palette);
101
102 private:
103 QPalette::ColorGroup columnToGroup(int index) const;
104 int groupToColumn(QPalette::ColorGroup group) const;
105
106 QPalette m_palette;
107 QPalette m_parentPalette;
108 QMap<QPalette::ColorRole, QString> m_roleNames;
109 bool m_compute;
110 };
111
112 /*!
113 * \brief The BrushEditor class is used by PaletteEditor.
114 */
115 class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
116 Q_OBJECT
117
118 public:
119 explicit BrushEditor(QWidget *parent = nullptr);
120
121 void setBrush(const QBrush &brush);
122 QBrush brush() const;
123 bool changed() const;
124
125 Q_SIGNALS:
126 void changed(QWidget *widget);
127
128 private Q_SLOTS:
129 void brushChanged();
130
131 private:
132 ColorButton *m_button;
133 bool m_changed;
134 };
135
136 /*!
137 * \brief The RoleEditor class is used by PaletteEditor.
138 */
139 class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
140 Q_OBJECT
141 public:
142 explicit RoleEditor(QWidget *parent = nullptr);
143
144 void setLabel(const QString &label);
145 void setEdited(bool on);
146 bool edited() const;
147
148 Q_SIGNALS:
149 void changed(QWidget *widget);
150
151 private Q_SLOTS:
152 void emitResetProperty();
153
154 private:
155 QLabel *m_label;
156 bool m_edited;
157 };
158
159 /*!
160 * \brief The ColorDelegate class is used by PaletteEditor.
161 */
162 class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate {
163 Q_OBJECT
164
165 public:
166 explicit ColorDelegate(QObject *parent = nullptr);
167
168 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
169
170 void setEditorData(QWidget *ed, const QModelIndex &index) const override;
171 void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const override;
172
173 void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
174
175 void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
176 QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
177 };
178 } // namespace QtUtilities
179
180 #endif // WIDGETS_PALETTEEDITOR_H