Wed, 25 May 2022 17:47:06 +0300
simplify further
178 | 1 | #include "colorindexinput.h" |
2 | #include "ui_colorindexinput.h" | |
3 | #include "colorselectdialog.h" | |
4 | #include "uiutilities.h" | |
5 | ||
6 | ColorIndexInput::ColorIndexInput(Document *document, ldraw::Color color, QWidget *parent) : | |
7 | QWidget{parent}, | |
8 | document{document}, | |
9 | ui{*new Ui_ColorIndexInput} | |
10 | { | |
11 | this->ui.setupUi(this); | |
12 | connect(this->ui.button, &QPushButton::clicked, [this]() | |
13 | { | |
14 | ColorSelectDialog dialog{this->document->colorTable, this->document}; | |
15 | const int result = dialog.exec(); | |
16 | if (result == QDialog::Accepted) | |
17 | { | |
18 | this->ui.index->setValue(dialog.currentColor().index); | |
19 | } | |
20 | }); | |
21 | connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value) | |
22 | { | |
23 | this->ui.button->setText(ldraw::colorDisplayName({value}, this->document->colorTable)); | |
24 | uiutilities::colorizeWidget(this->ui.button, ldraw::colorFace({value}, this->document->colorTable)); | |
25 | Q_EMIT this->colorChanged({value}); | |
26 | }); | |
27 | this->ui.index->setValue(color.index); | |
28 | } | |
29 | ||
30 | ColorIndexInput::~ColorIndexInput() | |
31 | { | |
32 | delete &this->ui; | |
33 | } | |
34 | ||
35 | ldraw::Color ColorIndexInput::selectedColor() const | |
36 | { | |
37 | return {this->ui.index->value()}; | |
38 | } | |
39 | ||
40 | void ColorIndexInput::setSelectedColor(ldraw::Color color) | |
41 | { | |
42 | this->ui.index->setValue(color.index); | |
43 | } |