Fri, 17 Sep 2021 22:38:53 +0300
Add missing changes to canvas.h
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include <QColorDialog> |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "colorbutton.h" |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | ColorButton::ColorButton(const QColor& color, QWidget* parent) : |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | ColorButton{parent} |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | this->setSelectedColor(color); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | } |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | ColorButton::ColorButton(QWidget* parent) : |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | QPushButton{parent} |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | connect(this, &QPushButton::clicked, [&]() |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | const QColor color = QColorDialog::getColor(this->storedSelectedColor, this->parentWidget()); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | if (color.isValid()) |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | this->setSelectedColor(color); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | } |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | }); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | } |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | QColor ColorButton::selectedColor() const |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | return this->storedSelectedColor; |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | } |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | void ColorButton::setSelectedColor(const QColor& newSelectedColor) |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | this->storedSelectedColor = newSelectedColor; |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | this->setStyleSheet(QString{"background-color: %1"}.arg(newSelectedColor.name())); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | this->setText(newSelectedColor.name()); |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | } |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 |