Qt Utilities  5.6.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
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 <c++utilities/conversion/types.h>
7 
8 #include <QItemDelegate>
9 #include <QDialog>
10 
11 #include <memory>
12 
13 QT_FORWARD_DECLARE_CLASS(QListView)
14 QT_FORWARD_DECLARE_CLASS(QLabel)
15 
16 namespace Widgets {
17 class ColorButton;
18 }
19 
20 namespace Dialogs {
21 
22 namespace Ui {
23 class PaletteEditor;
24 }
25 
32 class QT_UTILITIES_EXPORT PaletteEditor : public QDialog
33 {
34  Q_OBJECT
35 public:
36  PaletteEditor(QWidget *parent);
37  ~PaletteEditor();
38 
39  static QPalette getPalette(QWidget *parent, const QPalette &init = QPalette(),
40  const QPalette &parentPal = QPalette(), int *result = nullptr);
41 
42  QPalette palette() const;
43  void setPalette(const QPalette &palette);
44  void setPalette(const QPalette &palette, const QPalette &parentPalette);
45 
46 private Q_SLOTS:
47  void on_buildButton_colorChanged(const QColor &);
48  void on_activeRadio_clicked();
49  void on_inactiveRadio_clicked();
50  void on_disabledRadio_clicked();
51  void on_computeRadio_clicked();
52  void on_detailsRadio_clicked();
53 
54  void paletteChanged(const QPalette &palette);
55 
56 private:
57  void buildPalette();
58 
59  void updatePreviewPalette();
60  void updateStyledButton();
61 
62  QPalette::ColorGroup currentColorGroup() const
63  {
64  return m_currentColorGroup;
65  }
66 
67  std::unique_ptr<Ui::PaletteEditor> m_ui;
68  QPalette m_editPalette;
69  QPalette m_parentPalette;
70  QPalette::ColorGroup m_currentColorGroup;
71  class PaletteModel *m_paletteModel;
72  bool m_modelUpdated;
73  bool m_paletteUpdated;
74  bool m_compute;
75 };
76 
80 class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel
81 {
82  Q_OBJECT
83  Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
84 public:
85  explicit PaletteModel(QObject *parent = nullptr);
86 
87  int rowCount(const QModelIndex &parent = QModelIndex()) const;
88  int columnCount(const QModelIndex &parent = QModelIndex()) const;
89  QVariant data(const QModelIndex &index, int role) const;
90  bool setData(const QModelIndex &index, const QVariant &value, int role);
91  Qt::ItemFlags flags(const QModelIndex &index) const;
92  QVariant headerData(int section, Qt::Orientation orientation,
93  int role = Qt::DisplayRole) const;
94 
95  QPalette getPalette() const;
96  void setPalette(const QPalette &palette, const QPalette &parentPalette);
97 
98  QPalette::ColorRole colorRole() const { return QPalette::NoRole; }
99  void setCompute(bool on) { m_compute = on; }
100 
101 Q_SIGNALS:
102  void paletteChanged(const QPalette &palette);
103 
104 private:
105 
106  QPalette::ColorGroup columnToGroup(int index) const;
107  int groupToColumn(QPalette::ColorGroup group) const;
108 
109  QPalette m_palette;
110  QPalette m_parentPalette;
111  QMap<QPalette::ColorRole, QString> m_roleNames;
112  bool m_compute;
113 };
114 
118 class QT_UTILITIES_EXPORT BrushEditor : public QWidget
119 {
120  Q_OBJECT
121 
122 public:
123  explicit BrushEditor(QWidget *parent = nullptr);
124 
125  void setBrush(const QBrush &brush);
126  QBrush brush() const;
127  bool changed() const;
128 
129 Q_SIGNALS:
130  void changed(QWidget *widget);
131 
132 private Q_SLOTS:
133  void brushChanged();
134 
135 private:
136  Widgets::ColorButton *m_button;
137  bool m_changed;
138 };
139 
143 class QT_UTILITIES_EXPORT RoleEditor : public QWidget
144 {
145  Q_OBJECT
146 public:
147  explicit RoleEditor(QWidget *parent = nullptr);
148 
149  void setLabel(const QString &label);
150  void setEdited(bool on);
151  bool edited() const;
152 
153 signals:
154  void changed(QWidget *widget);
155 
156 private Q_SLOTS:
157  void emitResetProperty();
158 
159 private:
160  QLabel *m_label;
161  bool m_edited;
162 };
163 
167 class QT_UTILITIES_EXPORT ColorDelegate : public QItemDelegate
168 {
169  Q_OBJECT
170 
171 public:
172  explicit ColorDelegate(QObject *parent = nullptr);
173 
174  QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
175 
176  void setEditorData(QWidget *ed, const QModelIndex &index) const;
177  void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const;
178 
179  void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const;
180 
181  void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const;
182  QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const;
183 };
184 
185 }
186 
187 #endif // WIDGETS_PALETTEEDITOR_H
The BrushEditor class is used by PaletteEditor.
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:32
QT_UTILITIES_EXPORT void init()
Initiates the resources used and provided by this library.
Definition: resources.cpp:50
void setCompute(bool on)
Definition: paletteeditor.h:99
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Provides common dialogs such as AboutDialog, EnterPasswordDialog and SettingsDialog.
Definition: dialogutils.h:12
Provides a set of extended widgets such as ClearLineEdit and ClearComboBox.
Definition: buttonoverlay.h:13
The RoleEditor class is used by PaletteEditor.
QPalette::ColorRole colorRole() const
Definition: paletteeditor.h:98
The PaletteModel class is used by PaletteEditor.
Definition: paletteeditor.h:80