src/colorSelectDialog.cpp

Tue, 16 Jul 2013 20:01:36 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Jul 2013 20:01:36 +0300
changeset 397
a1d3d558d3fa
parent 396
582bea871af9
child 410
a5aebcf4a1c8
permissions
-rw-r--r--

Apply the proper edge color in the color sector too

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/>.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
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
19 #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
20 #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
21 #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
22 #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
23
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "common.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "gui.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "colorSelectDialog.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "colors.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "config.h"
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #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
30 #include "ui_colorsel.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
32 static const int g_numColumns = 16;
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
33 static const short g_squareSize = 32;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
35 extern_cfg (str, gl_maincolor);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
36 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
37
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
41 ColorSelector::ColorSelector (short defval, QWidget* parent) : QDialog (parent) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 // Remove the default color if it's invalid
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
43 if (!::getColor (defval))
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 defval = -1;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
45
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
46 m_firstResize = true;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
47 ui = new Ui_ColorSelUI;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
48 ui->setupUi (this);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
49
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
50 m_scene = new QGraphicsScene;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
51 ui->viewport->setScene (m_scene);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
52 setSelection (::getColor (defval));
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
53
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 // not really an icon but eh
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
55 m_scene->setBackgroundBrush (getIcon ("checkerboard"));
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
56
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
57 drawScene();
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
58
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
59 int width = viewportWidth();
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
60 ui->viewport->setMinimumWidth (width);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
61 ui->viewport->setMaximumWidth (width);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
62
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
63 drawColorInfo();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
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 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
69 ColorSelector::~ColorSelector() {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
70 delete ui;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
71 }
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
75 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
76 void ColorSelector::drawScene() {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
77 const int numCols = g_numColumns;
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);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
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);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
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;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
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();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
89
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
90 for (short i = 0; i < MAX_COLORS; ++i) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
91 LDColor* info = ::getColor (i);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
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;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
99
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;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
102 if (i == maincolor) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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));
397
a1d3d558d3fa Apply the proper edge color in the color sector too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 396
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);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
114 if (sel() && i == sel()->index) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
115 auto curspic = m_scene->addPixmap (getIcon ("colorcursor"));
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 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
124 int ColorSelector::numRows() const {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
125 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
126 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
127
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
128 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
130 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
131 int ColorSelector::viewportWidth() const {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
132 return g_numColumns * g_squareSize + 21;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
133 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
134
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
135 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
137 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
138 void ColorSelector::drawColorInfo() {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
139 if (!sel()) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
140 ui->colorLabel->setText ("---");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 return;
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
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
144 ui->colorLabel->setText (fmt ("%1 - %2", sel()->index, sel()->name));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
150 void ColorSelector::resizeEvent (QResizeEvent* ev) {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
151 // If this is the first resize, check if we need to scroll down to see the
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
152 // 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
153 // height is not set properly there.
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
154 if (m_firstResize) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
155 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns;
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
156
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
157 if (sel() && sel()->index >= visibleColors) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
158 int y = (sel()->index / g_numColumns) * g_squareSize;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
159 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
160 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
161
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
162 m_firstResize = false;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
163 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
165 drawScene();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
171 void ColorSelector::mousePressEvent (QMouseEvent* event) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
172 QPointF scenepos = ui->viewport->mapToScene (event->pos());
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
173
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
174 ulong x = ( (ulong) scenepos.x() - (g_squareSize / 2)) / g_squareSize;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
175 ulong y = ( (ulong) scenepos.y() - (g_squareSize / 2)) / g_squareSize;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
176 ulong idx = (y * g_numColumns) + x;
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
177
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
178 LDColor* col = ::getColor (idx);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
179
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
180 if (!col)
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
181 return;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
183 setSelection (col);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
184 drawScene();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
185 drawColorInfo();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
186 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
187
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
188 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
190 // =============================================================================
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
191 bool ColorSelector::getColor (short& val, short int defval, QWidget* parent) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
192 ColorSelector dlg (defval, parent);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
193
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
194 if (dlg.exec() && dlg.sel() != null) {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
195 val = dlg.sel()->index;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 return false;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
200 }

mercurial