src/widgets/colorindexinput.cpp

Sat, 08 Apr 2023 15:34:32 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 08 Apr 2023 15:34:32 +0300
changeset 350
676d0b43b577
parent 264
76a025db4948
permissions
-rw-r--r--

Opening recently opened files works again now

264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 258
diff changeset
1 #include <ui_colorindexinput.h>
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 258
diff changeset
2 #include "src/uiutilities.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 258
diff changeset
3 #include "src/widgets/colorindexinput.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 258
diff changeset
4 #include "src/widgets/colorselectdialog.h"
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
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 ui{*new Ui_ColorIndexInput}
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 this->ui.setupUi(this);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 connect(this->ui.button, &QPushButton::clicked, [this]()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 const int result = dialog.exec();
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 if (result == QDialog::Accepted)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 this->ui.index->setValue(dialog.currentColor().index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 });
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
27 if (face.has_value()) {
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
28 uiutilities::colorizeWidget(this->ui.button, *face);
1a4342d80de7 Refactor colors.cpp/.h
Teemu Piippo <teemu@hecknology.net>
parents: 200
diff changeset
29 }
178
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 Q_EMIT this->colorChanged({value});
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
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 ColorIndexInput::~ColorIndexInput()
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 delete &this->ui;
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 ldraw::Color ColorIndexInput::selectedColor() const
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 return {this->ui.index->value()};
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 }
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 void ColorIndexInput::setSelectedColor(ldraw::Color color)
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 this->ui.index->setValue(color.index);
a23024fc98e0 fix saving
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }

mercurial