Mercurial > hg > svgui
comparison widgets/AudioDial.cpp @ 1443:089afbbe1253 single-point
Make AudioDial a bit more visible with a dark background
author | Chris Cannam |
---|---|
date | Wed, 24 Apr 2019 15:42:35 +0100 |
parents | c8a6fd3f9dff |
children | c268fe2ad597 |
comparison
equal
deleted
inserted
replaced
1442:5554d5187494 | 1443:089afbbe1253 |
---|---|
72 | 72 |
73 | 73 |
74 // Constructor. | 74 // Constructor. |
75 AudioDial::AudioDial(QWidget *parent) : | 75 AudioDial::AudioDial(QWidget *parent) : |
76 QDial(parent), | 76 QDial(parent), |
77 m_knobColor(Qt::black), | 77 m_knobColor(Qt::black), // shorthand for "background colour" in paint() |
78 m_meterColor(Qt::white), | 78 m_meterColor(Qt::white), // shorthand for "foreground colour" in paint() |
79 m_defaultValue(0), | 79 m_defaultValue(0), |
80 m_defaultMappedValue(0), | 80 m_defaultMappedValue(0), |
81 m_mappedValue(0), | 81 m_mappedValue(0), |
82 m_noMappedUpdate(false), | 82 m_noMappedUpdate(false), |
83 m_showTooltip(true), | 83 m_showTooltip(true), |
129 | 129 |
130 int ns = notchSize(); | 130 int ns = notchSize(); |
131 int numTicks = 1 + (maximum() + ns - minimum()) / ns; | 131 int numTicks = 1 + (maximum() + ns - minimum()) / ns; |
132 | 132 |
133 QColor knobColor(m_knobColor); | 133 QColor knobColor(m_knobColor); |
134 if (knobColor == Qt::black) | 134 if (knobColor == Qt::black) { |
135 knobColor = palette().window().color(); | 135 knobColor = palette().window().color().light(150); |
136 } | |
137 bool knobIsDark = | |
138 (knobColor.red() + knobColor.green() + knobColor.blue() <= 384); | |
136 | 139 |
137 QColor meterColor(m_meterColor); | 140 QColor meterColor(m_meterColor); |
138 if (!isEnabled()) | 141 if (!isEnabled()) { |
139 meterColor = palette().mid().color(); | 142 meterColor = palette().mid().color(); |
140 else if (m_meterColor == Qt::white) | 143 } else if (m_meterColor == Qt::white) { |
141 meterColor = palette().highlight().color(); | 144 if (knobIsDark) { |
142 | 145 meterColor = palette().light().color(); |
146 } else { | |
147 meterColor = palette().highlight().color(); | |
148 } | |
149 } | |
150 | |
151 QColor notchColor(palette().dark().color()); | |
152 if (knobIsDark) { | |
153 notchColor = palette().light().color(); | |
154 } | |
155 | |
143 int m_size = width() < height() ? width() : height(); | 156 int m_size = width() < height() ? width() : height(); |
144 int scale = 1; | 157 int scale = 1; |
145 int width = m_size - 2*scale; | 158 int width = m_size - 2*scale; |
146 | 159 |
147 paint.begin(this); | 160 paint.begin(this); |
167 | 180 |
168 pen.setWidth(3 * scale); | 181 pen.setWidth(3 * scale); |
169 int pos = indent-1 + (width-2*indent) / 20; | 182 int pos = indent-1 + (width-2*indent) / 20; |
170 int darkWidth = (width-2*indent) * 3 / 4; | 183 int darkWidth = (width-2*indent) * 3 / 4; |
171 while (darkWidth) { | 184 while (darkWidth) { |
172 c = c.light(102); | 185 if (knobIsDark) { |
186 c = c.dark(102); | |
187 } else { | |
188 c = c.light(102); | |
189 } | |
173 pen.setColor(c); | 190 pen.setColor(c); |
174 paint.setPen(pen); | 191 paint.setPen(pen); |
175 paint.drawEllipse(pos, pos, darkWidth, darkWidth); | 192 paint.drawEllipse(pos, pos, darkWidth, darkWidth); |
176 if (!--darkWidth) break; | 193 if (!--darkWidth) break; |
177 paint.drawEllipse(pos, pos, darkWidth, darkWidth); | 194 paint.drawEllipse(pos, pos, darkWidth, darkWidth); |
182 | 199 |
183 // Tick notches... | 200 // Tick notches... |
184 | 201 |
185 if ( notchesVisible() ) { | 202 if ( notchesVisible() ) { |
186 // cerr << "Notches visible" << endl; | 203 // cerr << "Notches visible" << endl; |
187 pen.setColor(palette().dark().color()); | 204 pen.setColor(notchColor); |
188 pen.setWidth(scale); | 205 pen.setWidth(scale); |
189 paint.setPen(pen); | 206 paint.setPen(pen); |
190 for (int i = 0; i < numTicks; ++i) { | 207 for (int i = 0; i < numTicks; ++i) { |
191 int div = numTicks; | 208 int div = numTicks; |
192 if (div > 1) --div; | 209 if (div > 1) --div; |
218 paint.setPen(pen); | 235 paint.setPen(pen); |
219 | 236 |
220 // Knob shadow... | 237 // Knob shadow... |
221 | 238 |
222 int shadowAngle = -720; | 239 int shadowAngle = -720; |
223 c = knobColor.dark(); | 240 if (knobIsDark) { |
241 c = knobColor.light(); | |
242 } else { | |
243 c = knobColor.dark(); | |
244 } | |
224 for (int arc = 120; arc < 2880; arc += 240) { | 245 for (int arc = 120; arc < 2880; arc += 240) { |
225 pen.setColor(c); | 246 pen.setColor(c); |
226 paint.setPen(pen); | 247 paint.setPen(pen); |
227 paint.drawArc(indent, indent, | 248 paint.drawArc(indent, indent, |
228 width-2*indent, width-2*indent, shadowAngle + arc, 240); | 249 width-2*indent, width-2*indent, shadowAngle + arc, 240); |
229 paint.drawArc(indent, indent, | 250 paint.drawArc(indent, indent, |
230 width-2*indent, width-2*indent, shadowAngle - arc, 240); | 251 width-2*indent, width-2*indent, shadowAngle - arc, 240); |
231 c = c.light(110); | 252 if (knobIsDark) { |
253 c = c.dark(110); | |
254 } else { | |
255 c = c.light(110); | |
256 } | |
232 } | 257 } |
233 | 258 |
234 // Scale shadow, omitting the bottom part... | 259 // Scale shadow, omitting the bottom part... |
235 | 260 |
236 shadowAngle = 2160; | 261 shadowAngle = 2160; |
253 c = c.light(110); | 278 c = c.light(110); |
254 } | 279 } |
255 | 280 |
256 // Scale ends... | 281 // Scale ends... |
257 | 282 |
258 pen.setColor(palette().shadow().color()); | 283 if (knobIsDark) { |
284 pen.setColor(palette().mid().color()); | |
285 } else { | |
286 pen.setColor(palette().shadow().color()); | |
287 } | |
259 pen.setWidth(scale); | 288 pen.setWidth(scale); |
260 paint.setPen(pen); | 289 paint.setPen(pen); |
261 for (int i = 0; i < numTicks; ++i) { | 290 for (int i = 0; i < numTicks; ++i) { |
262 if (i != 0 && i != numTicks - 1) continue; | 291 if (i != 0 && i != numTicks - 1) continue; |
263 int div = numTicks; | 292 int div = numTicks; |
276 double y0 = hyp; | 305 double y0 = hyp; |
277 | 306 |
278 double x = hyp - len * sin(angle); | 307 double x = hyp - len * sin(angle); |
279 double y = hyp + len * cos(angle); | 308 double y = hyp + len * cos(angle); |
280 | 309 |
281 c = palette().dark().color(); | 310 c = notchColor; |
282 pen.setColor(isEnabled() ? c.dark(130) : c); | 311 if (isEnabled()) { |
312 if (knobIsDark) { | |
313 c = c.light(130); | |
314 } else { | |
315 c = c.dark(130); | |
316 } | |
317 } | |
318 pen.setColor(c); | |
283 pen.setWidth(scale * 2); | 319 pen.setWidth(scale * 2); |
284 paint.setPen(pen); | 320 paint.setPen(pen); |
285 paint.drawLine(int(x0), int(y0), int(x), int(y)); | 321 paint.drawLine(int(x0), int(y0), int(x), int(y)); |
286 | 322 |
287 paint.end(); | 323 paint.end(); |