src/colorSelectDialog.cpp

Tue, 20 Aug 2013 14:47:21 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 20 Aug 2013 14:47:21 +0300
changeset 461
fbcc91ae1dd2
parent 455
c5d14d112034
child 471
fc58b67d445c
permissions
-rw-r--r--

- added "Go to line" action, renamed the config classes to proper camelcase

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"
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
31 #include "build/moc_colorSelectDialog.cpp"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
33 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
34 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
35
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
36 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
37 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
38
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // =============================================================================
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
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;
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
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);
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
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));
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
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"));
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
56 drawScene();
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
57
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
58 int width = viewportWidth();
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
59 ui->viewport->setMinimumWidth (width);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
60 ui->viewport->setMaximumWidth (width);
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
61
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
62 drawColorInfo();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
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 // =============================================================================
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
66 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
67 ColorSelector::~ColorSelector() {
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
68 delete ui;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
69 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
70
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
71 // =============================================================================
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
72 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
73 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
74 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
75 const int square = g_squareSize;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
76 const int g_maxHeight = (numRows() * square);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
77 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
78
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
79 m_scene->setSceneRect (sceneRect);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
80 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
81
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
82 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
83
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 // 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
85 m_scene->clear();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
86
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
87 for (short i = 0; i < MAX_COLORS; ++i) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
88 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
89
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
90 if (!info)
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 continue;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
93 const double x = (i % numCols) * square;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
94 const double y = (i / numCols) * square;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
95 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
96
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
97 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
98
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
99 if (i == maincolor) {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // Use the user preferences for main color here
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
101 col = QColor (gl_maincolor);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
102 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
103 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104
397
a1d3d558d3fa Apply the proper edge color in the color sector too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 396
diff changeset
105 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
106 m_scene->addRect (x, y, w, w, pen, col);
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
107 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
108 numtext->setDefaultTextColor ((luma (col) < 80) ? Qt::white : Qt::black);
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
109 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
110
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
111 if (sel() && i == sel()->index) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
112 auto curspic = m_scene->addPixmap (getIcon ("colorcursor"));
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
113 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
114 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
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 // =============================================================================
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
119 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
120 int ColorSelector::numRows() const {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
121 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
122 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
123
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
124 // =============================================================================
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
125 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
126 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
127 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
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 // =============================================================================
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
131 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
132 void ColorSelector::drawColorInfo() {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
133 if (!sel()) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
134 ui->colorLabel->setText ("---");
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
138 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
139 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 // =============================================================================
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
142 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
143 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
144 // 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
145 // 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
146 // height is not set properly there.
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
147 if (m_firstResize) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
148 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
149
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
150 if (sel() && sel()->index >= visibleColors) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
151 int y = (sel()->index / g_numColumns) * g_squareSize;
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
152 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
153 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
154
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
155 m_firstResize = false;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
156 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
158 (void) ev;
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
159 drawScene();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 // =============================================================================
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
163 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
164 void ColorSelector::mousePressEvent (QMouseEvent* event) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
165 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
166
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
167 ulong x = ((ulong) scenepos.x() - (g_squareSize / 2)) / g_squareSize;
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 410
diff changeset
168 ulong y = ((ulong) scenepos.y() - (g_squareSize / 2)) / g_squareSize;
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
169 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
170
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
171 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
172
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
173 if (!col)
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
174 return;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
176 setSelection (col);
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
177 drawScene();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
178 drawColorInfo();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
179 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
180
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
181 // =============================================================================
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
182 // -----------------------------------------------------------------------------
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
183 bool ColorSelector::getColor (short& val, short int defval, QWidget* parent) {
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
184 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
185
396
582bea871af9 restyle colorselectdialog.cpp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 364
diff changeset
186 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
187 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
188 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 return false;
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
192 }

mercurial