zz_colorSelectDialog.cpp

Mon, 25 Mar 2013 17:04:18 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 25 Mar 2013 17:04:18 +0200
changeset 70
e6b8dab8f81a
parent 68
c637b172d565
child 71
c9f02d2dd9eb
permissions
-rw-r--r--

Phased out FOREACH macro in favor of C++11-style for iteration.

48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "common.h"
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "gui.h"
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <qgraphicsscene.h>
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <qgraphicsview.h>
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <qicon.h>
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <qboxlayout.h>
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <qgraphicsitem.h>
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
26 #include <qevent.h>
58
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
27 #include <qscrollbar.h>
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "zz_colorSelectDialog.h"
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "colors.h"
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 static const short g_dNumColumns = 8;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 static const short g_dNumRows = 10;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 static const short g_dSquareSize = 32;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 static const long g_lWidth = (g_dNumColumns * g_dSquareSize);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 static const long g_lHeight = (g_dNumRows * g_dSquareSize);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 static const long g_lMaxHeight = ((MAX_COLORS / g_dNumColumns) * g_dSquareSize);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 // =============================================================================
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // =============================================================================
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
41 ColorSelectDialog::ColorSelectDialog (short dDefault, QWidget* parent) : QDialog (parent) {
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
42 // Remove the default color if it's invalid
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
43 if (!getColor (dDefault))
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
44 dDefault = -1;
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
45
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 qScene = new QGraphicsScene;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 qView = new QGraphicsView (qScene);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
48 dSelColor = dDefault;
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // not really an icon but eh
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 qScene->setBackgroundBrush (QPixmap ("icons/checkerboard.png"));
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 qScene->setSceneRect (0, 0, g_lWidth, g_lMaxHeight);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 qView->setSceneRect (0, 0, g_lWidth, g_lMaxHeight);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
56 drawScene ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
57
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
58 IMPLEMENT_DIALOG_BUTTONS
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
59
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
60 // Set the size of the view
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
61 const long lWidth = g_lWidth + 21; // HACK
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
62 qView->setMaximumWidth (lWidth);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
63 qView->setMinimumWidth (lWidth);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
64 qView->setMaximumHeight (g_lHeight);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
65 qView->setMinimumHeight (g_lHeight);
58
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
66 qView->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
67
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
68 // If we have a default color selected, scroll down so that it is visible.
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
69 if (dDefault >= ((g_dNumColumns * g_dNumRows) - 2)) {
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
70 ulong ulNewY = ((dDefault / g_dNumColumns) - 3) * g_dSquareSize;
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
71 qView->verticalScrollBar ()->setSliderPosition (ulNewY);
4db04d4857c0 Scroll the color picker dialog to the selected color if it's off-screen
Santeri Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
72 }
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
73
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
74 qColorInfo = new QLabel;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
75 drawColorInfo ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
76
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
77 QHBoxLayout* qLayout = new QHBoxLayout;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
78 qLayout->addWidget (qColorInfo);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
79 qLayout->addWidget (qButtons);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
80
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
81 QVBoxLayout* qLayout2 = new QVBoxLayout;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
82 qLayout2->addWidget (qView);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
83 qLayout2->addLayout (qLayout);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
84 setLayout (qLayout2);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
85
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
86 setWindowIcon (QIcon ("icons/palette.png"));
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
87 setWindowTitle (APPNAME_DISPLAY " - choose a color");
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
88 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
89
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
90 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
92 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
93 void ColorSelectDialog::drawScene () {
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 const double fPenWidth = 1.0f;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 QPen qPen (Qt::black, fPenWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 // Draw the color rectangles.
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
98 qScene->clear ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
99 for (short i = 0; i < MAX_COLORS; ++i) {
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
100 color* meta = getColor (i);
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 if (!meta)
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 continue;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 const double x = (i % g_dNumColumns) * g_dSquareSize;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 const double y = (i / g_dNumColumns) * g_dSquareSize;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 const double w = (g_dSquareSize) - (fPenWidth / 2);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 QColor qColor (meta->zColor.chars ());
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 qColor.setAlpha (meta->fAlpha * 255.0);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 uchar ucLuma = (0.2126f * qColor.red()) +
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 (0.7152f * qColor.green()) + (0.0722 * qColor.blue());
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 bool bDark = (ucLuma < 80);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 qScene->addRect (x, y, w, w, qPen, qColor);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 QGraphicsTextItem* qText = qScene->addText (str::mkfmt ("%lu", i).chars());
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 qText->setDefaultTextColor ((bDark) ? Qt::white : Qt::black);
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 qText->setPos (x, y);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
119
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
120 if (i == dSelColor) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
121 QGraphicsPixmapItem* qCursorPic;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
122 qCursorPic = qScene->addPixmap (QPixmap ("icons/colorcursor.png"));
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
123 qCursorPic->setPos (x, y);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
124 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
125 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
126 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
127
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
128 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
130 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
131 void ColorSelectDialog::drawColorInfo () {
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
132 color* col = getColor (dSelColor);
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
133
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
134 if (dSelColor == -1 || !col) {
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
135 qColorInfo->setText ("---");
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
136 return;
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 }
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
139 qColorInfo->setText (str::mkfmt ("%d - %s",
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
140 dSelColor, col->zName.chars()));
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 }
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 // =============================================================================
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 // =============================================================================
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
146 void ColorSelectDialog::mousePressEvent (QMouseEvent* event) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
147 QPointF qPoint = qView->mapToScene (event->pos ());
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
148
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
149 ulong x = ((ulong)qPoint.x () - (g_dSquareSize / 2)) / g_dSquareSize;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
150 ulong y = ((ulong)qPoint.y () - (g_dSquareSize / 2)) / g_dSquareSize;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
151 ulong idx = (y * g_dNumColumns) + x;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
152
68
c637b172d565 Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
153 color* col = getColor (idx);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
154 if (!col)
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
155 return;
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
157 dSelColor = idx;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
158 drawScene ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
159 drawColorInfo ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
160 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
161
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
162 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
164 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
165 bool ColorSelectDialog::staticDialog (short& dValue, short dDefault, QWidget* parent) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
166 ColorSelectDialog dlg (dDefault, parent);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
167
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
168 if (dlg.exec () && dlg.dSelColor != -1) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
169 dValue = dlg.dSelColor;
48
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 return true;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 }
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 return false;
113eb6446c61 Color dialog almost up and running. Need to make it actually selectable now. TODO: make it read LDConfig.ldr
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 }

mercurial