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// Qt-Security score:significant reason:default
4
5#ifndef PALETTEEDITOR_H
6#define PALETTEEDITOR_H
7
8#include "ui_paletteeditor.h"
9#include <QtWidgets/qstyleditemdelegate.h>
10
11QT_BEGIN_NAMESPACE
12
13class QAction;
14class QListView;
15class QMenu;
16class QLabel;
17class QtColorButton;
18class QDesignerFormEditorInterface;
19
20namespace qdesigner_internal {
21
23{
25public:
27
28 static QPalette getPalette(QDesignerFormEditorInterface *core,
29 QWidget* parent, const QPalette &init = QPalette(),
30 const QPalette &parentPal = QPalette(), int *result = nullptr);
31
32 QPalette palette() const;
33 void setPalette(const QPalette &palette);
34 void setPalette(const QPalette &palette, const QPalette &parentPalette);
35
36private slots:
37
39 void activeRadioClicked();
40 void inactiveRadioClicked();
41 void disabledRadioClicked();
42 void computeRadioClicked();
43 void detailsRadioClicked();
44
45 void paletteChanged(const QPalette &palette);
46 void viewContextMenuRequested(QPoint pos);
47 void save();
48 void load();
49
50protected:
51
52private:
53 PaletteEditor(QDesignerFormEditorInterface *core, QWidget *parent);
54 void buildPalette();
55
56 void updatePreviewPalette();
57 void updateStyledButton();
58
59 QPalette::ColorGroup currentColorGroup() const
60 { return m_currentColorGroup; }
61
62 Ui::PaletteEditor ui;
63 QPalette m_editPalette;
64 QPalette m_parentPalette;
65 class PaletteModel *m_paletteModel;
66 QDesignerFormEditorInterface *m_core;
67 QAction *m_lighterAction = nullptr;
68 QAction *m_darkerAction = nullptr;
69 QAction *m_copyColorAction = nullptr;
70 QMenu *m_contextMenu = nullptr;
71 QPalette::ColorGroup m_currentColorGroup = QPalette::Active;
72 bool m_modelUpdated = false;
73 bool m_paletteUpdated = false;
74 bool m_compute = true;
75};
76
77
79{
80 Q_OBJECT
81 Q_PROPERTY(QPalette::ColorRole colorRole READ colorRole)
82public:
83 explicit PaletteModel(QObject *parent = nullptr);
84
85 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
86 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
87 QVariant data(const QModelIndex &index, int role) const override;
88 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
89 Qt::ItemFlags flags(const QModelIndex &index) const override;
90 QVariant headerData(int section, Qt::Orientation orientation,
91 int role = Qt::DisplayRole) const override;
92
93 QPalette getPalette() const;
94 void setPalette(const QPalette &palette, const QPalette &parentPalette);
95
96 QBrush brushAt(const QModelIndex &index) const;
97
98 QPalette::ColorRole colorRole() const { return QPalette::NoRole; }
99 void setCompute(bool on) { m_compute = on; }
100
101 quint64 rowMask(const QModelIndex &index) const;
102
103signals:
105private:
106 struct RoleEntry
107 {
108 QString name;
109 QPalette::ColorRole role;
110 };
111
112 QPalette::ColorGroup columnToGroup(int index) const;
113 int groupToColumn(QPalette::ColorGroup group) const;
114 QPalette::ColorRole roleAt(int row) const { return m_roleEntries.at(row).role; }
115 int rowOf(QPalette::ColorRole role) const;
116
117 QPalette m_palette;
118 QPalette m_parentPalette;
119 QList<RoleEntry> m_roleEntries;
120 bool m_compute = true;
121};
122
123class BrushEditor : public QWidget
124{
126public:
128
129 void setBrush(const QBrush &brush);
130 QBrush brush() const;
131 bool changed() const;
132signals:
134private slots:
135 void brushChanged();
136private:
137 QtColorButton *m_button;
138 bool m_changed = false;
139 QDesignerFormEditorInterface *m_core;
140};
141
142class RoleEditor : public QWidget
143{
145public:
146 explicit RoleEditor(QWidget *parent = nullptr);
147
148 void setLabel(const QString &label);
149 void setEdited(bool on);
150 bool edited() const;
151signals:
153private slots:
154 void emitResetProperty();
155private:
156 QLabel *m_label;
157 bool m_edited = false;
158};
159
161{
163
164public:
166
167 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
168 const QModelIndex &index) const override;
169
170 void setEditorData(QWidget *ed, const QModelIndex &index) const override;
171 void setModelData(QWidget *ed, QAbstractItemModel *model,
172 const QModelIndex &index) const override;
173
174 void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option,
175 const QModelIndex &index) const override;
176
177 void paint(QPainter *painter, const QStyleOptionViewItem &opt,
178 const QModelIndex &index) const override;
179 QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override;
180private:
181 QDesignerFormEditorInterface *m_core;
182};
183
184} // namespace qdesigner_internal
185
186QT_END_NAMESPACE
187
188#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)
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)