Qt Utilities 6.12.2
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 updateStyledButton();
52
53 QPalette::ColorGroup currentColorGroup() const
54 {
55 return m_currentColorGroup;
56 }
57
58 std::unique_ptr<Ui::PaletteEditor> m_ui;
59 QPalette m_editPalette;
60 QPalette m_parentPalette;
61 QPalette::ColorGroup m_currentColorGroup;
62 class PaletteModel *m_paletteModel;
63 bool m_modelUpdated;
64 bool m_paletteUpdated;
65 bool m_compute;
66};
67
71class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
72 Q_OBJECT
73 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
74public:
75 explicit PaletteModel(QObject *parent = nullptr);
76
77 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
78 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
79 QVariant data(const QModelIndex &index, int role) const override;
80 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
81 Qt::ItemFlags flags(const QModelIndex &index) const override;
82 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
83
84 QPalette getPalette() const;
85 void setPalette(const QPalette &palette, const QPalette &parentPalette);
86
87 QPalette::ColorRole colorRole() const
88 {
89 return QPalette::NoRole;
90 }
91 void setCompute(bool on)
92 {
93 m_compute = on;
94 }
95
96Q_SIGNALS:
97 void paletteChanged(const QPalette &palette);
98
99private:
100 QPalette::ColorGroup columnToGroup(int index) const;
101 int groupToColumn(QPalette::ColorGroup group) const;
102
103 QPalette m_palette;
104 QPalette m_parentPalette;
105 QMap<QPalette::ColorRole, QString> m_roleNames;
106 bool m_compute;
107};
108
112class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
113 Q_OBJECT
114
115public:
116 explicit BrushEditor(QWidget *parent = nullptr);
117
118 void setBrush(const QBrush &brush);
119 QBrush brush() const;
120 bool changed() const;
121
122Q_SIGNALS:
123 void changed(QWidget *widget);
124
125private Q_SLOTS:
126 void brushChanged();
127
128private:
129 ColorButton *m_button;
130 bool m_changed;
131};
132
136class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
137 Q_OBJECT
138public:
139 explicit RoleEditor(QWidget *parent = nullptr);
140
141 void setLabel(const QString &label);
142 void setEdited(bool on);
143 bool edited() const;
144
145Q_SIGNALS:
146 void changed(QWidget *widget);
147
148private Q_SLOTS:
149 void emitResetProperty();
150
151private:
152 QLabel *m_label;
153 bool m_edited;
154};
155
159class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate {
160 Q_OBJECT
161
162public:
163 explicit ColorDelegate(QObject *parent = nullptr);
164
165 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
166
167 void setEditorData(QWidget *ed, const QModelIndex &index) const override;
168 void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const override;
169
170 void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
171
172 void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
173 QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
174};
175} // namespace QtUtilities
176
177#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:13