Thu, 05 Dec 2013 23:20:50 +0200
- upgraded the PROPERTY macro, resulting in a major code refactor
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
471 | 17 | * ===================================================================== |
18 | * | |
19 | * colorSelectDialog.cpp: Color selector box. | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
199
10dd5909a50e
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
22 | #include <QGraphicsScene> |
10dd5909a50e
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
23 | #include <QGraphicsItem> |
10dd5909a50e
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
24 | #include <QMouseEvent> |
10dd5909a50e
Made Qt file includes more proper (<QLineEdit> instead of <qlineedit.h>), merged setContentsDialog.cpp into dialogs.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
25 | #include <QScrollBar> |
202
a027f6fc6141
Un-templated CheckBoxGroup, moved it and RadioButton into widgets.cpp/widgets.h; removed license text tab because I think LICENSE is enough.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
199
diff
changeset
|
26 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | #include "gui.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "colorSelectDialog.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | #include "colors.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "config.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "misc.h" |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
33 | #include "ui_colorsel.h" |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
34 | #include "moc_colorSelectDialog.cpp" |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
36 | static const int g_numColumns = 16; |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
37 | static const int g_squareSize = 32; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
39 | extern_cfg (String, gl_maincolor); |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
40 | extern_cfg (Float, gl_maincolor_alpha); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
43 | // ----------------------------------------------------------------------------- |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
44 | ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
45 | { // Remove the default color if it's invalid |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
46 | if (!getColor (defval)) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | defval = -1; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
48 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
49 | m_firstResize = true; |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
50 | ui = new Ui_ColorSelUI; |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
51 | ui->setupUi (this); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
52 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
53 | m_scene = new QGraphicsScene; |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
54 | ui->viewport->setScene (m_scene); |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
55 | setSelection (getColor (defval)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
56 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | // not really an icon but eh |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
58 | m_scene->setBackgroundBrush (getIcon ("checkerboard")); |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
59 | drawScene(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
60 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
61 | int width = viewportWidth(); |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
62 | ui->viewport->setMinimumWidth (width); |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
63 | ui->viewport->setMaximumWidth (width); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
64 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
65 | drawColorInfo(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
69 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
70 | ColorSelector::~ColorSelector() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
71 | { delete ui; |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
72 | } |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
73 | |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
74 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
75 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
76 | void ColorSelector::drawScene() |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
77 | { const int numCols = g_numColumns; |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
78 | const int square = g_squareSize; |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
79 | const int g_maxHeight = (numRows() * square); |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
80 | QRect sceneRect (0, 0, viewportWidth(), g_maxHeight); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
81 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
82 | m_scene->setSceneRect (sceneRect); |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
83 | ui->viewport->setSceneRect (sceneRect); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
84 | |
202
a027f6fc6141
Un-templated CheckBoxGroup, moved it and RadioButton into widgets.cpp/widgets.h; removed license text tab because I think LICENSE is enough.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
199
diff
changeset
|
85 | const double penWidth = 1.0f; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
86 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | // Draw the color rectangles. |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
88 | m_scene->clear(); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
89 | |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
90 | for (int i = 0; i < MAX_COLORS; ++i) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
91 | { LDColor* info = ::getColor (i); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
92 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
93 | if (!info) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | continue; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
95 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
96 | const double x = (i % numCols) * square; |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
97 | const double y = (i / numCols) * square; |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
98 | const double w = square - (penWidth / 2); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
99 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
100 | QColor col = info->faceColor; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
101 | |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
102 | if (i == maincolor) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
103 | { // Use the user preferences for main color here |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
104 | col = QColor (gl_maincolor); |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
105 | col.setAlpha (gl_maincolor_alpha * 255.0f); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
107 | |
397
a1d3d558d3fa
Apply the proper edge color in the color sector too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
396
diff
changeset
|
108 | QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
109 | m_scene->addRect (x, y, w, w, pen, col); |
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
110 | QGraphicsTextItem* numtext = m_scene->addText (fmt ("%1", i)); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
111 | numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black); |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
112 | numtext->setPos (x, y); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
113 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
114 | if (getSelection() && i == getSelection()->index) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
115 | { auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
116 | curspic->setPos (x, y); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
122 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
123 | int ColorSelector::numRows() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
124 | { return (MAX_COLORS / g_numColumns); |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
125 | } |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
126 | |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
127 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
128 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
129 | int ColorSelector::viewportWidth() const |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
130 | { return g_numColumns * g_squareSize + 21; |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
131 | } |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
132 | |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
133 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
134 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
135 | void ColorSelector::drawColorInfo() |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
136 | { if (!getSelection()) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
137 | { ui->colorLabel->setText ("---"); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | return; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
140 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
141 | ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
145 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
146 | void ColorSelector::resizeEvent (QResizeEvent* ev) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
147 | { // If this is the first resize, check if we need to scroll down to see the |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
148 | // currently selected color. We cannot do this in the constructor because the |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
149 | // height is not set properly there. |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
150 | if (m_firstResize) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
151 | { int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
152 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
153 | if (getSelection() && getSelection()->index >= visibleColors) |
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
154 | { int y = (getSelection()->index / g_numColumns) * g_squareSize; |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
155 | ui->viewport->verticalScrollBar()->setValue (y); |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
156 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
157 | |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
158 | m_firstResize = false; |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
159 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
160 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
410
diff
changeset
|
161 | (void) ev; |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
162 | drawScene(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
166 | // ----------------------------------------------------------------------------- |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
167 | void ColorSelector::mousePressEvent (QMouseEvent* event) |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
168 | { QPointF scenepos = ui->viewport->mapToScene (event->pos()); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
169 | |
498
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
170 | int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize; |
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
171 | int y = (scenepos.y() - (g_squareSize / 2)) / g_squareSize; |
791c831c8020
further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
493
diff
changeset
|
172 | int idx = (y * g_numColumns) + x; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
173 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
174 | LDColor* col = ::getColor (idx); |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
175 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
176 | if (!col) |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
177 | return; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
178 | |
396
582bea871af9
restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
364
diff
changeset
|
179 | setSelection (col); |
327
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
180 | drawScene(); |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
181 | drawColorInfo(); |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
182 | } |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
183 | |
9ea604af1319
Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
286
diff
changeset
|
184 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
421
diff
changeset
|
185 | // ----------------------------------------------------------------------------- |
538
2f85d4d286e5
- ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents:
498
diff
changeset
|
186 | bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
187 | { ColorSelector dlg (defval, parent); |
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
188 | |
539
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
189 | if (dlg.exec() && dlg.getSelection() != null) |
72ad83a67165
- upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
538
diff
changeset
|
190 | { val = dlg.getSelection()->index; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
191 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | } |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
193 | |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | return false; |
493
16766ac1bbd9
last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents:
491
diff
changeset
|
195 | } |