src/colorSelectDialog.cpp

Thu, 04 Jul 2013 16:19:50 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 04 Jul 2013 16:19:50 +0300
changeset 327
9ea604af1319
parent 286
7a562bf3d829
child 354
b32d4d66cb6e
permissions
-rw-r--r--

Largely reworked the color selector. Still not perfect but is better

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
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
35 extern_cfg( str, gl_maincolor );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
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 // =============================================================================
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
41 ColorSelector::ColorSelector( short defval, QWidget* parent ) : QDialog( parent )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
42 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // Remove the default color if it's invalid
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
44 if( !::getColor( defval ))
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 defval = -1;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
47 m_firstResize = true;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
48 ui = new Ui_ColorSelUI;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
49 ui->setupUi( this );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
50
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
51 m_scene = new QGraphicsScene;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
52 ui->viewport->setScene( m_scene );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
53 setSelection( ::getColor( defval ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 // not really an icon but eh
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
56 m_scene->setBackgroundBrush( getIcon( "checkerboard" ));
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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 drawScene();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
61 ui->viewport->setMinimumWidth( width );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
62 ui->viewport->setMaximumWidth( width );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // =============================================================================
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
70 ColorSelector::~ColorSelector()
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 delete ui;
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 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
77 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
78 void ColorSelector::drawScene()
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
79 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
80 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
81 const int square = g_squareSize;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
82 const int g_maxHeight = ( numRows() * square );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
83 QRect sceneRect( 0, 0, viewportWidth(), g_maxHeight );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
84
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
85 m_scene->setSceneRect( sceneRect );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
86 ui->viewport->setSceneRect( sceneRect );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
87
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
88 const double penWidth = 1.0f;
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
89 QPen pen( Qt::black, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 // 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
92 m_scene->clear();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
93
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
94 for( short i = 0; i < MAX_COLORS; ++i )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
95 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
96 color* info = ::getColor( i );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
97
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
98 if( !info )
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 continue;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
101 const double x = ( i % numCols ) * square;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
102 const double y = ( i / numCols ) * square;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
103 const double w = square - ( penWidth / 2 );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
104
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
105 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
106
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
107 if( i == maincolor )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
108 {
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 // Use the user preferences for main color here
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
110 col = QColor( gl_maincolor );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
111 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
112 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
114 m_scene->addRect( x, y, w, w, pen, col );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
115 QGraphicsTextItem* numtext = m_scene->addText( fmt( "%1", i ));
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
116 numtext->setDefaultTextColor(( luma( col ) < 80 ) ? Qt::white : Qt::black );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
117 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
118
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
119 if( i == sel()->index )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
120 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
121 auto curspic = m_scene->addPixmap( getIcon( "colorcursor" ));
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
122 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
123 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 // =============================================================================
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
130 int ColorSelector::numRows() const
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 return ( MAX_COLORS / g_numColumns );
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 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
138 int ColorSelector::viewportWidth() const
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
139 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
140 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
141 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
142
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
143 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
145 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
146 void ColorSelector::drawColorInfo()
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
147 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
148 if( !sel() )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
149 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
150 ui->colorLabel->setText( "---" );
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 return;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
154 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
155 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 // =============================================================================
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
160 void ColorSelector::resizeEvent( QResizeEvent* ev )
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 // 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
163 // 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
164 // height is not set properly there.
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
165 if( m_firstResize )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
166 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
167 int visibleColors = ( ui->viewport->height() / g_squareSize ) * g_numColumns;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
168
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
169 if( sel() && sel()->index >= visibleColors )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
170 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
171 int y = ( sel()->index / g_numColumns ) * g_squareSize;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
172 ui->viewport->verticalScrollBar()->setValue( y );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
173 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
174
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
175 m_firstResize = false;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
176 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
178 drawScene();
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 // =============================================================================
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 // =============================================================================
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
184 void ColorSelector::mousePressEvent( QMouseEvent* event )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
185 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
186 QPointF scenepos = ui->viewport->mapToScene( event->pos() );
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 ulong x = (( ulong ) scenepos.x() - ( g_squareSize / 2 )) / g_squareSize;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
189 ulong y = (( ulong ) scenepos.y() - ( g_squareSize / 2 )) / g_squareSize;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
190 ulong idx = ( y * g_numColumns ) + x;
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
191
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
192 color* col = ::getColor( idx );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
193
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
194 if( !col )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
195 return;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
197 setSelection( col );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
198 drawScene();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
199 drawColorInfo();
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
200 }
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
201
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
202 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
204 // =============================================================================
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
205 bool ColorSelector::getColor( short& val, short int defval, QWidget* parent )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
206 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
207 ColorSelector dlg( defval, parent );
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
208
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
209 if( dlg.exec() && dlg.sel() != null )
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
210 {
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
211 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
212 return true;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 return false;
327
9ea604af1319 Largely reworked the color selector. Still not perfect but is better
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
216 }

mercurial