Commit baf9dedd authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: SoundSlider: optimize paint method

parent 29fe32be
...@@ -600,6 +600,15 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -600,6 +600,15 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
for( int i = colorList.count(); i < 12; i++) for( int i = colorList.count(); i < 12; i++)
colorList.append( "255" ); colorList.append( "255" );
background = palette().color( QPalette::Active, QPalette::Background );
foreground = palette().color( QPalette::Active, QPalette::WindowText );
foreground.setHsv( foreground.hue(),
( background.saturation() + foreground.saturation() ) / 2,
( background.value() + foreground.value() ) / 2 );
textfont.setPixelSize( 9 );
textrect.setRect( 0, 0, 34, 15 );
/* Regular colors */ /* Regular colors */
#define c(i) colorList.at(i).toInt() #define c(i) colorList.at(i).toInt()
#define add_color(gradient, range, c1, c2, c3) \ #define add_color(gradient, range, c1, c2, c3) \
...@@ -623,7 +632,7 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -623,7 +632,7 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
add_colors( gradient, gradient2, 0.55, 6, 7, 8 ); add_colors( gradient, gradient2, 0.55, 6, 7, 8 );
add_colors( gradient, gradient2, 1.0, 9, 10, 11 ); add_colors( gradient, gradient2, 1.0, 9, 10, 11 );
QPainter painter( &pixGradient ); painter.begin( &pixGradient );
painter.setPen( Qt::NoPen ); painter.setPen( Qt::NoPen );
painter.setBrush( gradient ); painter.setBrush( gradient );
painter.drawRect( pixGradient.rect() ); painter.drawRect( pixGradient.rect() );
...@@ -716,13 +725,14 @@ void SoundSlider::setMuted( bool m ) ...@@ -716,13 +725,14 @@ void SoundSlider::setMuted( bool m )
void SoundSlider::paintEvent( QPaintEvent *e ) void SoundSlider::paintEvent( QPaintEvent *e )
{ {
QPainter painter( this );
QPixmap *paintGradient; QPixmap *paintGradient;
if (b_isMuted) if (b_isMuted)
paintGradient = &this->pixGradient2; paintGradient = &this->pixGradient2;
else else
paintGradient = &this->pixGradient; paintGradient = &this->pixGradient;
painter.begin( this );
const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL; const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
const QRectF boundsG( 0, 0, offset , paintGradient->height() ); const QRectF boundsG( 0, 0, offset , paintGradient->height() );
...@@ -731,16 +741,9 @@ void SoundSlider::paintEvent( QPaintEvent *e ) ...@@ -731,16 +741,9 @@ void SoundSlider::paintEvent( QPaintEvent *e )
const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() ); const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
painter.drawPixmap( boundsO, pixOutside, boundsO ); painter.drawPixmap( boundsO, pixOutside, boundsO );
QColor background = palette().color( QPalette::Active, QPalette::Background );
QColor foreground = palette().color( QPalette::Active, QPalette::WindowText );
foreground.setHsv( foreground.hue(),
( background.saturation() + foreground.saturation() ) / 2,
( background.value() + foreground.value() ) / 2 );
painter.setPen( foreground ); painter.setPen( foreground );
QFont font; font.setPixelSize( 9 ); painter.setFont( textfont );
painter.setFont( font ); painter.drawText( textrect, Qt::AlignRight | Qt::AlignVCenter,
const QRect rect( 0, 0, 34, 15 );
painter.drawText( rect, Qt::AlignRight | Qt::AlignVCenter,
QString::number( value() ) + '%' ); QString::number( value() ) + '%' );
painter.end(); painter.end();
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "timetooltip.hpp" #include "timetooltip.hpp"
#include <QSlider> #include <QSlider>
#include <QPainter>
#define MSTRTIME_MAX_SIZE 22 #define MSTRTIME_MAX_SIZE 22
...@@ -133,6 +134,11 @@ private: ...@@ -133,6 +134,11 @@ private:
QPixmap pixGradient; /* Gradient pix storage */ QPixmap pixGradient; /* Gradient pix storage */
QPixmap pixGradient2; /* Muted Gradient pix storage */ QPixmap pixGradient2; /* Muted Gradient pix storage */
QPixmap pixOutside; /* OutLine pix storage */ QPixmap pixOutside; /* OutLine pix storage */
QPainter painter;
QColor background;
QColor foreground;
QFont textfont;
QRect textrect;
void changeValue( int x ); /* Function to modify the value from pixel x() */ void changeValue( int x ); /* Function to modify the value from pixel x() */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment