src/widgets/colorindexinput.cpp

Wed, 08 Jun 2022 23:02:04 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 08 Jun 2022 23:02:04 +0300
changeset 207
5315358a7d91
parent 205
1a4342d80de7
child 214
8e1fe64ce4e3
permissions
-rw-r--r--

well that's embarrassing

178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "colorindexinput.h"
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "ui_colorindexinput.h"
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "colorselectdialog.h"
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 #include "uiutilities.h"
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
6 ColorIndexInput::ColorIndexInput(EditorTabWidget *document, ColorIndex color, QWidget *parent) :
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 QWidget{parent},
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 document{document},
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ui{*new Ui_ColorIndexInput}
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 this->ui.setupUi(this);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 connect(this->ui.button, &QPushButton::clicked, [this]()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 ColorSelectDialog dialog{this->document->colorTable, this->document};
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 const int result = dialog.exec();
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 if (result == QDialog::Accepted)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 this->ui.index->setValue(dialog.currentColor().index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 });
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 {
205
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
23 this->ui.button->setText(colorDisplayName({value}, this->document->colorTable).value_or("???"));
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
24 const opt<QColor> face = colorFace({value}, this->document->colorTable);
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
25 if (face.has_value()) {
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
26 uiutilities::colorizeWidget(this->ui.button, *face);
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
27 }
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 Q_EMIT this->colorChanged({value});
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 });
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 ColorIndexInput::~ColorIndexInput()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 delete &this->ui;
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 ldraw::Color ColorIndexInput::selectedColor() const
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 return {this->ui.index->value()};
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 void ColorIndexInput::setSelectedColor(ldraw::Color color)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 }

mercurial