src/colorSelectDialog.cc

Wed, 01 Jan 2014 00:25:01 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 01 Jan 2014 00:25:01 +0200
changeset 600
209e3f1f7b2c
parent 557
04e140bdeb0b
child 603
47e7773c7841
permissions
-rw-r--r--

- updated copyright year. Best wishes for 2014!

557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
600
209e3f1f7b2c - updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents: 557
diff changeset
3 * Copyright (C) 2013, 2014 Santeri Piippo
557
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 * =====================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 *
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 * colorSelectDialog.cpp: Color selector box.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 */
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QGraphicsScene>
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QGraphicsItem>
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QMouseEvent>
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <QScrollBar>
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "main.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "gui.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "colorSelectDialog.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "colors.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "config.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "misc.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "ui_colorsel.h"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "moc_colorSelectDialog.cpp"
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 static const int g_numColumns = 16;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 static const int g_squareSize = 32;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 extern_cfg (String, gl_maincolor);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 extern_cfg (Float, gl_maincolor_alpha);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 { // Remove the default color if it's invalid
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 if (!getColor (defval))
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 defval = -1;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 m_firstResize = true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 ui = new Ui_ColorSelUI;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 ui->setupUi (this);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 m_scene = new QGraphicsScene;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 ui->viewport->setScene (m_scene);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 setSelection (getColor (defval));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 // not really an icon but eh
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 m_scene->setBackgroundBrush (getIcon ("checkerboard"));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 drawScene();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 int width = viewportWidth();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 ui->viewport->setMinimumWidth (width);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 ui->viewport->setMaximumWidth (width);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 drawColorInfo();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 ColorSelector::~ColorSelector()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 { delete ui;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 void ColorSelector::drawScene()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 { const int numCols = g_numColumns;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 const int square = g_squareSize;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 const int g_maxHeight = (numRows() * square);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 QRect sceneRect (0, 0, viewportWidth(), g_maxHeight);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 m_scene->setSceneRect (sceneRect);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 ui->viewport->setSceneRect (sceneRect);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 const double penWidth = 1.0f;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 // Draw the color rectangles.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 m_scene->clear();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 for (int i = 0; i < MAX_COLORS; ++i)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 { LDColor* info = ::getColor (i);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 if (!info)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 continue;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 const double x = (i % numCols) * square;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 const double y = (i / numCols) * square;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 const double w = square - (penWidth / 2);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 QColor col = info->faceColor;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 if (i == maincolor)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 { // Use the user preferences for main color here
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 col = QColor (gl_maincolor);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 col.setAlpha (gl_maincolor_alpha * 255.0f);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 m_scene->addRect (x, y, w, w, pen, col);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 QGraphicsTextItem* numtext = m_scene->addText (fmt ("%1", i));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 numtext->setPos (x, y);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 if (getSelection() && i == getSelection()->index)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 { auto curspic = m_scene->addPixmap (getIcon ("colorcursor"));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 curspic->setPos (x, y);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 int ColorSelector::numRows() const
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 { return (MAX_COLORS / g_numColumns);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 int ColorSelector::viewportWidth() const
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 { return g_numColumns * g_squareSize + 21;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 void ColorSelector::drawColorInfo()
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 { if (!getSelection())
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 { ui->colorLabel->setText ("---");
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name));
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 void ColorSelector::resizeEvent (QResizeEvent* ev)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 { // If this is the first resize, check if we need to scroll down to see the
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 // currently selected color. We cannot do this in the constructor because the
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 // height is not set properly there.
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 if (m_firstResize)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 { int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 if (getSelection() && getSelection()->index >= visibleColors)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 { int y = (getSelection()->index / g_numColumns) * g_squareSize;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 ui->viewport->verticalScrollBar()->setValue (y);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 m_firstResize = false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 (void) ev;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 drawScene();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 void ColorSelector::mousePressEvent (QMouseEvent* event)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 { QPointF scenepos = ui->viewport->mapToScene (event->pos());
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 int y = (scenepos.y() - (g_squareSize / 2)) / g_squareSize;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 int idx = (y * g_numColumns) + x;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 LDColor* col = ::getColor (idx);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 if (!col)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 return;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 setSelection (col);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 drawScene();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 drawColorInfo();
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 // =============================================================================
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 // -----------------------------------------------------------------------------
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 bool ColorSelector::selectColor (int& val, int defval, QWidget* parent)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 { ColorSelector dlg (defval, parent);
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 if (dlg.exec() && dlg.getSelection() != null)
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 { val = dlg.getSelection()->index;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 return true;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 }
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 return false;
04e140bdeb0b - changed source file extension from .cpp to .cc
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 }

mercurial