Qt Utilities 6.14.4
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
42protected:
43 bool event(QEvent *event) override;
44
45private Q_SLOTS:
46 void buildPalette();
47 void paletteChanged(const QPalette &palette);
48 void handleComputeRadioClicked();
49 void handleDetailsRadioClicked();
50 void load();
51 void save();
52
53private:
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
74class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
75 Q_OBJECT
76 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
77public:
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
99Q_SIGNALS:
100 void paletteChanged(const QPalette &palette);
101
102private:
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
115class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
116 Q_OBJECT
117
118public:
119 explicit BrushEditor(QWidget *parent = nullptr);
120
121 void setBrush(const QBrush &brush);
122 QBrush brush() const;
123 bool changed() const;
124
125Q_SIGNALS:
126 void changed(QWidget *widget);
127
128private Q_SLOTS:
129 void brushChanged();
130
131private:
132 ColorButton *m_button;
133 bool m_changed;
134};
135
139class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
140 Q_OBJECT
141public:
142 explicit RoleEditor(QWidget *parent = nullptr);
143
144 void setLabel(const QString &label);
145 void setEdited(bool on);
146 bool edited() const;
147
148Q_SIGNALS:
149 void changed(QWidget *widget);
150
151private Q_SLOTS:
152 void emitResetProperty();
153
154private:
155 QLabel *m_label;
156 bool m_edited;
157};
158
162class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate {
163 Q_OBJECT
164
165public:
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
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.
The PaletteModel class is used by PaletteEditor.
QPalette::ColorRole colorRole() const
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.
Definition global.h:14