Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
paletteeditor.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef PALETTEEDITOR_H
5#define PALETTEEDITOR_H
6
7#include "ui_paletteeditor.h"
8#include <QtWidgets/qitemdelegate.h>
9
10QT_BEGIN_NAMESPACE
11
12class QAction;
13class QListView;
14class QMenu;
15class QLabel;
16class QtColorButton;
17class QDesignerFormEditorInterface;
18
19namespace qdesigner_internal {
20
22{
24public:
26
27 static QPalette getPalette(QDesignerFormEditorInterface *core,
28 QWidget* parent, const QPalette &init = QPalette(),
29 const QPalette &parentPal = QPalette(), int *result = nullptr);
30
31 QPalette palette() const;
32 void setPalette(const QPalette &palette);
33 void setPalette(const QPalette &palette, const QPalette &parentPalette);
34
35private slots:
36
38 void activeRadioClicked();
39 void inactiveRadioClicked();
40 void disabledRadioClicked();
41 void computeRadioClicked();
42 void detailsRadioClicked();
43
44 void paletteChanged(const QPalette &palette);
45 void viewContextMenuRequested(QPoint pos);
46 void save();
47 void load();
48
49protected:
50
51private:
52 PaletteEditor(QDesignerFormEditorInterface *core, QWidget *parent);
53 void buildPalette();
54
55 void updatePreviewPalette();
56 void updateStyledButton();
57
58 QPalette::ColorGroup currentColorGroup() const
59 { return m_currentColorGroup; }
60
61 Ui::PaletteEditor ui;
62 QPalette m_editPalette;
63 QPalette m_parentPalette;
64 class PaletteModel *m_paletteModel;
65 QDesignerFormEditorInterface *m_core;
66 QAction *m_lighterAction = nullptr;
67 QAction *m_darkerAction = nullptr;
68 QAction *m_copyColorAction = nullptr;
69 QMenu *m_contextMenu = nullptr;
70 QPalette::ColorGroup m_currentColorGroup = QPalette::Active;
71 bool m_modelUpdated = false;
72 bool m_paletteUpdated = false;
73 bool m_compute = true;
74};
75
76
78{
79 Q_OBJECT
80 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
81public:
82 explicit PaletteModel(QObject *parent = nullptr);
83
84 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
85 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
86 QVariant data(const QModelIndex &index, int role) const override;
87 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
88 Qt::ItemFlags flags(const QModelIndex &index) const override;
89 QVariant headerData(int section, Qt::Orientation orientation,
90 int role = Qt::DisplayRole) const override;
91
92 QPalette getPalette() const;
93 void setPalette(const QPalette &palette, const QPalette &parentPalette);
94
95 QBrush brushAt(const QModelIndex &index) const;
96
97 QPalette::ColorRole colorRole() const { return QPalette::NoRole; }
98 void setCompute(bool on) { m_compute = on; }
99
100 quint64 rowMask(const QModelIndex &index) const;
101
102signals:
104private:
105 struct RoleEntry
106 {
107 QString name;
108 QPalette::ColorRole role;
109 };
110
111 QPalette::ColorGroup columnToGroup(int index) const;
112 int groupToColumn(QPalette::ColorGroup group) const;
113 QPalette::ColorRole roleAt(int row) const { return m_roleEntries.at(row).role; }
114 int rowOf(QPalette::ColorRole role) const;
115
116 QPalette m_palette;
117 QPalette m_parentPalette;
118 QList<RoleEntry> m_roleEntries;
119 bool m_compute = true;
120};
121
122class BrushEditor : public QWidget
123{
125public:
127
128 void setBrush(const QBrush &brush);
129 QBrush brush() const;
130 bool changed() const;
131signals:
133private slots:
134 void brushChanged();
135private:
136 QtColorButton *m_button;
137 bool m_changed = false;
138 QDesignerFormEditorInterface *m_core;
139};
140
141class RoleEditor : public QWidget
142{
144public:
145 explicit RoleEditor(QWidget *parent = nullptr);
146
147 void setLabel(const QString &label);
148 void setEdited(bool on);
149 bool edited() const;
150signals:
152private slots:
153 void emitResetProperty();
154private:
155 QLabel *m_label;
156 bool m_edited = false;
157};
158
160{
162
163public:
165
166 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
167 const QModelIndex &index) const override;
168
169 void setEditorData(QWidget *ed, const QModelIndex &index) const override;
170 void setModelData(QWidget *ed, QAbstractItemModel *model,
171 const QModelIndex &index) const override;
172
173 void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option,
174 const QModelIndex &index) const override;
175
176 void paint(QPainter *painter, const QStyleOptionViewItem &opt,
177 const QModelIndex &index) const override;
178 QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
179private:
180 QDesignerFormEditorInterface *m_core;
181};
182
183} // namespace qdesigner_internal
184
185QT_END_NAMESPACE
186
187#endif // PALETTEEDITOR_H
void setBrush(const QBrush &brush)
QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override
This pure abstract function must be reimplemented if you want to provide custom rendering.
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
This pure abstract function must be reimplemented if you want to provide custom rendering.
void setPalette(const QPalette &palette)
void setPalette(const QPalette &palette, const QPalette &parentPalette)
QBrush brushAt(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the data for the given role and section in the header with the specified orientation.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns for the children of the given parent.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
QPalette::ColorRole colorRole() const
quint64 rowMask(const QModelIndex &index) const
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Sets the role data for the item at index to value.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given index.
void setPalette(const QPalette &palette, const QPalette &parentPalette)
void setLabel(const QString &label)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QString paletteFilter()
static bool savePalette(const QString &fileName, const QPalette &pal, QString *errorMessage)
static QString msgCannotReadPalette(const QString &fileName, const QXmlStreamReader &reader)
static QString msgCannotReadPalette(const QString &fileName, const QXmlStreamReader &reader, const QString &why)
static bool loadPalette(const QString &fileName, QPalette *pal, QString *errorMessage)