25 #include <tqdatetime.h>
30 #include <tqpainter.h>
33 #include <tdeapplication.h>
34 #include <kpixmapeffect.h>
38 class KLed::KLedPrivate
51 : TQWidget( parent, name),
57 d =
new KLed::KLedPrivate;
59 d->offcolor = col.dark(300);
67 KLed::KLed(
const TQColor& col, TQWidget *parent,
const char *name)
68 : TQWidget( parent, name),
73 d =
new KLed::KLedPrivate;
75 d->offcolor = col.dark(300);
85 : TQWidget(parent, name),
90 d =
new KLed::KLedPrivate;
92 d->offcolor = col.dark(300);
109 KLed::paintEvent(TQPaintEvent *)
112 const int rounds = 1000;
115 for (
int i=0; i<rounds; i++) {
132 tqWarning(
"%s: in class KLed: no KLed::Look set",tqApp->argv()[0]);
148 tqWarning(
"%s: in class KLed: no KLed::Look set",tqApp->argv()[0]);
152 tqWarning(
"%s: in class KLed: no KLed::Shape set",tqApp->argv()[0]);
157 int ready = t.elapsed();
158 tqWarning(
"elapsed: %d msec. for %d rounds", ready, rounds);
167 int width = this->width();
169 if (width > this->height())
170 width = this->height();
183 TQPainter paint(
this);
184 paint.drawPixmap(0, 0, *d->on_map);
189 TQPainter paint(
this);
190 paint.drawPixmap(0, 0, *d->off_map);
212 TQPixmap *tmpMap = 0;
216 tmpMap =
new TQPixmap(width + 6, width + 6);
217 tmpMap->fill(paletteBackgroundColor());
224 color = ( led_state ) ? led_color : d->offcolor;
228 brush.setStyle( TQt::SolidPattern );
229 brush.setColor(
color );
231 pen.setWidth( scale );
232 color = colorGroup().dark();
233 pen.setColor(
color );
236 paint.setBrush( brush );
239 paint.drawEllipse( scale, scale, width - scale * 2, width - scale * 2 );
244 TQPixmap *&dest = led_state ? d->on_map : d->off_map;
245 TQImage i = tmpMap->convertToImage();
247 i = i.smoothScale(width, width);
249 dest =
new TQPixmap(i);
251 paint.drawPixmap(0, 0, *dest);
270 TQPixmap *tmpMap = 0;
274 tmpMap =
new TQPixmap(width + 6, width + 6);
275 tmpMap->fill(paletteBackgroundColor());
279 color = ( led_state ) ? led_color : d->offcolor;
283 brush.setStyle( TQt::SolidPattern );
284 brush.setColor(
color );
285 paint.setBrush( brush );
288 paint.drawEllipse( scale, scale, width - scale*2, width - scale*2 );
295 pen.setWidth( 2 * scale );
298 int pos = width/5 + 1;
299 int light_width = width;
304 int light_quote = (130*2/(light_width?light_width:1))+100;
307 while (light_width) {
309 pen.setColor(
color );
311 paint.drawEllipse( pos, pos, light_width, light_width );
315 paint.drawEllipse( pos, pos, light_width, light_width );
319 paint.drawEllipse( pos, pos, light_width, light_width );
320 pos++; light_width--;
327 pen.setWidth( 2 * scale + 1 );
328 color = colorGroup().dark();
329 pen.setColor(
color );
331 brush.setStyle( TQt::NoBrush );
332 paint.setBrush( brush );
334 paint.drawEllipse( 2, 2, width, width );
339 TQPixmap *&dest = led_state ? d->on_map : d->off_map;
340 TQImage i = tmpMap->convertToImage();
342 i = i.smoothScale(width, width);
344 dest =
new TQPixmap(i);
346 paint.drawPixmap(0, 0, *dest);
366 TQPixmap *tmpMap = 0;
370 tmpMap =
new TQPixmap(width, width);
371 tmpMap->fill(paletteBackgroundColor());
375 color = ( led_state ) ? led_color : d->offcolor;
379 brush.setStyle( TQt::SolidPattern );
380 brush.setColor(
color );
381 paint.setBrush( brush );
384 paint.drawEllipse( scale, scale, width - scale*2, width - scale*2 );
391 pen.setWidth( 2 * scale );
394 int pos = width/5 + 1;
395 int light_width = width;
400 int light_quote = (130*2/(light_width?light_width:1))+100;
403 while (light_width) {
405 pen.setColor(
color );
407 paint.drawEllipse( pos, pos, light_width, light_width );
411 paint.drawEllipse( pos, pos, light_width, light_width );
415 paint.drawEllipse( pos, pos, light_width, light_width );
416 pos++; light_width--;
423 pen.setWidth( 2 * scale + 1 );
424 brush.setStyle( (TQt::BrushStyle)NoBrush );
425 paint.setBrush( brush );
431 color = colorGroup().light();
433 for (
int arc = 120; arc < 2880; arc += 240 ) {
434 pen.setColor(
color );
436 int w = width - pen.width()/2 - scale + 1;
437 paint.drawArc( pen.width()/2, pen.width()/2, w, w, angle + arc, 240 );
438 paint.drawArc( pen.width()/2, pen.width()/2, w, w, angle - arc, 240 );
446 TQPixmap *&dest = led_state ? d->on_map : d->off_map;
447 TQImage i = tmpMap->convertToImage();
449 i = i.smoothScale(width, width);
451 dest =
new TQPixmap(i);
453 paint.drawPixmap(0, 0, *dest);
461 TQPainter painter(
this);
462 TQBrush lightBrush(led_color);
463 TQBrush darkBrush(d->offcolor);
464 TQPen pen(led_color.dark(300));
471 painter.setBrush(lightBrush);
472 painter.drawRect(0, 0, w, h);
475 painter.setBrush(darkBrush);
476 painter.drawRect(0, 0, w, h);
478 painter.drawLine(0, 0, w, 0);
479 painter.drawLine(0, h-1, w, h-1);
482 for(i=0; i < w; i+= 4 )
483 painter.drawLine(i, 1, i, h-1);
492 TQPainter painter(
this);
493 TQBrush lightBrush(led_color);
494 TQBrush darkBrush(d->offcolor);
497 TQColor black=TQt::black;
498 TQColor white=TQt::white;
502 painter.setPen(white);
503 painter.drawLine(0, 0, 0, h-1);
504 painter.drawLine(1, 0, w-1, 0);
505 painter.setPen(black);
506 painter.drawLine(1, h-1, w-1, h-1);
507 painter.drawLine(w-1, 1, w-1, h-1);
508 painter.fillRect(1, 1, w-2, h-2,
509 (led_state==On)? lightBrush : darkBrush);
511 painter.setPen(black);
512 painter.drawRect(0,0,w,h);
513 painter.drawRect(0,0,w-1,h-1);
514 painter.setPen(white);
515 painter.drawRect(1,1,w-1,h-1);
516 painter.fillRect(2, 2, w-4, h-4,
517 (led_state==On)? lightBrush : darkBrush);
542 return led_off_color;
554 if (led_state !=
state)
581 if(d->on_map) {
delete d->on_map; d->on_map = 0; }
582 if(d->off_map) {
delete d->off_map; d->off_map = 0; }
584 d->offcolor = col.dark(d->dark_factor);
592 if(led_off_color!=col) {
593 if(d->on_map) {
delete d->on_map; d->on_map = 0; }
594 if(d->off_map) {
delete d->off_map; d->off_map = 0; }
603 if (d->dark_factor != darkfactor) {
604 d->dark_factor = darkfactor;
605 d->offcolor = led_color.dark(darkfactor);
613 return d->dark_factor;
629 led_state = (led_state == On) ? Off : On;
647 KLed::sizeHint()
const
649 return TQSize(16, 16);
653 KLed::minimumSizeHint()
const
655 return TQSize(16, 16 );
658 void KLed::virtual_hook(
int,
void* )
void on()
Sets the state of the widget to On.
State
Status of the light is on/off.
virtual void paintRectFrame(bool raised)
Paints a rectangular LED, either raised or sunken, depending on its argument.
void setOffColor(const TQColor &color)
Set the off color of the widget.
void setDarkFactor(int darkfactor)
Sets the factor to darken the LED in OFF state.
virtual void paintRect()
Paints a rectangular, flat LED.
void toggleState() TDE_DEPRECATED
Toggle the state of the LED from Off to On and vice versa.
int ensureRoundLed()
Compute LED width.
Look
Displays a flat, round or sunken LED.
State state() const
Returns the current state of the widget (on/off).
void setColor(const TQColor &color)
Set the color of the widget.
TQColor color() const
Returns the color of the widget.
virtual void paintRound()
Paints a circular, raised LED.
void off()
Sets the state of the widget to Off.
Look look() const
Returns the look of the widget.
void setState(State state)
Sets the state of the widget to On or Off.
virtual void paintFlat()
Paints a circular, flat LED.
virtual void paintSunken()
Paints a circular, sunken LED.
void toggle()
Toggles the state of the led from Off to On or vice versa.
KLed(TQWidget *parent=0, const char *name=0)
Constructs a green, round LED widget which will initially be turned on.
TQColor offColor() const
Returns the off color of the widget.
void setLook(Look look)
Sets the color of the widget.
void setShape(Shape s)
Set the shape of the LED to s.
int darkFactor() const
Returns the factor to darken the LED.
bool paintCachedPixmap()
Paint the cached antialiased pixmap corresponding to the state if any.