src/widgets/colorindexinput.cpp

Wed, 22 Jun 2022 16:53:35 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 22 Jun 2022 16:53:35 +0300
changeset 250
2837b549e616
parent 214
8e1fe64ce4e3
child 258
fe094d0687ad
permissions
-rw-r--r--

I felt that the compiler was too kind to me, so I enabled a big pile of warnings

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
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
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
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 {
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
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 {
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
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
26 if (face.has_value()) {
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
27 uiutilities::colorizeWidget(this->ui.button, *face);
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
28 }
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 Q_EMIT this->colorChanged({value});
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 });
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 ColorIndexInput::~ColorIndexInput()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 delete &this->ui;
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 ldraw::Color ColorIndexInput::selectedColor() const
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 return {this->ui.index->value()};
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 void ColorIndexInput::setSelectedColor(ldraw::Color color)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 }

mercurial