Qt Utilities 6.12.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
paletteeditor.h
Go to the documentation of this file.
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
11QT_FORWARD_DECLARE_CLASS(QListView)
12QT_FORWARD_DECLARE_CLASS(QLabel)
13
14namespace QtUtilities {
15
16class ColorButton;
17
18namespace Ui {
19class PaletteEditor;
20}
21
29class QT_UTILITIES_EXPORT PaletteEditor : public QDialog {
30 Q_OBJECT
31 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
32public:
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
42private Q_SLOTS:
43 void buildPalette();
44 void paletteChanged(const QPalette &palette);
45 void handleComputeRadioClicked();
46 void handleDetailsRadioClicked();
47 void load();
48 void save();
49
50private:
51 void updatePreviewPalette();
52 void updateStyledButton();
53
54 QPalette::ColorGroup currentColorGroup() const
55 {
56 return m_currentColorGroup;
57 }
58
59 std::unique_ptr<Ui::PaletteEditor> m_ui;
60 QPalette m_editPalette;
61 QPalette m_parentPalette;
62 QPalette::ColorGroup m_currentColorGroup;
63 class PaletteModel *m_paletteModel;
64 bool m_modelUpdated;
65 bool m_paletteUpdated;
66 bool m_compute;
67};
68
72class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
73 Q_OBJECT
74 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
75public:
76 explicit PaletteModel(QObject *parent = nullptr);
77
78 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
79 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
80 QVariant data(const QModelIndex &index, int role) const override;
81 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
82 Qt::ItemFlags flags(const QModelIndex &index) const override;
83 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
84
85 QPalette getPalette() const;
86 void setPalette(const QPalette &palette, const QPalette &parentPalette);
87
88 QPalette::ColorRole colorRole() const
89 {
90 return QPalette::NoRole;
91 }
92 void setCompute(bool on)
93 {
94 m_compute = on;
95 }
96
97Q_SIGNALS:
98 void paletteChanged(const QPalette &palette);
99
100private:
101 QPalette::ColorGroup columnToGroup(int index) const;
102 int groupToColumn(QPalette::ColorGroup group) const;
103
104 QPalette m_palette;
105 QPalette m_parentPalette;
106 QMap<QPalette::ColorRole, QString> m_roleNames;
107 bool m_compute;
108};
109
113class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
114 Q_OBJECT
115
116public:
117 explicit BrushEditor(QWidget *parent = nullptr);
118
119 void setBrush(const QBrush &brush);
120 QBrush brush() const;
121 bool changed() const;
122
123Q_SIGNALS:
124 void changed(QWidget *widget);
125
126private Q_SLOTS:
127 void brushChanged();
128
129private:
130 ColorButton *m_button;
131 bool m_changed;
132};
133
137class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
138 Q_OBJECT
139public:
140 explicit RoleEditor(QWidget *parent = nullptr);
141
142 void setLabel(const QString &label);
143 void setEdited(bool on);
144 bool edited() const;
145
146Q_SIGNALS:
147 void changed(QWidget *widget);
148
149private Q_SLOTS:
150 void emitResetProperty();
151
152private:
153 QLabel *m_label;
154 bool m_edited;
155};
156
160class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate {
161 Q_OBJECT
162
163public:
164 explicit ColorDelegate(QObject *parent = nullptr);
165
166 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
167
168 void setEditorData(QWidget *ed, const QModelIndex &index) const override;
169 void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const override;
170
171 void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
172
173 void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
174 QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
175};
176} // namespace QtUtilities
177
178#endif // WIDGETS_PALETTEEDITOR_H
The BrushEditor class is used by PaletteEditor.
void changed(QWidget *widget)
The ColorButton class is used by PaletteEditor.
Definition: colorbutton.h:15
The ColorDelegate class is used by PaletteEditor.
The PaletteEditor class provides a dialog to customize a QPalette.
Definition: paletteeditor.h:29
The PaletteModel class is used by PaletteEditor.
Definition: paletteeditor.h:72
QPalette::ColorRole colorRole() const
Definition: paletteeditor.h:88
void paletteChanged(const QPalette &palette)
The RoleEditor class is used by PaletteEditor.
void changed(QWidget *widget)
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.