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