src/widgets/colorindexinput.cpp

Wed, 25 May 2022 17:47:06 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 25 May 2022 17:47:06 +0300
changeset 194
be056e87c8ca
parent 178
a23024fc98e0
child 200
ca23936b455b
permissions
-rw-r--r--

simplify further

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
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 ColorIndexInput::ColorIndexInput(Document *document, ldraw::Color color, QWidget *parent) :
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 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 this->ui.button->setText(ldraw::colorDisplayName({value}, this->document->colorTable));
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 uiutilities::colorizeWidget(this->ui.button, ldraw::colorFace({value}, this->document->colorTable));
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 Q_EMIT this->colorChanged({value});
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 });
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 ColorIndexInput::~ColorIndexInput()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 delete &this->ui;
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 ldraw::Color ColorIndexInput::selectedColor() const
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 return {this->ui.index->value()};
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 void ColorIndexInput::setSelectedColor(ldraw::Color color)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }

mercurial