Sun, 26 Jun 2022 20:27:04 +0300
pi is no longer a template
178 | 1 | #include "colorindexinput.h" |
2 | #include "ui_colorindexinput.h" | |
3 | #include "colorselectdialog.h" | |
4 | #include "uiutilities.h" | |
5 | ||
258
fe094d0687ad
Add widgets to object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
6 | ColorIndexInput::ColorIndexInput(QWidget *parent) : |
178 | 7 | QWidget{parent}, |
8 | ui{*new Ui_ColorIndexInput} | |
9 | { | |
258
fe094d0687ad
Add widgets to object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
10 | static const ColorTable emptyColorTable; |
fe094d0687ad
Add widgets to object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
11 | this->colorTable = &emptyColorTable; |
178 | 12 | this->ui.setupUi(this); |
13 | connect(this->ui.button, &QPushButton::clicked, [this]() | |
14 | { | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
15 | ColorSelectDialog dialog{*this->colorTable, this}; |
178 | 16 | const int result = dialog.exec(); |
17 | if (result == QDialog::Accepted) | |
18 | { | |
19 | this->ui.index->setValue(dialog.currentColor().index); | |
20 | } | |
21 | }); | |
22 | connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value) | |
23 | { | |
214
8e1fe64ce4e3
begin refactor of gl side
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
205
diff
changeset
|
24 | 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
|
25 | 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
|
26 | this->ui.button->setText(displayName.value_or(tr("???"))); |
205 | 27 | if (face.has_value()) { |
28 | uiutilities::colorizeWidget(this->ui.button, *face); | |
29 | } | |
178 | 30 | Q_EMIT this->colorChanged({value}); |
31 | }); | |
258
fe094d0687ad
Add widgets to object editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
214
diff
changeset
|
32 | this->ui.index->setValue(MAIN_COLOR.index); |
178 | 33 | } |
34 | ||
35 | ColorIndexInput::~ColorIndexInput() | |
36 | { | |
37 | delete &this->ui; | |
38 | } | |
39 | ||
40 | ldraw::Color ColorIndexInput::selectedColor() const | |
41 | { | |
42 | return {this->ui.index->value()}; | |
43 | } | |
44 | ||
45 | void ColorIndexInput::setSelectedColor(ldraw::Color color) | |
46 | { | |
47 | this->ui.index->setValue(color.index); | |
48 | } |