Qt Utilities 6.12.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
paletteeditor.cpp
Go to the documentation of this file.
1#include "./paletteeditor.h"
2#include "./colorbutton.h"
3
4#include "ui_paletteeditor.h"
5
6#include <QFileDialog>
7#include <QHeaderView>
8#include <QLabel>
9#include <QMessageBox>
10#include <QMetaProperty>
11#include <QPainter>
12#include <QPushButton>
13#include <QSettings>
14#include <QStyle>
15#include <QToolButton>
16
17namespace QtUtilities {
18
19enum { BrushRole = 33 };
20
22 : QDialog(parent)
23 , m_ui(new Ui::PaletteEditor)
24 , m_currentColorGroup(QPalette::Active)
25 , m_paletteModel(new PaletteModel(this))
26 , m_modelUpdated(false)
27 , m_paletteUpdated(false)
28 , m_compute(true)
29{
30 m_ui->setupUi(this);
31 m_ui->paletteView->setModel(m_paletteModel);
32 updatePreviewPalette();
33 updateStyledButton();
34 m_ui->paletteView->setModel(m_paletteModel);
35 auto *const delegate = new ColorDelegate(this);
36 m_ui->paletteView->setItemDelegate(delegate);
37 m_ui->paletteView->setEditTriggers(QAbstractItemView::AllEditTriggers);
38 m_ui->paletteView->setSelectionBehavior(QAbstractItemView::SelectRows);
39 m_ui->paletteView->setDragEnabled(true);
40 m_ui->paletteView->setDropIndicatorShown(true);
41 m_ui->paletteView->setRootIsDecorated(false);
42 m_ui->paletteView->setColumnHidden(2, true);
43 m_ui->paletteView->setColumnHidden(3, true);
44
45 auto saveButton = m_ui->buttonBox->addButton(tr("Save…"), QDialogButtonBox::ActionRole);
46 connect(saveButton, &QPushButton::clicked, this, &PaletteEditor::save);
47 auto loadButton = m_ui->buttonBox->addButton(tr("Load…"), QDialogButtonBox::ActionRole);
48 connect(loadButton, &QPushButton::clicked, this, &PaletteEditor::load);
49
50 connect(m_paletteModel, &PaletteModel::paletteChanged, this, &PaletteEditor::paletteChanged);
51 connect(m_ui->buildButton, &ColorButton::colorChanged, this, &PaletteEditor::buildPalette);
52 connect(m_ui->computeRadio, &QRadioButton::clicked, this, &PaletteEditor::handleComputeRadioClicked);
53 connect(m_ui->detailsRadio, &QRadioButton::clicked, this, &PaletteEditor::handleDetailsRadioClicked);
54}
55
57{
58}
59
60QPalette PaletteEditor::palette() const
61{
62 return m_editPalette;
63}
64
65void PaletteEditor::setPalette(const QPalette &palette)
66{
67 m_editPalette = palette;
68 const auto mask = palette.
69#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
70 resolveMask()
71#else
72 resolve()
73#endif
74 ;
75 for (int i = 0; i < static_cast<int>(QPalette::NColorRoles); ++i) {
76 if (mask & (1 << i)) {
77 continue;
78 }
79 m_editPalette.setBrush(
80 QPalette::Active, static_cast<QPalette::ColorRole>(i), m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
81 m_editPalette.setBrush(
82 QPalette::Inactive, static_cast<QPalette::ColorRole>(i), m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
83 m_editPalette.setBrush(
84 QPalette::Disabled, static_cast<QPalette::ColorRole>(i), m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
85 }
86 m_editPalette.
87#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
88 setResolveMask(mask);
89 m_editPalette = m_editPalette.resolve(m_editPalette)
90#else
91 resolve(mask)
92#endif
93 ;
94 updatePreviewPalette();
95 updateStyledButton();
96 m_paletteUpdated = true;
97 if (!m_modelUpdated) {
98 m_paletteModel->setPalette(m_editPalette, m_parentPalette);
99 }
100 m_paletteUpdated = false;
101}
102
103void PaletteEditor::setPalette(const QPalette &palette, const QPalette &parentPalette)
104{
105 m_parentPalette = parentPalette;
107}
108
109void PaletteEditor::handleComputeRadioClicked()
110{
111 if (m_compute) {
112 return;
113 }
114 m_ui->paletteView->setColumnHidden(2, true);
115 m_ui->paletteView->setColumnHidden(3, true);
116 m_compute = true;
117 m_paletteModel->setCompute(true);
118}
119
120void PaletteEditor::handleDetailsRadioClicked()
121{
122 if (!m_compute) {
123 return;
124 }
125 const int w = m_ui->paletteView->columnWidth(1);
126 m_ui->paletteView->setColumnHidden(2, false);
127 m_ui->paletteView->setColumnHidden(3, false);
128 auto *const header = m_ui->paletteView->header();
129 header->resizeSection(1, w / 3);
130 header->resizeSection(2, w / 3);
131 header->resizeSection(3, w / 3);
132 m_compute = false;
133 m_paletteModel->setCompute(false);
134}
135
136static inline QString paletteSuffix()
137{
138 return QStringLiteral("ini");
139}
140
141static inline QString paletteFilter()
142{
143 return PaletteEditor::tr("Color palette configuration (*.ini)");
144}
145
146static bool loadPalette(const QString &fileName, QPalette *pal, QString *errorMessage)
147{
148 const auto settings = QSettings(fileName, QSettings::IniFormat);
149 if (settings.status() != QSettings::NoError) {
150 *errorMessage = PaletteEditor::tr("Unable to load \"%1\".").arg(fileName);
151 return false;
152 }
153 const auto value = settings.value(QStringLiteral("palette"));
154 if (!value.isValid() || !value.canConvert<QPalette>()) {
155 *errorMessage = PaletteEditor::tr("\"%1\" does not contain a valid palette.").arg(fileName);
156 return false;
157 }
158 *pal = settings.value(QStringLiteral("palette")).value<QPalette>();
159 return true;
160}
161
162static bool savePalette(const QString &fileName, const QPalette &pal, QString *errorMessage)
163{
164 auto settings = QSettings(fileName, QSettings::IniFormat);
165 settings.setValue(QStringLiteral("palette"), QVariant(pal));
166 settings.sync();
167 if (settings.status() != QSettings::NoError) {
168 *errorMessage = PaletteEditor::tr("Unable to write \"%1\".").arg(fileName);
169 return false;
170 }
171 return true;
172}
173
174void PaletteEditor::load()
175{
176 auto dialog = QFileDialog(this, tr("Load palette"), QString(), paletteFilter());
177 dialog.setAcceptMode(QFileDialog::AcceptOpen);
178 if (dialog.exec() != QDialog::Accepted) {
179 return;
180 }
181 auto pal = QPalette();
182 auto errorMessage = QString();
183 if (loadPalette(dialog.selectedFiles().constFirst(), &pal, &errorMessage)) {
184 setPalette(pal);
185 } else {
186 QMessageBox::warning(this, tr("Error reading palette"), errorMessage);
187 }
188}
189
190void PaletteEditor::save()
191{
192 auto dialog = QFileDialog(this, tr("Save palette"), QString(), paletteFilter());
193 dialog.setAcceptMode(QFileDialog::AcceptSave);
194 dialog.setDefaultSuffix(paletteSuffix());
195 if (dialog.exec() != QDialog::Accepted) {
196 return;
197 }
198 auto errorMessage = QString();
199 if (!savePalette(dialog.selectedFiles().constFirst(), palette(), &errorMessage)) {
200 QMessageBox::warning(this, tr("Error writing palette"), errorMessage);
201 }
202}
203
204void PaletteEditor::paletteChanged(const QPalette &palette)
205{
206 m_modelUpdated = true;
207 if (!m_paletteUpdated) {
209 }
210 m_modelUpdated = false;
211}
212
213void PaletteEditor::buildPalette()
214{
215 const QColor btn(m_ui->buildButton->color());
216 const QPalette temp(btn);
217 setPalette(temp);
218}
219
220void PaletteEditor::updatePreviewPalette()
221{
222 const QPalette::ColorGroup g = currentColorGroup();
223 // build the preview palette
224 const QPalette currentPalette = palette();
225 QPalette previewPalette;
226 for (int i = QPalette::WindowText; i < QPalette::NColorRoles; ++i) {
227 const QPalette::ColorRole r = static_cast<QPalette::ColorRole>(i);
228 const QBrush br = currentPalette.brush(g, r);
229 previewPalette.setBrush(QPalette::Active, r, br);
230 previewPalette.setBrush(QPalette::Inactive, r, br);
231 previewPalette.setBrush(QPalette::Disabled, r, br);
232 }
233}
234
235void PaletteEditor::updateStyledButton()
236{
237 m_ui->buildButton->setColor(palette().color(QPalette::Active, QPalette::Button));
238}
239
240QPalette PaletteEditor::getPalette(QWidget *parent, const QPalette &init, const QPalette &parentPal, int *ok)
241{
242 PaletteEditor dlg(parent);
243 auto parentPalette(parentPal);
244 const auto mask = init.
245#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
246 resolveMask()
247#else
248 resolve()
249#endif
250 ;
251 for (int i = 0; i < static_cast<int>(QPalette::NColorRoles); ++i) {
252 if (mask & (1 << i)) {
253 continue;
254 }
255 parentPalette.setBrush(
256 QPalette::Active, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
257 parentPalette.setBrush(
258 QPalette::Inactive, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
259 parentPalette.setBrush(
260 QPalette::Disabled, static_cast<QPalette::ColorRole>(i), init.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
261 }
262 dlg.setPalette(init, parentPalette);
263
264 const int result = dlg.exec();
265 if (ok) {
266 *ok = result;
267 }
268 return result == QDialog::Accepted ? dlg.palette() : init;
269}
270
272 : QAbstractTableModel(parent)
273 , m_compute(true)
274{
275 const QMetaObject *meta = metaObject();
276 const QMetaProperty property = meta->property(meta->indexOfProperty("colorRole"));
277 const QMetaEnum enumerator = property.enumerator();
278 for (int r = QPalette::WindowText; r < QPalette::NColorRoles; ++r) {
279 m_roleNames[static_cast<QPalette::ColorRole>(r)] = QLatin1String(enumerator.key(r));
280 }
281}
282
283int PaletteModel::rowCount(const QModelIndex &) const
284{
285 return static_cast<int>(m_roleNames.count());
286}
287
288int PaletteModel::columnCount(const QModelIndex &) const
289{
290 return 4;
291}
292
293QVariant PaletteModel::data(const QModelIndex &index, int role) const
294{
295 if (!index.isValid() || index.row() < 0 || index.row() >= QPalette::NColorRoles || index.column() < 0 || index.column() >= 4) {
296 return QVariant();
297 }
298
299 if (index.column() == 0) {
300 if (role == Qt::DisplayRole) {
301 return m_roleNames[static_cast<QPalette::ColorRole>(index.row())];
302 }
303 if (role == Qt::EditRole) {
304 const auto mask = m_palette.
305#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
306 resolveMask()
307#else
308 resolve()
309#endif
310 ;
311 if (mask & (1 << index.row()))
312 return true;
313 return false;
314 }
315 return QVariant();
316 }
317 if (role == BrushRole) {
318 return m_palette.brush(columnToGroup(index.column()), static_cast<QPalette::ColorRole>(index.row()));
319 }
320 return QVariant();
321}
322
323bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int role)
324{
325 if (!index.isValid()) {
326 return false;
327 }
328
329 if (index.column() != 0 && role == BrushRole) {
330 const QBrush br = qvariant_cast<QBrush>(value);
331 const QPalette::ColorRole r = static_cast<QPalette::ColorRole>(index.row());
332 const QPalette::ColorGroup g = columnToGroup(index.column());
333 m_palette.setBrush(g, r, br);
334
335 QModelIndex idxBegin = PaletteModel::index(r, 0);
336 QModelIndex idxEnd = PaletteModel::index(r, 3);
337 if (m_compute) {
338 m_palette.setBrush(QPalette::Inactive, r, br);
339 switch (r) {
340 case QPalette::WindowText:
341 case QPalette::Text:
342 case QPalette::ButtonText:
343 case QPalette::Base:
344 break;
345 case QPalette::Dark:
346 m_palette.setBrush(QPalette::Disabled, QPalette::WindowText, br);
347 m_palette.setBrush(QPalette::Disabled, QPalette::Dark, br);
348 m_palette.setBrush(QPalette::Disabled, QPalette::Text, br);
349 m_palette.setBrush(QPalette::Disabled, QPalette::ButtonText, br);
350 idxBegin = PaletteModel::index(0, 0);
351 idxEnd = PaletteModel::index(static_cast<int>(m_roleNames.count()) - 1, 3);
352 break;
353 case QPalette::Window:
354 m_palette.setBrush(QPalette::Disabled, QPalette::Base, br);
355 m_palette.setBrush(QPalette::Disabled, QPalette::Window, br);
356 idxBegin = PaletteModel::index(QPalette::Base, 0);
357 break;
358 case QPalette::Highlight:
359 break;
360 default:
361 m_palette.setBrush(QPalette::Disabled, r, br);
362 break;
363 }
364 }
365 emit paletteChanged(m_palette);
366 emit dataChanged(idxBegin, idxEnd);
367 return true;
368 }
369 if (index.column() == 0 && role == Qt::EditRole) {
370 auto mask = m_palette.
371#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
372 resolveMask()
373#else
374 resolve()
375#endif
376 ;
377 const bool isMask = qvariant_cast<bool>(value);
378 const int r = index.row();
379 if (isMask) {
380 mask |= (1 << r);
381 } else {
382 m_palette.setBrush(
383 QPalette::Active, static_cast<QPalette::ColorRole>(r), m_parentPalette.brush(QPalette::Active, static_cast<QPalette::ColorRole>(r)));
384 m_palette.setBrush(QPalette::Inactive, static_cast<QPalette::ColorRole>(r),
385 m_parentPalette.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(r)));
386 m_palette.setBrush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r),
387 m_parentPalette.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(r)));
388 mask &= ~static_cast<decltype(mask)>(1 << index.row());
389 }
390 m_palette.
391#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
392 setResolveMask(mask);
393 m_palette = m_palette.resolve(m_palette)
394#else
395 resolve(mask)
396#endif
397 ;
398 emit paletteChanged(m_palette);
399 const QModelIndex idxEnd = PaletteModel::index(r, 3);
400 emit dataChanged(index, idxEnd);
401 return true;
402 }
403 return false;
404}
405
406Qt::ItemFlags PaletteModel::flags(const QModelIndex &index) const
407{
408 if (!index.isValid())
409 return Qt::ItemIsEnabled;
410 return Qt::ItemIsEditable | Qt::ItemIsEnabled;
411}
412
413QVariant PaletteModel::headerData(int section, Qt::Orientation orientation, int role) const
414{
415 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
416 if (section == 0)
417 return tr("Color Role");
418 if (section == groupToColumn(QPalette::Active))
419 return tr("Active");
420 if (section == groupToColumn(QPalette::Inactive))
421 return tr("Inactive");
422 if (section == groupToColumn(QPalette::Disabled))
423 return tr("Disabled");
424 }
425 return QVariant();
426}
427
429{
430 return m_palette;
431}
432
433void PaletteModel::setPalette(const QPalette &palette, const QPalette &parentPalette)
434{
435 m_parentPalette = parentPalette;
436 m_palette = palette;
437 const QModelIndex idxBegin = index(0, 0);
438 const QModelIndex idxEnd = index(static_cast<int>(m_roleNames.count()) - 1, 3);
439 emit dataChanged(idxBegin, idxEnd);
440}
441
442QPalette::ColorGroup PaletteModel::columnToGroup(int index) const
443{
444 if (index == 1)
445 return QPalette::Active;
446 if (index == 2)
447 return QPalette::Inactive;
448 return QPalette::Disabled;
449}
450
451int PaletteModel::groupToColumn(QPalette::ColorGroup group) const
452{
453 if (group == QPalette::Active)
454 return 1;
455 if (group == QPalette::Inactive)
456 return 2;
457 return 3;
458}
459
461 : QWidget(parent)
462 , m_button(new ColorButton(this))
463 , m_changed(false)
464{
465 auto *const layout = new QHBoxLayout(this);
466 layout->setContentsMargins(0, 0, 0, 0);
467 layout->addWidget(m_button);
468 connect(m_button, &ColorButton::colorChanged, this, &BrushEditor::brushChanged);
469 setFocusProxy(m_button);
470}
471
472void BrushEditor::setBrush(const QBrush &brush)
473{
474 m_button->setColor(brush.color());
475 m_changed = false;
476}
477
478QBrush BrushEditor::brush() const
479{
480 return QBrush(m_button->color());
481}
482
483void BrushEditor::brushChanged()
484{
485 m_changed = true;
486 emit changed(this);
487}
488
490{
491 return m_changed;
492}
493
495 : QWidget(parent)
496 , m_label(new QLabel(this))
497 , m_edited(false)
498{
499 QHBoxLayout *layout = new QHBoxLayout(this);
500 layout->setContentsMargins(0, 0, 0, 0);
501 layout->setSpacing(0);
502
503 layout->addWidget(m_label);
504 m_label->setAutoFillBackground(true);
505 m_label->setIndent(3); // same value as textMargin in QItemDelegate
506 setFocusProxy(m_label);
507
508 auto *const button = new QToolButton(this);
509 button->setToolButtonStyle(Qt::ToolButtonIconOnly);
510 button->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear")));
511 button->setIconSize(QSize(8, 8));
512 button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
513 layout->addWidget(button);
514 connect(button, &QAbstractButton::clicked, this, &RoleEditor::emitResetProperty);
515}
516
517void RoleEditor::setLabel(const QString &label)
518{
519 m_label->setText(label);
520}
521
523{
524 QFont font;
525 if (on == true) {
526 font.setBold(on);
527 }
528 m_label->setFont(font);
529 m_edited = on;
530}
531
533{
534 return m_edited;
535}
536
537void RoleEditor::emitResetProperty()
538{
539 setEdited(false);
540 emit changed(this);
541}
542
544 : QItemDelegate(parent)
545{
546}
547
548QWidget *ColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
549{
550 if (index.column() == 0) {
551 auto *const editor = new RoleEditor(parent);
552 connect(editor, &RoleEditor::changed, this, &ColorDelegate::commitData);
553 return editor;
554 }
555
556 using BrushEditorWidgetSignal = void (BrushEditor::*)(QWidget *);
557
558 auto *const editor = new BrushEditor(parent);
559 connect(editor, static_cast<BrushEditorWidgetSignal>(&BrushEditor::changed), this, &ColorDelegate::commitData);
560 editor->setFocusPolicy(Qt::NoFocus);
561 editor->installEventFilter(const_cast<ColorDelegate *>(this));
562 return editor;
563}
564
565void ColorDelegate::setEditorData(QWidget *ed, const QModelIndex &index) const
566{
567 if (index.column() == 0) {
568 const auto mask = qvariant_cast<bool>(index.model()->data(index, Qt::EditRole));
569 auto *const editor = static_cast<RoleEditor *>(ed);
570 editor->setEdited(mask);
571 const auto colorName = qvariant_cast<QString>(index.model()->data(index, Qt::DisplayRole));
572 editor->setLabel(colorName);
573 } else {
574 const auto br = qvariant_cast<QBrush>(index.model()->data(index, BrushRole));
575 auto *const editor = static_cast<BrushEditor *>(ed);
576 editor->setBrush(br);
577 }
578}
579
580void ColorDelegate::setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const
581{
582 if (index.column() == 0) {
583 const auto *const editor = static_cast<RoleEditor *>(ed);
584 const auto mask = editor->edited();
585 model->setData(index, mask, Qt::EditRole);
586 } else {
587 const auto *const editor = static_cast<BrushEditor *>(ed);
588 if (editor->changed()) {
589 QBrush br = editor->brush();
590 model->setData(index, br, BrushRole);
591 }
592 }
593}
594
595void ColorDelegate::updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const
596{
597 QItemDelegate::updateEditorGeometry(ed, option, index);
598 ed->setGeometry(ed->geometry().adjusted(0, 0, -1, -1));
599}
600
601void ColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const
602{
603 QStyleOptionViewItem option = opt;
604 const auto mask = qvariant_cast<bool>(index.model()->data(index, Qt::EditRole));
605 if (index.column() == 0 && mask) {
606 option.font.setBold(true);
607 }
608 auto br = qvariant_cast<QBrush>(index.model()->data(index, BrushRole));
609 if (br.style() == Qt::LinearGradientPattern || br.style() == Qt::RadialGradientPattern || br.style() == Qt::ConicalGradientPattern) {
610 painter->save();
611 painter->translate(option.rect.x(), option.rect.y());
612 painter->scale(option.rect.width(), option.rect.height());
613 QGradient gr = *(br.gradient());
614 gr.setCoordinateMode(QGradient::LogicalMode);
615 br = QBrush(gr);
616 painter->fillRect(0, 0, 1, 1, br);
617 painter->restore();
618 } else {
619 painter->save();
620 painter->setBrushOrigin(option.rect.x(), option.rect.y());
621 painter->fillRect(option.rect, br);
622 painter->restore();
623 }
624 QItemDelegate::paint(painter, option, index);
625
626 const QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
627 const QPen oldPen = painter->pen();
628 painter->setPen(QPen(color));
629
630 painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom());
631 painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
632 painter->setPen(oldPen);
633}
634
635QSize ColorDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const
636{
637 return QItemDelegate::sizeHint(opt, index) + QSize(4, 4);
638}
639
640} // namespace QtUtilities
The BrushEditor class is used by PaletteEditor.
void setBrush(const QBrush &brush)
BrushEditor(QWidget *parent=nullptr)
The ColorButton class is used by PaletteEditor.
Definition: colorbutton.h:15
void setColor(const QColor &color)
void colorChanged(const QColor &color)
The ColorDelegate class is used by PaletteEditor.
void setModelData(QWidget *ed, QAbstractItemModel *model, const QModelIndex &index) const override
void updateEditorGeometry(QWidget *ed, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setEditorData(QWidget *ed, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const override
ColorDelegate(QObject *parent=nullptr)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
The PaletteEditor class provides a dialog to customize a QPalette.
Definition: paletteeditor.h:29
static QPalette getPalette(QWidget *parent, const QPalette &init=QPalette(), const QPalette &parentPal=QPalette(), int *result=nullptr)
PaletteEditor(QWidget *parent)
void setPalette(const QPalette &palette)
The PaletteModel class is used by PaletteEditor.
Definition: paletteeditor.h:72
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QPalette getPalette() const
QVariant data(const QModelIndex &index, int role) const override
PaletteModel(QObject *parent=nullptr)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void setPalette(const QPalette &palette, const QPalette &parentPalette)
void paletteChanged(const QPalette &palette)
The RoleEditor class is used by PaletteEditor.
void changed(QWidget *widget)
RoleEditor(QWidget *parent=nullptr)
void setLabel(const QString &label)