Sat, 11 Jun 2022 15:20:24 +0300
Rewrite prune to use graphs rather than O(n²) searches
178 | 1 | #include "colorindexinput.h" |
2 | #include "ui_colorindexinput.h" | |
3 | #include "colorselectdialog.h" | |
4 | #include "uiutilities.h" | |
5 | ||
205 | 6 | ColorIndexInput::ColorIndexInput(EditorTabWidget *document, ColorIndex color, QWidget *parent) : |
178 | 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 | { | |
205 | 23 | this->ui.button->setText(colorDisplayName({value}, this->document->colorTable).value_or("???")); |
24 | const opt<QColor> face = colorFace({value}, this->document->colorTable); | |
25 | if (face.has_value()) { | |
26 | uiutilities::colorizeWidget(this->ui.button, *face); | |
27 | } | |
178 | 28 | Q_EMIT this->colorChanged({value}); |
29 | }); | |
30 | this->ui.index->setValue(color.index); | |
31 | } | |
32 | ||
33 | ColorIndexInput::~ColorIndexInput() | |
34 | { | |
35 | delete &this->ui; | |
36 | } | |
37 | ||
38 | ldraw::Color ColorIndexInput::selectedColor() const | |
39 | { | |
40 | return {this->ui.index->value()}; | |
41 | } | |
42 | ||
43 | void ColorIndexInput::setSelectedColor(ldraw::Color color) | |
44 | { | |
45 | this->ui.index->setValue(color.index); | |
46 | } |