Mercurial > hg > svgui
comparison widgets/LEDButton.cpp @ 33:651e4e868bcc
* Implement play mute, level and pan controls and a layer visibility control
* Handle swapping the buffers in AudioCallbackPlaySource more gracefully, so
that in many cases it can be done inaudibly. Still gets it wrong when
playing in a noncontiguous selection.
* Fix to SV file save for non-2d sparse models
* Fixes to LED button drawing and AudioDial mouse functionality
* Add progress bar for Ogg file import
* Reshuffle PropertyContainer and its subclasses so it can be a QObject
* Add layer dormancy (invisible layer permitted to free its cache space)
* Optimisations to SpectrogramLayer, removing locks when reading/writing
individual pixels in the cache (should be unnecessary there) -- there's
still an issue here as we need a lock when reading from the model in
case the model is replaced, and we don't currently have one
* Several munlock() calls to make it harder to exhaust real memory if
running in an RT mode with mlockall() active
author | Chris Cannam |
---|---|
date | Fri, 17 Feb 2006 18:04:26 +0000 |
parents | c53b949ef142 |
children | c43f2c4f66f2 |
comparison
equal
deleted
inserted
replaced
32:c53b949ef142 | 33:651e4e868bcc |
---|---|
20 #include "LEDButton.h" | 20 #include "LEDButton.h" |
21 | 21 |
22 #include <QPainter> | 22 #include <QPainter> |
23 #include <QImage> | 23 #include <QImage> |
24 #include <QColor> | 24 #include <QColor> |
25 #include <QMouseEvent> | |
25 | 26 |
26 | 27 |
27 class LEDButton::LEDButtonPrivate | 28 class LEDButton::LEDButtonPrivate |
28 { | 29 { |
29 friend class LEDButton; | 30 friend class LEDButton; |
79 LEDButton::~LEDButton() | 80 LEDButton::~LEDButton() |
80 { | 81 { |
81 delete d->off_map; | 82 delete d->off_map; |
82 delete d->on_map; | 83 delete d->on_map; |
83 delete d; | 84 delete d; |
85 } | |
86 | |
87 void | |
88 LEDButton::mousePressEvent(QMouseEvent *e) | |
89 { | |
90 if (e->buttons() & Qt::LeftButton) { | |
91 toggle(); | |
92 emit stateChanged(state()); | |
93 } | |
84 } | 94 } |
85 | 95 |
86 void | 96 void |
87 LEDButton::paintEvent(QPaintEvent *) | 97 LEDButton::paintEvent(QPaintEvent *) |
88 { | 98 { |
123 paint.end(); | 133 paint.end(); |
124 return; | 134 return; |
125 } | 135 } |
126 } | 136 } |
127 | 137 |
128 scale = 3; | 138 scale = 1; |
129 width *= scale; | 139 width *= scale; |
130 | 140 |
131 tmpMap = new QPixmap(width, width); | 141 tmpMap = new QPixmap(width, width); |
132 tmpMap->fill(palette().background().color()); | 142 tmpMap->fill(palette().background().color()); |
133 paint.begin(tmpMap); | 143 paint.begin(tmpMap); |
134 | 144 |
135 } else { | 145 } else { |
136 paint.begin(this); | 146 paint.begin(this); |
137 } | 147 } |
138 | 148 |
139 paint.setRenderHint(QPainter::Antialiasing, false); | 149 paint.setRenderHint(QPainter::Antialiasing, true); |
140 | 150 |
141 // Set the color of the LED according to given parameters | 151 // Set the color of the LED according to given parameters |
142 color = (led_state) ? led_color : d->offcolor; | 152 color = (led_state) ? led_color : d->offcolor; |
143 | 153 |
144 // Set the brush to SolidPattern, this fills the entire area | 154 // Set the brush to SolidPattern, this fills the entire area |
185 | 195 |
186 // Drawing of bright spot finished, now draw a thin border | 196 // Drawing of bright spot finished, now draw a thin border |
187 // around the LED which resembles a shadow with light coming | 197 // around the LED which resembles a shadow with light coming |
188 // from the upper left. | 198 // from the upper left. |
189 | 199 |
190 pen.setWidth( 2 * scale + 1 ); // ### shouldn't this value be smaller for smaller LEDs? | 200 // pen.setWidth( 2 * scale + 1 ); // ### shouldn't this value be smaller for smaller LEDs? |
201 pen.setWidth(2 * scale); | |
191 brush.setStyle(Qt::NoBrush); | 202 brush.setStyle(Qt::NoBrush); |
192 paint.setBrush(brush); // This avoids filling of the ellipse | 203 paint.setBrush(brush); // This avoids filling of the ellipse |
193 | 204 |
194 // Set the initial color value to colorGroup().light() (bright) and start | 205 // Set the initial color value to colorGroup().light() (bright) and start |
195 // drawing the shadow border at 45° (45*16 = 720). | 206 // drawing the shadow border at 45° (45*16 = 720). |
199 | 210 |
200 for (int arc = 120; arc < 2880; arc += 240) { | 211 for (int arc = 120; arc < 2880; arc += 240) { |
201 pen.setColor(color); | 212 pen.setColor(color); |
202 paint.setPen(pen); | 213 paint.setPen(pen); |
203 int w = width - pen.width()/2 - scale + 1; | 214 int w = width - pen.width()/2 - scale + 1; |
204 paint.drawArc(pen.width()/2, pen.width()/2, w, w, angle + arc, 240); | 215 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle + arc, 240); |
205 paint.drawArc(pen.width()/2, pen.width()/2, w, w, angle - arc, 240); | 216 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle - arc, 240); |
206 color = color.dark(110); //FIXME: this should somehow use the contrast value | 217 color = color.dark(110); //FIXME: this should somehow use the contrast value |
207 } // end for ( angle = 720; angle < 6480; angle += 160 ) | 218 } // end for ( angle = 720; angle < 6480; angle += 160 ) |
208 | 219 |
209 paint.end(); | 220 paint.end(); |
210 // | 221 // |
211 // painting done | 222 // painting done |
212 | 223 |
213 if (smooth) { | 224 if (smooth) { |
214 QPixmap *&dest = led_state ? d->on_map : d->off_map; | 225 QPixmap *&dest = led_state ? d->on_map : d->off_map; |
215 QImage i = tmpMap->toImage(); | 226 QImage i = tmpMap->toImage(); |
216 width /= 3; | 227 width /= scale; |
217 i = i.scaled(width, width, | |
218 Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | |
219 delete tmpMap; | 228 delete tmpMap; |
220 dest = new QPixmap(QPixmap::fromImage(i)); | 229 dest = new QPixmap(QPixmap::fromImage |
230 (i.scaled(width, width, | |
231 Qt::KeepAspectRatio, | |
232 Qt::SmoothTransformation))); | |
221 paint.begin(this); | 233 paint.begin(this); |
222 paint.drawPixmap(0, 0, *dest); | 234 paint.drawPixmap(0, 0, *dest); |
223 paint.end(); | 235 paint.end(); |
224 } | 236 } |
225 } | 237 } |
303 } | 315 } |
304 | 316 |
305 QSize | 317 QSize |
306 LEDButton::sizeHint() const | 318 LEDButton::sizeHint() const |
307 { | 319 { |
308 return QSize(16, 16); | 320 return QSize(17, 17); |
309 } | 321 } |
310 | 322 |
311 QSize | 323 QSize |
312 LEDButton::minimumSizeHint() const | 324 LEDButton::minimumSizeHint() const |
313 { | 325 { |
314 return QSize(16, 16 ); | 326 return QSize(17, 17); |
315 } | 327 } |
316 | 328 |