vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Sat Mar 3 22:29:10 2012 +0100| [baf9deddc7313288415cdd0f6afa1f6423dbea9c] | committer: Francois Cartegnie
Qt: SoundSlider: optimize paint method > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=baf9deddc7313288415cdd0f6afa1f6423dbea9c --- modules/gui/qt4/util/input_slider.cpp | 25 ++++++++++++++----------- modules/gui/qt4/util/input_slider.hpp | 6 ++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp index d45a0e4..d94bf5c 100644 --- a/modules/gui/qt4/util/input_slider.cpp +++ b/modules/gui/qt4/util/input_slider.cpp @@ -600,6 +600,15 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, for( int i = colorList.count(); i < 12; i++) 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 */ #define c(i) colorList.at(i).toInt() #define add_color(gradient, range, c1, c2, c3) \ @@ -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, 1.0, 9, 10, 11 ); - QPainter painter( &pixGradient ); + painter.begin( &pixGradient ); painter.setPen( Qt::NoPen ); painter.setBrush( gradient ); painter.drawRect( pixGradient.rect() ); @@ -716,13 +725,14 @@ void SoundSlider::setMuted( bool m ) void SoundSlider::paintEvent( QPaintEvent *e ) { - QPainter painter( this ); QPixmap *paintGradient; if (b_isMuted) paintGradient = &this->pixGradient2; else paintGradient = &this->pixGradient; + painter.begin( this ); + const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL; const QRectF boundsG( 0, 0, offset , paintGradient->height() ); @@ -731,16 +741,9 @@ void SoundSlider::paintEvent( QPaintEvent *e ) const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() ); 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 ); - QFont font; font.setPixelSize( 9 ); - painter.setFont( font ); - const QRect rect( 0, 0, 34, 15 ); - painter.drawText( rect, Qt::AlignRight | Qt::AlignVCenter, + painter.setFont( textfont ); + painter.drawText( textrect, Qt::AlignRight | Qt::AlignVCenter, QString::number( value() ) + '%' ); painter.end(); diff --git a/modules/gui/qt4/util/input_slider.hpp b/modules/gui/qt4/util/input_slider.hpp index 3e052e8..ea47d66 100644 --- a/modules/gui/qt4/util/input_slider.hpp +++ b/modules/gui/qt4/util/input_slider.hpp @@ -34,6 +34,7 @@ #include "timetooltip.hpp" #include <QSlider> +#include <QPainter> #define MSTRTIME_MAX_SIZE 22 @@ -133,6 +134,11 @@ private: QPixmap pixGradient; /* Gradient pix storage */ QPixmap pixGradient2; /* Muted Gradient 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() */ }; _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org http://mailman.videolan.org/listinfo/vlc-commits