Sat, 24 Mar 2018 12:58:01 +0200
added comment
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QGraphicsScene> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QGraphicsItem> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QMouseEvent> |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QScrollBar> |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
23 | #include <QColorDialog> |
974
b2fa5f89798a
Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
24 | #include "../colors.h" |
b2fa5f89798a
Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
971
diff
changeset
|
25 | #include "../guiutilities.h" |
950
5df69eb50182
Move colorSelector.cc to dialogs/colorselector.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
947
diff
changeset
|
26 | #include "../main.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
950
diff
changeset
|
27 | #include "../mainwindow.h" |
950
5df69eb50182
Move colorSelector.cc to dialogs/colorselector.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
947
diff
changeset
|
28 | #include "colorselector.h" |
5df69eb50182
Move colorSelector.cc to dialogs/colorselector.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents:
947
diff
changeset
|
29 | #include "ui_colorselector.h" |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
31 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
32 | * Constructs a color selection dialog. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
33 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
34 | ColorSelector::ColorSelector(QWidget* parent, LDColor defaultColor) : |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1252
diff
changeset
|
35 | QDialog {parent}, |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
36 | ui {*new Ui_ColorSelUi}, |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
37 | m_selectedColor {LDColor::nullColor} |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
38 | { |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
39 | ui.setupUi(this); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
41 | QGridLayout* gridLayout = new QGridLayout; |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
42 | |
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
43 | // Spawn color selector buttons |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
44 | for (LDColor color; color.isLDConfigColor(); ++color) |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
45 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
46 | QPushButton* button = new QPushButton {this}; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
47 | button->setMinimumSize({32, 32}); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
48 | button->setMaximumSize(button->minimumSize()); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
49 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
50 | if (color.isValid()) |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
51 | { |
1175
7cf1dbf97d90
No need for braces there...
Teemu Piippo <teemu@hecknology.net>
parents:
1174
diff
changeset
|
52 | QColor faceColor = color.faceColor(); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
53 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
54 | if (color == MainColor) |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
55 | { |
1323
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1319
diff
changeset
|
56 | faceColor = config::mainColor(); |
05b3e173c900
Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents:
1319
diff
changeset
|
57 | faceColor.setAlphaF(config::mainColorAlpha()); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
58 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
60 | QString edgeColor = luma(faceColor) < 80 ? "white" : "black"; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
61 | button->setAutoFillBackground(true); |
1252 | 62 | button->setStyleSheet(format( |
1296
aee618d087ff
Added vertex object editing dialog
Teemu Piippo <teemu@hecknology.net>
parents:
1252
diff
changeset
|
63 | "background-color: %1; color: %2; border:none;", |
1252 | 64 | faceColor.name(QColor::HexArgb), |
65 | edgeColor | |
66 | )); | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
67 | button->setCheckable(true); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
68 | button->setText(QString::number(color.index())); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
69 | button->setToolTip(format("%1: %2", color.index(), color.name())); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
70 | m_buttons[color] = button; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
71 | m_buttonsReversed[button] = color; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
72 | connect(button, SIGNAL(clicked(bool)), this, SLOT(colorButtonClicked())); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
73 | } |
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
74 | else |
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
75 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
76 | button->setEnabled(false); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
77 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
79 | gridLayout->addWidget(button, color.index() / columnCount, color.index() % columnCount); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
80 | } |
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
81 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
82 | QWidget* gridContainerWidget = new QWidget; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
83 | gridContainerWidget->setLayout(gridLayout); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
84 | ui.definedColors->setWidget(gridContainerWidget); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
85 | connect(ui.directColor, SIGNAL(clicked(bool)), this, SLOT(chooseDirectColor())); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
86 | ui.definedColors->setMinimumWidth(ui.definedColors->widget()->width() + 16); |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
87 | |
801
f6abc9eb4217
- made transparent direct colors a compile-time opt-in since it appears to be non-standard
Santeri Piippo <crimsondusk64@gmail.com>
parents:
796
diff
changeset
|
88 | #ifdef TRANSPARENT_DIRECT_COLORS |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
89 | connect(ui.transparentDirectColor, SIGNAL(clicked(bool)), this, SLOT(transparentCheckboxClicked())); |
801
f6abc9eb4217
- made transparent direct colors a compile-time opt-in since it appears to be non-standard
Santeri Piippo <crimsondusk64@gmail.com>
parents:
796
diff
changeset
|
90 | #else |
947
edc8fc0f37f2
ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
91 | ui.transparentDirectColor->hide(); |
801
f6abc9eb4217
- made transparent direct colors a compile-time opt-in since it appears to be non-standard
Santeri Piippo <crimsondusk64@gmail.com>
parents:
796
diff
changeset
|
92 | #endif |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
93 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
94 | setSelectedColor(defaultColor); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
97 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
98 | * Destructs the color selection dialog. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
99 | */ |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | ColorSelector::~ColorSelector() |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
947
edc8fc0f37f2
ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
946
diff
changeset
|
102 | delete &ui; |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
105 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
106 | * Handles the press of a color button. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
107 | */ |
878
945e44575b3e
- changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
108 | void ColorSelector::colorButtonClicked() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
110 | QPushButton* button = qobject_cast<QPushButton*>(sender()); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
111 | LDColor color = m_buttonsReversed.value(button, LDColor::nullColor); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
113 | if (color.isValid()) |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
114 | setSelectedColor(color); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
115 | } |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
117 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
118 | * Asks the user for a direct color. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
119 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
120 | void ColorSelector::chooseDirectColor() |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
121 | { |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
122 | QColor defaultColor = selectedColor() != -1 ? selectedColor().faceColor() : Qt::white; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
123 | QColor newColor = QColorDialog::getColor(defaultColor); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
125 | if (newColor.isValid()) |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
126 | setSelectedColor({newColor, ui.transparentDirectColor->isChecked()}); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
129 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
130 | * Handles the click of the transparent direct color option (only available of transparent direct colors are enabled). |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
131 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
132 | void ColorSelector::transparentCheckboxClicked() |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
134 | if (selectedColor().isDirect()) |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
135 | setSelectedColor({selectedColor().faceColor(), ui.transparentDirectColor->isChecked()}); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
138 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
139 | * Convenience function for invoking the color selection dialog. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
140 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
141 | bool ColorSelector::selectColor(QWidget* parent, LDColor& color, LDColor defaultColor) |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
142 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
143 | ColorSelector dialog {parent, defaultColor}; |
795
195fa1fff9c3
- changed all color usage to use LDColor classes instead of color indices. Added support for direct colors.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
757
diff
changeset
|
144 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
145 | if (dialog.exec() and dialog.selectedColor().isValid()) |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
147 | color = dialog.selectedColor(); |
655
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | return true; |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | } |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
b376645315ab
- renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | return false; |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
855
diff
changeset
|
152 | } |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
153 | |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
154 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
155 | * Returns the currently selected color. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
156 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
157 | LDColor ColorSelector::selectedColor() const |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
158 | { |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
159 | return m_selectedColor; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
160 | } |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
161 | |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
162 | /* |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
163 | * Changes the selected color to the one provided, and updates all relevant widgets. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
164 | */ |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
165 | void ColorSelector::setSelectedColor(LDColor newColor) |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
166 | { |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
167 | // Uncheck the button we previously had pressed. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
168 | QPushButton* button = m_buttons.value(m_selectedColor); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
169 | |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
170 | if (button) |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
171 | button->setChecked(false); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
172 | |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
173 | // Select the new color. |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
174 | m_selectedColor = newColor; |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
175 | button = m_buttons.value(newColor); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
176 | |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
177 | if (button) |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
178 | button->setChecked(true); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
179 | |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
180 | if (m_selectedColor.isValid()) |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
181 | { |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
182 | ui.colorLabel->setText(format("%1 - %2", |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
183 | newColor.indexString(), |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
184 | newColor.isDirect() ? newColor.faceColor().name() : newColor.name())); |
1252 | 185 | ui.iconLabel->setPixmap(makeColorIcon(newColor, 16).pixmap(16, 16)); |
1174
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
186 | ui.transparentDirectColor->setEnabled(newColor.isDirect()); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
187 | ui.transparentDirectColor->setChecked(newColor.isDirect() and newColor.faceColor().alphaF() < 1.0); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
188 | } |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
189 | else |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
190 | { |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
191 | ui.colorLabel->setText("---"); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
192 | ui.iconLabel->setPixmap({}); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
193 | ui.transparentDirectColor->setChecked(false); |
91696a2e022c
Cleanup ColorSelector, moved direct color composition to a new LDColor constructor.
Teemu Piippo <teemu@hecknology.net>
parents:
1173
diff
changeset
|
194 | } |
1010
969b48eddd6b
A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
195 | } |