37 |
37 |
38 extern_cfg (String, gl_maincolor); |
38 extern_cfg (String, gl_maincolor); |
39 extern_cfg (Float, gl_maincolor_alpha); |
39 extern_cfg (Float, gl_maincolor_alpha); |
40 |
40 |
41 // ============================================================================= |
41 // ============================================================================= |
42 // ----------------------------------------------------------------------------- |
42 // ============================================================================= |
43 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
43 ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) |
44 { |
44 { |
45 // Remove the default color if it's invalid |
45 // Remove the default color if it's invalid |
46 if (!getColor (defval)) |
46 if (!getColor (defval)) |
47 defval = -1; |
47 defval = -1; |
64 |
64 |
65 drawColorInfo(); |
65 drawColorInfo(); |
66 } |
66 } |
67 |
67 |
68 // ============================================================================= |
68 // ============================================================================= |
69 // ----------------------------------------------------------------------------- |
69 // ============================================================================= |
70 ColorSelector::~ColorSelector() |
70 ColorSelector::~ColorSelector() |
71 { |
71 { |
72 delete ui; |
72 delete ui; |
73 } |
73 } |
74 |
74 |
75 // ============================================================================= |
75 // ============================================================================= |
76 // ----------------------------------------------------------------------------- |
76 // ============================================================================= |
77 void ColorSelector::drawScene() |
77 void ColorSelector::drawScene() |
78 { |
78 { |
79 const int numCols = g_numColumns; |
79 const int numCols = g_numColumns; |
80 const int square = g_squareSize; |
80 const int square = g_squareSize; |
81 const int g_maxHeight = (numRows() * square); |
81 const int g_maxHeight = (numRows() * square); |
122 } |
122 } |
123 } |
123 } |
124 } |
124 } |
125 |
125 |
126 // ============================================================================= |
126 // ============================================================================= |
127 // ----------------------------------------------------------------------------- |
127 // ============================================================================= |
128 int ColorSelector::numRows() const |
128 int ColorSelector::numRows() const |
129 { |
129 { |
130 return (MAX_COLORS / g_numColumns); |
130 return (MAX_COLORS / g_numColumns); |
131 } |
131 } |
132 |
132 |
133 // ============================================================================= |
133 // ============================================================================= |
134 // ----------------------------------------------------------------------------- |
134 // ============================================================================= |
135 int ColorSelector::viewportWidth() const |
135 int ColorSelector::viewportWidth() const |
136 { |
136 { |
137 return g_numColumns * g_squareSize + 21; |
137 return g_numColumns * g_squareSize + 21; |
138 } |
138 } |
139 |
139 |
140 // ============================================================================= |
140 // ============================================================================= |
141 // ----------------------------------------------------------------------------- |
141 // ============================================================================= |
142 void ColorSelector::drawColorInfo() |
142 void ColorSelector::drawColorInfo() |
143 { |
143 { |
144 if (!getSelection()) |
144 if (!getSelection()) |
145 { |
145 { |
146 ui->colorLabel->setText ("---"); |
146 ui->colorLabel->setText ("---"); |
149 |
149 |
150 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
150 ui->colorLabel->setText (fmt ("%1 - %2", getSelection()->index, getSelection()->name)); |
151 } |
151 } |
152 |
152 |
153 // ============================================================================= |
153 // ============================================================================= |
154 // ----------------------------------------------------------------------------- |
154 // ============================================================================= |
155 void ColorSelector::resizeEvent (QResizeEvent* ev) |
155 void ColorSelector::resizeEvent (QResizeEvent* ev) |
156 { |
156 { |
157 // If this is the first resize, check if we need to scroll down to see the |
157 // If this is the first resize, check if we need to scroll down to see the |
158 // currently selected color. We cannot do this in the constructor because the |
158 // currently selected color. We cannot do this in the constructor because the |
159 // height is not set properly there. |
159 // height is not set properly there. |
173 (void) ev; |
173 (void) ev; |
174 drawScene(); |
174 drawScene(); |
175 } |
175 } |
176 |
176 |
177 // ============================================================================= |
177 // ============================================================================= |
178 // ----------------------------------------------------------------------------- |
178 // ============================================================================= |
179 void ColorSelector::mousePressEvent (QMouseEvent* event) |
179 void ColorSelector::mousePressEvent (QMouseEvent* event) |
180 { |
180 { |
181 QPointF scenepos = ui->viewport->mapToScene (event->pos()); |
181 QPointF scenepos = ui->viewport->mapToScene (event->pos()); |
182 |
182 |
183 int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize; |
183 int x = (scenepos.x() - (g_squareSize / 2)) / g_squareSize; |
193 drawScene(); |
193 drawScene(); |
194 drawColorInfo(); |
194 drawColorInfo(); |
195 } |
195 } |
196 |
196 |
197 // ============================================================================= |
197 // ============================================================================= |
198 // ----------------------------------------------------------------------------- |
198 // ============================================================================= |
199 bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) |
199 bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) |
200 { |
200 { |
201 ColorSelector dlg (defval, parent); |
201 ColorSelector dlg (defval, parent); |
202 |
202 |
203 if (dlg.exec() && dlg.getSelection() != null) |
203 if (dlg.exec() && dlg.getSelection() != null) |