zz_colorSelectDialog.cpp

Wed, 10 Apr 2013 14:10:58 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 10 Apr 2013 14:10:58 +0300
changeset 94
a9e67f6e610e
parent 72
5755c02d89f0
child 104
6e29bb0e83c5
permissions
-rw-r--r--

Added history management for cut and paste, copy doesn't alter the object list by itself so it doesn't touch history

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"
71
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
30 #include "config.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
31
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_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
33 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
34 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
35 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
36 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
37 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
38
71
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
39 extern_cfg (str, gl_maincolor);
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
40 extern_cfg (float, gl_maincolor_alpha);
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
41
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
42 // =============================================================================
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
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
44 // =============================================================================
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
45 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
46 // 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
47 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
48 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
49
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
50 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
51 qView = new QGraphicsView (qScene);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
52 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
53
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 // 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
55 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
56
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
57 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
58 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
59
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
60 drawScene ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
61
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
62 IMPLEMENT_DIALOG_BUTTONS
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
63
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
64 // Set the size of the view
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
65 const long lWidth = g_lWidth + 21; // HACK
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
66 qView->setMaximumWidth (lWidth);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
67 qView->setMinimumWidth (lWidth);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
68 qView->setMaximumHeight (g_lHeight);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
69 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
70 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
71
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 // 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
73 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
74 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
75 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
76 }
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
77
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
78 qColorInfo = new QLabel;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
79 drawColorInfo ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
80
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
81 QVBoxLayout* qLayout = new QVBoxLayout;
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
82 qLayout->addWidget (qView);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
83 qLayout->addWidget (qColorInfo);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
84 qLayout->addWidget (qButtons);
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
85 setLayout (qLayout);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
86
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
87 setWindowIcon (QIcon ("icons/palette.png"));
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
88 setWindowTitle (APPNAME_DISPLAY " - choose a color");
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 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
94 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
95 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
96 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
97
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
98 // Draw the color rectangles.
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
99 qScene->clear ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
100 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
101 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
102 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
103 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
104
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 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
106 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
107 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
108
72
5755c02d89f0 Added LDConfig.ldr parsing. All colors now available as long as LDConfig.ldr is provided.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
109 QColor qColor = meta->qColor;
71
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
110
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
111 if (i == dMainColor) {
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
112 // Use the user preferences for main color here
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
113 qColor = gl_maincolor.value.chars ();
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
114 qColor.setAlpha (gl_maincolor_alpha * 255.0f);
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
115 }
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
116
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 uchar ucLuma = (0.2126f * qColor.red()) +
71
c9f02d2dd9eb Draw main color in the selection dialog based on preferences, take subfiles into account when calculating bbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 68
diff changeset
118 (0.7152f * qColor.green()) + (0.0722f * qColor.blue());
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
119 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
120
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
121 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
122 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
123 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
124 qText->setPos (x, y);
49
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 if (i == dSelColor) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
127 QGraphicsPixmapItem* qCursorPic;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
128 qCursorPic = qScene->addPixmap (QPixmap ("icons/colorcursor.png"));
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
129 qCursorPic->setPos (x, y);
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 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
132 }
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
133
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
134 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
136 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
137 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
138 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
139
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 if (dSelColor == -1 || !col) {
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
141 qColorInfo->setText ("---");
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
142 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
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
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
145 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
146 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
147 }
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
148
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
149 // =============================================================================
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
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
151 // =============================================================================
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
152 void ColorSelectDialog::mousePressEvent (QMouseEvent* event) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
153 QPointF qPoint = qView->mapToScene (event->pos ());
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
154
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
155 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
156 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
157 ulong idx = (y * g_dNumColumns) + x;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
158
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
159 color* col = getColor (idx);
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
160 if (!col)
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
161 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
162
49
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
163 dSelColor = idx;
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
164 drawScene ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
165 drawColorInfo ();
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
166 }
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 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
170 // =============================================================================
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
171 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
172 ColorSelectDialog dlg (dDefault, parent);
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
173
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
174 if (dlg.exec () && dlg.dSelColor != -1) {
242f6ea0f5e5 Finished with the color selection dialog
Santeri Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
175 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
176 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
177 }
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
178
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
179 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
180 }

mercurial