40 extern_cfg (Float, gl_maincolor_alpha); |
40 extern_cfg (Float, gl_maincolor_alpha); |
41 |
41 |
42 // ============================================================================= |
42 // ============================================================================= |
43 // ----------------------------------------------------------------------------- |
43 // ----------------------------------------------------------------------------- |
44 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
44 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
45 { // Remove the default color if it's invalid |
45 { |
|
46 // Remove the default color if it's invalid |
46 if (!getColor (defval)) |
47 if (!getColor (defval)) |
47 defval = -1; |
48 defval = -1; |
48 |
49 |
49 m_firstResize = true; |
50 m_firstResize = true; |
50 ui = new Ui_ColorSelUI; |
51 ui = new Ui_ColorSelUI; |
66 } |
67 } |
67 |
68 |
68 // ============================================================================= |
69 // ============================================================================= |
69 // ----------------------------------------------------------------------------- |
70 // ----------------------------------------------------------------------------- |
70 ColorSelector::~ColorSelector() |
71 ColorSelector::~ColorSelector() |
71 { delete ui; |
72 { |
|
73 delete ui; |
72 } |
74 } |
73 |
75 |
74 // ============================================================================= |
76 // ============================================================================= |
75 // ----------------------------------------------------------------------------- |
77 // ----------------------------------------------------------------------------- |
76 void ColorSelector::drawScene() |
78 void ColorSelector::drawScene() |
77 { const int numCols = g_numColumns; |
79 { |
|
80 const int numCols = g_numColumns; |
78 const int square = g_squareSize; |
81 const int square = g_squareSize; |
79 const int g_maxHeight = (numRows() * square); |
82 const int g_maxHeight = (numRows() * square); |
80 QRect sceneRect (0, 0, viewportWidth(), g_maxHeight); |
83 QRect sceneRect (0, 0, viewportWidth(), g_maxHeight); |
81 |
84 |
82 m_scene->setSceneRect (sceneRect); |
85 m_scene->setSceneRect (sceneRect); |
98 const double w = square - (penWidth / 2); |
102 const double w = square - (penWidth / 2); |
99 |
103 |
100 QColor col = info->faceColor; |
104 QColor col = info->faceColor; |
101 |
105 |
102 if (i == maincolor) |
106 if (i == maincolor) |
103 { // Use the user preferences for main color here |
107 { |
|
108 // Use the user preferences for main color here |
104 col = QColor (gl_maincolor); |
109 col = QColor (gl_maincolor); |
105 col.setAlpha (gl_maincolor_alpha * 255.0f); |
110 col.setAlpha (gl_maincolor_alpha * 255.0f); |
106 } |
111 } |
107 |
112 |
108 QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
113 QPen pen (info->edgeColor, penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
110 QGraphicsTextItem* numtext = m_scene->addText (fmt ("%1", i)); |
115 QGraphicsTextItem* numtext = m_scene->addText (fmt ("%1", i)); |
111 numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black); |
116 numtext->setDefaultTextColor ( (luma (col) < 80) ? Qt::white : Qt::black); |
112 numtext->setPos (x, y); |
117 numtext->setPos (x, y); |
113 |
118 |
114 if (getSelection() && i == getSelection()->index) |
119 if (getSelection() && i == getSelection()->index) |
115 { auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); |
120 { |
|
121 auto curspic = m_scene->addPixmap (getIcon ("colorcursor")); |
116 curspic->setPos (x, y); |
122 curspic->setPos (x, y); |
117 } |
123 } |
118 } |
124 } |
119 } |
125 } |
120 |
126 |
121 // ============================================================================= |
127 // ============================================================================= |
122 // ----------------------------------------------------------------------------- |
128 // ----------------------------------------------------------------------------- |
123 int ColorSelector::numRows() const |
129 int ColorSelector::numRows() const |
124 { return (MAX_COLORS / g_numColumns); |
130 { |
|
131 return (MAX_COLORS / g_numColumns); |
125 } |
132 } |
126 |
133 |
127 // ============================================================================= |
134 // ============================================================================= |
128 // ----------------------------------------------------------------------------- |
135 // ----------------------------------------------------------------------------- |
129 int ColorSelector::viewportWidth() const |
136 int ColorSelector::viewportWidth() const |
130 { return g_numColumns * g_squareSize + 21; |
137 { |
|
138 return g_numColumns * g_squareSize + 21; |
131 } |
139 } |
132 |
140 |
133 // ============================================================================= |
141 // ============================================================================= |
134 // ----------------------------------------------------------------------------- |
142 // ----------------------------------------------------------------------------- |
135 void ColorSelector::drawColorInfo() |
143 void ColorSelector::drawColorInfo() |
136 { if (!getSelection()) |
144 { |
137 { ui->colorLabel->setText ("---"); |
145 if (!getSelection()) |
|
146 { |
|
147 ui->colorLabel->setText ("---"); |
138 return; |
148 return; |
139 } |
149 } |
140 |
150 |
141 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
151 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
142 } |
152 } |
143 |
153 |
144 // ============================================================================= |
154 // ============================================================================= |
145 // ----------------------------------------------------------------------------- |
155 // ----------------------------------------------------------------------------- |
146 void ColorSelector::resizeEvent (QResizeEvent* ev) |
156 void ColorSelector::resizeEvent (QResizeEvent* ev) |
147 { // If this is the first resize, check if we need to scroll down to see the |
157 { |
|
158 // If this is the first resize, check if we need to scroll down to see the |
148 // currently selected color. We cannot do this in the constructor because the |
159 // currently selected color. We cannot do this in the constructor because the |
149 // height is not set properly there. |
160 // height is not set properly there. |
150 if (m_firstResize) |
161 if (m_firstResize) |
151 { int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; |
162 { |
|
163 int visibleColors = (ui->viewport->height() / g_squareSize) * g_numColumns; |
152 |
164 |
153 if (getSelection() && getSelection()->index >= visibleColors) |
165 if (getSelection() && getSelection()->index >= visibleColors) |
154 { int y = (getSelection()->index / g_numColumns) * g_squareSize; |
166 { |
|
167 int y = (getSelection()->index / g_numColumns) * g_squareSize; |
155 ui->viewport->verticalScrollBar()->setValue (y); |
168 ui->viewport->verticalScrollBar()->setValue (y); |
156 } |
169 } |
157 |
170 |
158 m_firstResize = false; |
171 m_firstResize = false; |
159 } |
172 } |
163 } |
176 } |
164 |
177 |
165 // ============================================================================= |
178 // ============================================================================= |
166 // ----------------------------------------------------------------------------- |
179 // ----------------------------------------------------------------------------- |
167 void ColorSelector::mousePressEvent (QMouseEvent* event) |
180 void ColorSelector::mousePressEvent (QMouseEvent* event) |
168 { QPointF scenepos = ui->viewport->mapToScene (event->pos()); |
181 { |
|
182 QPointF scenepos = ui->viewport->mapToScene (event->pos()); |
169 |
183 |
170 int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize; |
184 int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize; |
171 int y = (scenepos.y() - (g_squareSize / 2)) / g_squareSize; |
185 int y = (scenepos.y() - (g_squareSize / 2)) / g_squareSize; |
172 int idx = (y * g_numColumns) + x; |
186 int idx = (y * g_numColumns) + x; |
173 |
187 |
182 } |
196 } |
183 |
197 |
184 // ============================================================================= |
198 // ============================================================================= |
185 // ----------------------------------------------------------------------------- |
199 // ----------------------------------------------------------------------------- |
186 bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) |
200 bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) |
187 { ColorSelector dlg (defval, parent); |
201 { |
|
202 ColorSelector dlg (defval, parent); |
188 |
203 |
189 if (dlg.exec() && dlg.getSelection() != null) |
204 if (dlg.exec() && dlg.getSelection() != null) |
190 { val = dlg.getSelection()->index; |
205 { |
|
206 val = dlg.getSelection()->index; |
191 return true; |
207 return true; |
192 } |
208 } |
193 |
209 |
194 return false; |
210 return false; |
195 } |
211 } |