# HG changeset patch # User Chris Cannam # Date 1435672823 -3600 # Node ID 04337eb34f23799636755ec17567cadfe88b7467 # Parent 5d4730da027664807887eea7f50c536b83919d8a Render LED button direct to widget, making it look OK on retina screen diff -r 5d4730da0276 -r 04337eb34f23 widgets/LEDButton.cpp --- a/widgets/LEDButton.cpp Tue Jun 30 14:58:09 2015 +0100 +++ b/widgets/LEDButton.cpp Tue Jun 30 15:00:23 2015 +0100 @@ -38,8 +38,6 @@ int dark_factor; QColor offcolor; - QPixmap *off_map; - QPixmap *on_map; }; @@ -51,8 +49,6 @@ d = new LEDButton::LEDButtonPrivate; d->dark_factor = 300; d->offcolor = col.dark(300); - d->off_map = 0; - d->on_map = 0; setColor(col); } @@ -65,8 +61,6 @@ d = new LEDButton::LEDButtonPrivate; d->dark_factor = 300; d->offcolor = col.dark(300); - d->off_map = 0; - d->on_map = 0; setColor(col); } @@ -78,16 +72,12 @@ d = new LEDButton::LEDButtonPrivate; d->dark_factor = 300; d->offcolor = col.dark(300); - d->off_map = 0; - d->on_map = 0; setColor(col); } LEDButton::~LEDButton() { - delete d->off_map; - delete d->on_map; delete d; } @@ -135,40 +125,7 @@ if (width < 0) width = 0; - QPixmap *tmpMap = 0; - - if (led_state) { - if (d->on_map) { - if (d->on_map->size() == size()) { - paint.begin(this); - paint.drawPixmap(0, 0, *d->on_map); - paint.end(); - return; - } else { - delete d->on_map; - d->on_map = 0; - } - } - } else { - if (d->off_map) { - if (d->off_map->size() == size()) { - paint.begin(this); - paint.drawPixmap(0, 0, *d->off_map); - paint.end(); - return; - } else { - delete d->off_map; - d->off_map = 0; - } - } - } - - int scale = 1; - width *= scale; - - tmpMap = new QPixmap(width, width); - tmpMap->fill(palette().background().color()); - paint.begin(tmpMap); + paint.begin(this); paint.setRenderHint(QPainter::Antialiasing, true); @@ -182,14 +139,14 @@ paint.setBrush(brush); // Draws a "flat" LED with the given color: - paint.drawEllipse( scale, scale, width - scale*2, width - scale*2 ); + paint.drawEllipse( 1, 1, width - 2, width - 2 ); // Draw the bright light spot of the LED now, using modified "old" // painter routine taken from KDEUI´s LEDButton widget: // Setting the new width of the pen is essential to avoid "pixelized" // shadow like it can be observed with the old LED code - pen.setWidth( 2 * scale ); + pen.setWidth( 2 ); // shrink the light on the LED to a size about 2/3 of the complete LED int pos = width/5 + 1; @@ -221,8 +178,7 @@ // around the LED which resembles a shadow with light coming // from the upper left. -// pen.setWidth( 2 * scale + 1 ); // ### shouldn't this value be smaller for smaller LEDs? - pen.setWidth(2 * scale); + pen.setWidth(2); brush.setStyle(Qt::NoBrush); paint.setBrush(brush); // This avoids filling of the ellipse @@ -235,36 +191,13 @@ for (int arc = 120; arc < 2880; arc += 240) { pen.setColor(color); paint.setPen(pen); - int w = width - pen.width()/2 - scale + 1; + int w = width - pen.width()/2; paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle + arc, 240); paint.drawArc(pen.width()/2 + 1, pen.width()/2 + 1, w - 2, w - 2, angle - arc, 240); color = color.dark(110); //FIXME: this should somehow use the contrast value } // end for ( angle = 720; angle < 6480; angle += 160 ) paint.end(); - // - // painting done - - QPixmap *&dest = led_state ? d->on_map : d->off_map; - - if (scale > 1) { - - QImage i = tmpMap->toImage(); - width /= scale; - delete tmpMap; - dest = new QPixmap(QPixmap::fromImage - (i.scaled(width, width, - Qt::KeepAspectRatio, - Qt::SmoothTransformation))); - - } else { - - dest = tmpMap; - } - - paint.begin(this); - paint.drawPixmap(0, 0, *dest); - paint.end(); } bool @@ -303,10 +236,6 @@ if(led_color!=col) { led_color = col; d->offcolor = col.dark(d->dark_factor); - delete d->on_map; - d->on_map = 0; - delete d->off_map; - d->off_map = 0; update(); } }