src/colorSelectDialog.cpp

Thu, 22 Aug 2013 20:39:26 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 22 Aug 2013 20:39:26 +0300
changeset 475
1f5ab7410e4d
parent 473
2a84149fe642
child 491
7d1b5ecd76c0
permissions
-rw-r--r--

Apparently CMake requires the moc files to be compiled separately.. qt4_wrap_cpp does nothing if I don't include the results in the executable... why?

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

mercurial