src/dialogs/colorselector.cpp

Tue, 15 Nov 2016 17:37:31 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 15 Nov 2016 17:37:31 +0200
changeset 1046
f4a7b56c7eb2
parent 1017
fc1c13db9618
child 1072
9ce9496427f2
permissions
-rw-r--r--

Cleanup PartDownloader

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
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
3 * Copyright (C) 2013 - 2016 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 "../miscallenous.h"
5df69eb50182 Move colorSelector.cc to dialogs/colorselector.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 947
diff changeset
29 #include "colorselector.h"
5df69eb50182 Move colorSelector.cc to dialogs/colorselector.cpp
Teemu Piippo <crimsondusk64@gmail.com>
parents: 947
diff changeset
30 #include "ui_colorselector.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
32 enum { NUM_COLUMNS = 16 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
34 ColorSelector::ColorSelector (QWidget* parent, LDColor defaultvalue) :
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
35 QDialog (parent),
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
36 HierarchyElement (parent),
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
37 ui (*new Ui_ColorSelUi),
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
38 m_selection (defaultvalue)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 m_firstResize = true;
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
41 ui.setupUi (this);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
43 QGridLayout* layout = new QGridLayout (this);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
44
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
45 // Spawn color selector buttons
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
46 for (LDColor ldcolor; ldcolor.isLDConfigColor(); ++ldcolor)
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
47 {
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
48 QPushButton* button = new QPushButton (this);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
49 button->setMinimumSize (QSize (32, 32));
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
50 button->setMaximumSize (button->minimumSize());
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
51
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
52 if (ldcolor.isValid ())
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
53 {
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
54 QColor color (ldcolor.faceColor());
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
55
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
56 if (ldcolor == MainColor)
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
57 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
58 color = QColor (m_config->mainColor());
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
59 color.setAlphaF (m_config->mainColorAlpha());
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
60 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
62 QString color2name (luma (color) < 80 ? "white" : "black");
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
63 button->setAutoFillBackground (true);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
64 button->setStyleSheet (format ("background-color: rgba(%1, %2, %3, %4); color: %5",
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
65 color.red(), color.green(), color.blue(), color.alpha(), color2name));
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
66 button->setCheckable (true);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
67 button->setText (QString::number (ldcolor.index()));
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
68 button->setToolTip (format ("%1: %2", ldcolor.index(), ldcolor.name()));
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
69 m_buttons[ldcolor.index()] = button;
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
70 m_buttonsReversed[button] = ldcolor.index();
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
71 connect (button, SIGNAL (clicked(bool)), this, SLOT (colorButtonClicked()));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
73 if (ldcolor == selection())
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
74 button->setChecked (true);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
75 }
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
76 else
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
77 {
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
78 button->setEnabled (false);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
79 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
81 layout->addWidget (button, ldcolor.index() / NUM_COLUMNS, ldcolor.index() % NUM_COLUMNS);
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
82 }
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
83
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
84 QWidget* widget = new QWidget();
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
85 widget->setLayout (layout);
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
86 ui.definedColors->setWidget (widget);
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
87 connect (ui.directColor, SIGNAL (clicked (bool)), this, SLOT (chooseDirectColor()));
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
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
89 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
90
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
91 #ifdef TRANSPARENT_DIRECT_COLORS
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
92 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
93 #else
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
94 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
95 #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
96
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 drawColorInfo();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
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
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
105 void ColorSelector::colorButtonClicked()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 {
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
107 QPushButton* button = qobject_cast<QPushButton*> (sender());
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
108 auto it = m_buttonsReversed.find (button);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
109 LDColor color;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 974
diff changeset
111 if (Q_UNLIKELY (button == nullptr or it == m_buttonsReversed.end()
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
112 or not (color = *it).isValid()))
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
113 {
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
114 print ("colorButtonClicked() called with invalid sender");
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
115 return;
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
116 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
118 if (selection().isValid())
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
119 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
120 auto button = m_buttons.find (selection().index());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
122 if (button != m_buttons.end())
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
123 (*button)->setChecked (false);
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
124 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
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
126 m_selection = color;
878
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
127 button->setChecked (true);
945e44575b3e - changed the unorthodox color selection grid into a push button grid
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
128 drawColorInfo();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 void ColorSelector::drawColorInfo()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
133 if (not selection().isValid())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 {
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
135 ui.colorLabel->setText ("---");
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
136 ui.iconLabel->setPixmap (QPixmap());
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
137 ui.transparentDirectColor->setChecked (false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
141 ui.colorLabel->setText (format ("%1 - %2", selection().indexString(),
806
4240f47aa2d4 - moved most of LDColorData API into LDColor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 801
diff changeset
142 (selection().isDirect() ? "<direct color>" : selection().name())));
974
b2fa5f89798a Added a GuiUtilities class to contain useful non-MainWindow-related GUI functions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
143 ui.iconLabel->setPixmap (guiUtilities()->makeColorIcon (selection(), 16).pixmap (16, 16));
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
144
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
145 #ifdef TRANSPARENT_DIRECT_COLORS
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
146 ui.transparentDirectColor->setEnabled (selection().isDirect());
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
147 ui.transparentDirectColor->setChecked (selection().isDirect() and selection().faceColor().alphaF() < 1.0);
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
148 #else
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
149 ui.transparentDirectColor->setChecked (false);
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
150 ui.transparentDirectColor->setEnabled (false);
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
151 #endif
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
154 void ColorSelector::selectDirectColor (QColor color)
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
155 {
947
edc8fc0f37f2 ColorSelector: `ui->` -> `ui.`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 946
diff changeset
156 qint32 colorIndex = (ui.transparentDirectColor->isChecked() ? 0x03000000 : 0x02000000);
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
157 colorIndex |= (color.red() << 16) | (color.green() << 8) | (color.blue());
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
158 m_selection = colorIndex;
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
159 drawColorInfo();
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
160 }
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
161
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
162 void ColorSelector::chooseDirectColor()
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
163 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
164 QColor defcolor = selection() != -1 ? selection().faceColor() : Qt::white;
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
165 QColor newcolor = QColorDialog::getColor (defcolor);
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
166
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
167 if (not newcolor.isValid())
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
168 return; // canceled
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
169
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
170 selectDirectColor (newcolor);
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
171 }
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
172
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
173 void ColorSelector::transparentCheckboxClicked()
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
174 {
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
175 if (selection().isDirect())
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
176 selectDirectColor (selection().faceColor());
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
177 }
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
178
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
179 bool ColorSelector::selectColor (QWidget* parent, LDColor& val, LDColor defaultvalue)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 {
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
181 ColorSelector dlg (parent, defaultvalue);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 878
diff changeset
183 if (dlg.exec() and dlg.selection().isValid())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 {
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
185 val = dlg.selection();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 return false;
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
190 }
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
191
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
192 LDColor ColorSelector::selection() const
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
193 {
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
194 return m_selection;
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 }

mercurial