Mon, 20 Jun 2022 22:21:53 +0300
fix typo
178 | 1 | #include "colorindexinput.h" |
2 | #include "ui_colorindexinput.h" | |
3 | #include "colorselectdialog.h" | |
4 | #include "uiutilities.h" | |
5 | ||
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
6 | ColorIndexInput::ColorIndexInput(ColorTable *colorTable, ColorIndex color, QWidget *parent) : |
178 | 7 | QWidget{parent}, |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
8 | colorTable{colorTable}, |
178 | 9 | ui{*new Ui_ColorIndexInput} |
10 | { | |
11 | this->ui.setupUi(this); | |
12 | connect(this->ui.button, &QPushButton::clicked, [this]() | |
13 | { | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
14 | ColorSelectDialog dialog{*this->colorTable, this}; |
178 | 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 | { | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
23 | const opt<QString> displayName = colorDisplayName({value}, *this->colorTable); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
24 | const opt<QColor> face = colorFace({value}, *this->colorTable); |
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
25 | this->ui.button->setText(displayName.value_or(tr("???"))); |
205 | 26 | if (face.has_value()) { |
27 | uiutilities::colorizeWidget(this->ui.button, *face); | |
28 | } | |
178 | 29 | Q_EMIT this->colorChanged({value}); |
30 | }); | |
31 | this->ui.index->setValue(color.index); | |
32 | } | |
33 | ||
34 | ColorIndexInput::~ColorIndexInput() | |
35 | { | |
36 | delete &this->ui; | |
37 | } | |
38 | ||
39 | ldraw::Color ColorIndexInput::selectedColor() const | |
40 | { | |
41 | return {this->ui.index->value()}; | |
42 | } | |
43 | ||
44 | void ColorIndexInput::setSelectedColor(ldraw::Color color) | |
45 | { | |
46 | this->ui.index->setValue(color.index); | |
47 | } |