src/widgets/colorindexinput.cpp

changeset 214
8e1fe64ce4e3
parent 205
1a4342d80de7
child 258
fe094d0687ad
equal deleted inserted replaced
213:ee5758ddb6d2 214:8e1fe64ce4e3
1 #include "colorindexinput.h" 1 #include "colorindexinput.h"
2 #include "ui_colorindexinput.h" 2 #include "ui_colorindexinput.h"
3 #include "colorselectdialog.h" 3 #include "colorselectdialog.h"
4 #include "uiutilities.h" 4 #include "uiutilities.h"
5 5
6 ColorIndexInput::ColorIndexInput(EditorTabWidget *document, ColorIndex color, QWidget *parent) : 6 ColorIndexInput::ColorIndexInput(ColorTable *colorTable, ColorIndex color, QWidget *parent) :
7 QWidget{parent}, 7 QWidget{parent},
8 document{document}, 8 colorTable{colorTable},
9 ui{*new Ui_ColorIndexInput} 9 ui{*new Ui_ColorIndexInput}
10 { 10 {
11 this->ui.setupUi(this); 11 this->ui.setupUi(this);
12 connect(this->ui.button, &QPushButton::clicked, [this]() 12 connect(this->ui.button, &QPushButton::clicked, [this]()
13 { 13 {
14 ColorSelectDialog dialog{this->document->colorTable, this->document}; 14 ColorSelectDialog dialog{*this->colorTable, this};
15 const int result = dialog.exec(); 15 const int result = dialog.exec();
16 if (result == QDialog::Accepted) 16 if (result == QDialog::Accepted)
17 { 17 {
18 this->ui.index->setValue(dialog.currentColor().index); 18 this->ui.index->setValue(dialog.currentColor().index);
19 } 19 }
20 }); 20 });
21 connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value) 21 connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value)
22 { 22 {
23 this->ui.button->setText(colorDisplayName({value}, this->document->colorTable).value_or("???")); 23 const opt<QString> displayName = colorDisplayName({value}, *this->colorTable);
24 const opt<QColor> face = colorFace({value}, this->document->colorTable); 24 const opt<QColor> face = colorFace({value}, *this->colorTable);
25 this->ui.button->setText(displayName.value_or(tr("???")));
25 if (face.has_value()) { 26 if (face.has_value()) {
26 uiutilities::colorizeWidget(this->ui.button, *face); 27 uiutilities::colorizeWidget(this->ui.button, *face);
27 } 28 }
28 Q_EMIT this->colorChanged({value}); 29 Q_EMIT this->colorChanged({value});
29 }); 30 });

mercurial