Mercurial > hg > svgui
comparison widgets/LEDButton.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 3f5c82034f9b |
children | d39db4673676 |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
86 LEDButton::mousePressEvent(QMouseEvent *e) | 86 LEDButton::mousePressEvent(QMouseEvent *e) |
87 { | 87 { |
88 cerr << "LEDButton(" << this << ")::mousePressEvent" << endl; | 88 cerr << "LEDButton(" << this << ")::mousePressEvent" << endl; |
89 | 89 |
90 if (e->buttons() & Qt::LeftButton) { | 90 if (e->buttons() & Qt::LeftButton) { |
91 toggle(); | 91 toggle(); |
92 bool newState = state(); | 92 bool newState = state(); |
93 SVDEBUG << "emitting new state " << newState << endl; | 93 SVDEBUG << "emitting new state " << newState << endl; |
94 emit stateChanged(newState); | 94 emit stateChanged(newState); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 void | 98 void |
99 LEDButton::enterEvent(QEvent *) | 99 LEDButton::enterEvent(QEvent *) |
112 { | 112 { |
113 QPainter paint; | 113 QPainter paint; |
114 QColor color; | 114 QColor color; |
115 QBrush brush; | 115 QBrush brush; |
116 QPen pen; | 116 QPen pen; |
117 | 117 |
118 // First of all we want to know what area should be updated | 118 // First of all we want to know what area should be updated |
119 // Initialize coordinates, width, and height of the LED | 119 // Initialize coordinates, width, and height of the LED |
120 int width = this->width(); | 120 int width = this->width(); |
121 | 121 |
122 // Make sure the LED is round! | 122 // Make sure the LED is round! |
123 if (width > this->height()) | 123 if (width > this->height()) |
124 width = this->height(); | 124 width = this->height(); |
125 width -= 2; // leave one pixel border | 125 width -= 2; // leave one pixel border |
126 if (width < 0) | 126 if (width < 0) |
127 width = 0; | 127 width = 0; |
128 | 128 |
129 paint.begin(this); | 129 paint.begin(this); |
130 | 130 |
131 paint.setRenderHint(QPainter::Antialiasing, true); | 131 paint.setRenderHint(QPainter::Antialiasing, true); |
132 | 132 |
152 // shrink the light on the LED to a size about 2/3 of the complete LED | 152 // shrink the light on the LED to a size about 2/3 of the complete LED |
153 int pos = width/5 + 1; | 153 int pos = width/5 + 1; |
154 int light_width = width; | 154 int light_width = width; |
155 light_width *= 2; | 155 light_width *= 2; |
156 light_width /= 3; | 156 light_width /= 3; |
157 | 157 |
158 // Calculate the LEDīs "light factor": | 158 // Calculate the LEDīs "light factor": |
159 int light_quote = (130*2/(light_width?light_width:1))+100; | 159 int light_quote = (130*2/(light_width?light_width:1))+100; |
160 | 160 |
161 // Now draw the bright spot on the LED: | 161 // Now draw the bright spot on the LED: |
162 while (light_width) { | 162 while (light_width) { |
163 color = color.light( light_quote ); // make color lighter | 163 color = color.light( light_quote ); // make color lighter |
164 pen.setColor( color ); // set color as pen color | 164 pen.setColor( color ); // set color as pen color |
165 paint.setPen( pen ); // select the pen for drawing | 165 paint.setPen( pen ); // select the pen for drawing |
166 paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) | 166 paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) |
167 light_width--; | 167 light_width--; |
168 if (!light_width) | 168 if (!light_width) |
169 break; | 169 break; |
170 paint.drawEllipse( pos, pos, light_width, light_width ); | 170 paint.drawEllipse( pos, pos, light_width, light_width ); |
171 light_width--; | 171 light_width--; |
172 if (!light_width) | 172 if (!light_width) |
173 break; | 173 break; |
174 paint.drawEllipse( pos, pos, light_width, light_width ); | 174 paint.drawEllipse( pos, pos, light_width, light_width ); |
175 pos++; light_width--; | 175 pos++; light_width--; |
176 } | 176 } |
177 | 177 |
178 paint.drawPoint(pos, pos); | 178 paint.drawPoint(pos, pos); |
179 | 179 |
180 // Drawing of bright spot finished, now draw a thin border | 180 // Drawing of bright spot finished, now draw a thin border |
190 | 190 |
191 int angle = -720; | 191 int angle = -720; |
192 color = palette().light().color(); | 192 color = palette().light().color(); |
193 | 193 |
194 for (int arc = 120; arc < 2880; arc += 240) { | 194 for (int arc = 120; arc < 2880; arc += 240) { |
195 pen.setColor(color); | 195 pen.setColor(color); |
196 paint.setPen(pen); | 196 paint.setPen(pen); |
197 int w = width - pen.width()/2; | 197 int w = width - pen.width()/2; |
198 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle + arc, 240); | 198 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle + arc, 240); |
199 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle - arc, 240); | 199 paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle - arc, 240); |
200 color = color.dark(110); //FIXME: this should somehow use the contrast value | 200 color = color.dark(110); //FIXME: this should somehow use the contrast value |
201 } // end for ( angle = 720; angle < 6480; angle += 160 ) | 201 } // end for ( angle = 720; angle < 6480; angle += 160 ) |
202 | 202 |
203 paint.end(); | 203 paint.end(); |
204 } | 204 } |
205 | 205 |
206 bool | 206 bool |
218 void | 218 void |
219 LEDButton::setState( bool state ) | 219 LEDButton::setState( bool state ) |
220 { | 220 { |
221 if (led_state != state) | 221 if (led_state != state) |
222 { | 222 { |
223 led_state = state; | 223 led_state = state; |
224 update(); | 224 update(); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 void | 228 void |
229 LEDButton::toggleState() | 229 LEDButton::toggleState() |
235 | 235 |
236 void | 236 void |
237 LEDButton::setColor(const QColor& col) | 237 LEDButton::setColor(const QColor& col) |
238 { | 238 { |
239 if(led_color!=col) { | 239 if(led_color!=col) { |
240 led_color = col; | 240 led_color = col; |
241 d->offcolor = col.dark(d->dark_factor); | 241 d->offcolor = col.dark(d->dark_factor); |
242 update(); | 242 update(); |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 void | 246 void |
247 LEDButton::setDarkFactor(int darkfactor) | 247 LEDButton::setDarkFactor(int darkfactor) |
248 { | 248 { |
249 if (d->dark_factor != darkfactor) { | 249 if (d->dark_factor != darkfactor) { |
250 d->dark_factor = darkfactor; | 250 d->dark_factor = darkfactor; |
251 d->offcolor = led_color.dark(darkfactor); | 251 d->offcolor = led_color.dark(darkfactor); |
252 update(); | 252 update(); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 int | 256 int |
257 LEDButton::darkFactor() const | 257 LEDButton::darkFactor() const |