Qt Utilities: paletteeditor/paletteeditor.h Source File

Qt Utilities 6.21.3 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
29 class 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
74 class 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
115 class 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
139 class 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
162 class 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
QtUtilities::BrushEditor::brush
QBrush brush() const
Definition paletteeditor.cpp:477
QtUtilities::BrushEditor::changed
bool changed() const
Definition paletteeditor.cpp:488
QtUtilities::BrushEditor::setBrush
void setBrush(const QBrush &brush)
Definition paletteeditor.cpp:471
QtUtilities::BrushEditor::changed
void changed(QWidget *widget)
QtUtilities::BrushEditor::BrushEditor
BrushEditor(QWidget *parent=nullptr)
Definition paletteeditor.cpp:459
QtUtilities::ColorButton
The ColorButton class is used by PaletteEditor.
Definition colorbutton.h:15
QtUtilities::ColorDelegate::setModelData
void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const override
Definition paletteeditor.cpp:579
QtUtilities::ColorDelegate::updateEditorGeometry
void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition paletteeditor.cpp:594
QtUtilities::ColorDelegate::setEditorData
void setEditorData(QWidget *ed, const QModelIndex &index) const override
Definition paletteeditor.cpp:564
QtUtilities::ColorDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
Definition paletteeditor.cpp:600
QtUtilities::ColorDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override
Definition paletteeditor.cpp:634
QtUtilities::ColorDelegate::ColorDelegate
ColorDelegate(QObject *parent=nullptr)
Definition paletteeditor.cpp:542
QtUtilities::ColorDelegate::createEditor
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition paletteeditor.cpp:547
QtUtilities::PaletteEditor::getPalette
static QPalette getPalette(QWidget *parent, const QPalette &init=QPalette(), const QPalette &parentPal=QPalette(), int *result=nullptr)
Definition paletteeditor.cpp:239
QtUtilities::PaletteEditor::PaletteEditor
PaletteEditor(QWidget *parent)
Definition paletteeditor.cpp:23
QtUtilities::PaletteEditor::event
bool event(QEvent *event) override
Definition paletteeditor.cpp:110
QtUtilities::PaletteEditor::setPalette
void setPalette(const QPalette &palette)
Definition paletteeditor.cpp:66
QtUtilities::PaletteEditor::palette
QPalette palette
Definition paletteeditor.h:31
QtUtilities::PaletteModel
The PaletteModel class is used by PaletteEditor.
Definition paletteeditor.h:74
QtUtilities::PaletteModel::colorRole
QPalette::ColorRole colorRole
Definition paletteeditor.h:76
QtUtilities::PaletteModel::colorRole
QPalette::ColorRole colorRole() const
Definition paletteeditor.h:90
QtUtilities::PaletteModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition paletteeditor.cpp:288
QtUtilities::PaletteModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition paletteeditor.cpp:405
QtUtilities::PaletteModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition paletteeditor.cpp:283
QtUtilities::PaletteModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition paletteeditor.cpp:412
QtUtilities::PaletteModel::setCompute
void setCompute(bool on)
Definition paletteeditor.h:94
QtUtilities::PaletteModel::getPalette
QPalette getPalette() const
Definition paletteeditor.cpp:427
QtUtilities::PaletteModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition paletteeditor.cpp:293
QtUtilities::PaletteModel::PaletteModel
PaletteModel(QObject *parent=nullptr)
Definition paletteeditor.cpp:271
QtUtilities::PaletteModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition paletteeditor.cpp:322
QtUtilities::PaletteModel::setPalette
void setPalette(const QPalette &palette, const QPalette &parentPalette)
Definition paletteeditor.cpp:432
QtUtilities::PaletteModel::paletteChanged
void paletteChanged(const QPalette &palette)
QtUtilities::RoleEditor::changed
void changed(QWidget *widget)
QtUtilities::RoleEditor::setEdited
void setEdited(bool on)
Definition paletteeditor.cpp:521
QtUtilities::RoleEditor::edited
bool edited() const
Definition paletteeditor.cpp:531
QtUtilities::RoleEditor::RoleEditor
RoleEditor(QWidget *parent=nullptr)
Definition paletteeditor.cpp:493
QtUtilities::RoleEditor::setLabel
void setLabel(const QString &label)
Definition paletteeditor.cpp:516
global.h
QT_UTILITIES_EXPORT
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14
QtUtilities::Ui
Definition aboutdialog.h:14
QtUtilities
!
Definition trylocker.h:8