Qt Utilities  5.7.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 <QDialog>
9 #include <QItemDelegate>
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 
33 class QT_UTILITIES_EXPORT PaletteEditor : public QDialog {
34  Q_OBJECT
35 public:
36  PaletteEditor(QWidget *parent);
37  ~PaletteEditor();
38 
39  static QPalette getPalette(QWidget *parent, const QPalette &init = QPalette(), const QPalette &parentPal = QPalette(), int *result = nullptr);
40 
41  QPalette palette() const;
42  void setPalette(const QPalette &palette);
43  void setPalette(const QPalette &palette, const QPalette &parentPalette);
44 
45 private Q_SLOTS:
46  void on_buildButton_colorChanged(const QColor &);
47  void on_activeRadio_clicked();
48  void on_inactiveRadio_clicked();
49  void on_disabledRadio_clicked();
50  void on_computeRadio_clicked();
51  void on_detailsRadio_clicked();
52 
53  void paletteChanged(const QPalette &palette);
54 
55 private:
56  void buildPalette();
57 
58  void updatePreviewPalette();
59  void updateStyledButton();
60 
61  QPalette::ColorGroup currentColorGroup() const
62  {
63  return m_currentColorGroup;
64  }
65 
66  std::unique_ptr<Ui::PaletteEditor> m_ui;
67  QPalette m_editPalette;
68  QPalette m_parentPalette;
69  QPalette::ColorGroup m_currentColorGroup;
70  class PaletteModel *m_paletteModel;
71  bool m_modelUpdated;
72  bool m_paletteUpdated;
73  bool m_compute;
74 };
75 
79 class QT_UTILITIES_EXPORT PaletteModel : public QAbstractTableModel {
80  Q_OBJECT
81  Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
82 public:
83  explicit PaletteModel(QObject *parent = nullptr);
84 
85  int rowCount(const QModelIndex &parent = QModelIndex()) const;
86  int columnCount(const QModelIndex &parent = QModelIndex()) const;
87  QVariant data(const QModelIndex &index, int role) const;
88  bool setData(const QModelIndex &index, const QVariant &value, int role);
89  Qt::ItemFlags flags(const QModelIndex &index) const;
90  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
91 
92  QPalette getPalette() const;
93  void setPalette(const QPalette &palette, const QPalette &parentPalette);
94 
95  QPalette::ColorRole colorRole() const
96  {
97  return QPalette::NoRole;
98  }
99  void setCompute(bool on)
100  {
101  m_compute = on;
102  }
103 
104 Q_SIGNALS:
105  void paletteChanged(const QPalette &palette);
106 
107 private:
108  QPalette::ColorGroup columnToGroup(int index) const;
109  int groupToColumn(QPalette::ColorGroup group) const;
110 
111  QPalette m_palette;
112  QPalette m_parentPalette;
113  QMap<QPalette::ColorRole, QString> m_roleNames;
114  bool m_compute;
115 };
116 
120 class QT_UTILITIES_EXPORT BrushEditor : public QWidget {
121  Q_OBJECT
122 
123 public:
124  explicit BrushEditor(QWidget *parent = nullptr);
125 
126  void setBrush(const QBrush &brush);
127  QBrush brush() const;
128  bool changed() const;
129 
130 Q_SIGNALS:
131  void changed(QWidget *widget);
132 
133 private Q_SLOTS:
134  void brushChanged();
135 
136 private:
137  Widgets::ColorButton *m_button;
138  bool m_changed;
139 };
140 
144 class QT_UTILITIES_EXPORT RoleEditor : public QWidget {
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  Q_OBJECT
169 
170 public:
171  explicit ColorDelegate(QObject *parent = nullptr);
172 
173  QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
174 
175  void setEditorData(QWidget *ed, const QModelIndex &index) const;
176  void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const;
177 
178  void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const;
179 
180  void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const;
181  QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const;
182 };
183 }
184 
185 #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:33
QT_UTILITIES_EXPORT void init()
Initiates the resources used and provided by this library.
Definition: resources.cpp:52
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:95
The PaletteModel class is used by PaletteEditor.
Definition: paletteeditor.h:79