[vlc-devel] [PATCH 1/2] Qt: make the rendering of the volume slider independant from the image resolution
Pierre Lamot
pierre at videolabs.io
Thu Sep 14 11:05:44 CEST 2017
---
modules/gui/qt/util/input_slider.cpp | 35 ++++++++++++++++++-----------------
modules/gui/qt/util/input_slider.hpp | 3 ---
2 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index 08638e3399..e7042a3e4f 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -573,8 +573,10 @@ void SeekSlider::startAnimLoading()
- Mark Kretschmann
- Gábor Lehel
*/
-#define WLENGTH 80 // px
-#define WHEIGHT 22 // px
+#define WLENGTH 85 // px
+#define WHEIGHT 26 // px
+#define PADDINGL 6 // px
+#define PADDINGR 6 // px
#define SOUNDMIN 0 // %
SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
@@ -594,14 +596,14 @@ SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
const QPixmap temp( ":/toolbar/volslide-inside" );
const QBitmap mask( temp.createHeuristicMask() );
- setFixedSize( pixOutside.size() );
+ setFixedSize( WLENGTH, WHEIGHT );
pixGradient = QPixmap( mask.size() );
pixGradient2 = QPixmap( mask.size() );
/* Gradient building from the preferences */
- QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
- QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );
+ QLinearGradient gradient( PADDINGL, 2, pixGradient.width() - PADDINGR, 2 );
+ QLinearGradient gradient2( PADDINGL, 2, pixGradient2.width()- PADDINGR, 2 );
QStringList colorList = qfu( psz_colors ).split( ";" );
free( psz_colors );
@@ -677,7 +679,7 @@ void SoundSlider::mousePressEvent( QMouseEvent *event )
isSliding = true;
i_oldvalue = value();
emit sliderPressed();
- changeValue( event->x() - paddingL );
+ changeValue( event->x() );
emit sliderMoved( value() );
}
}
@@ -708,8 +710,8 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
if( isSliding )
{
- QRect rect( paddingL - 15, -1,
- WLENGTH + 15 * 2 , WHEIGHT + 5 );
+ QRect rect( PADDINGL - 15, -1,
+ WLENGTH - PADDINGR + 15 * 2 , WHEIGHT + 5 );
if( !rect.contains( event->pos() ) )
{ /* We are outside */
if ( !b_mouseOutside )
@@ -719,13 +721,13 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
else
{ /* We are inside */
b_mouseOutside = false;
- changeValue( event->x() - paddingL );
+ changeValue( event->x() );
emit sliderMoved( value() );
}
}
else
{
- int i = ( ( event->x() - paddingL ) * maximum() + 40 ) / WLENGTH;
+ int i = ( ( event->x() - PADDINGL ) * maximum() ) / ( WLENGTH - ( PADDINGR + PADDINGL ) );
i = __MIN( __MAX( 0, i ), maximum() );
setToolTip( QString("%1 %" ).arg( i ) );
}
@@ -733,7 +735,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
void SoundSlider::changeValue( int x )
{
- setValue( (x * maximum() + 40 ) / WLENGTH );
+ setValue( ( ( x - PADDINGL ) * maximum() ) / ( WLENGTH - ( PADDINGR + PADDINGL ) ) );
}
void SoundSlider::setMuted( bool m )
@@ -752,13 +754,12 @@ void SoundSlider::paintEvent( QPaintEvent *e )
painter.begin( this );
- const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
+ float f_scale = paintGradient->width() / float( WLENGTH );
+ const int offsetDst = int( ( ( WLENGTH - ( PADDINGR + PADDINGL ) ) * value() + 100 ) / maximum() ) + PADDINGL;
+ const int offsetSrc = int( ( ( paintGradient->width() - ( PADDINGR + PADDINGL ) * f_scale ) * value() + 100 ) / maximum() + PADDINGL * f_scale );
- const QRectF boundsG( 0, 0, offset , paintGradient->height() );
- painter.drawPixmap( boundsG, *paintGradient, boundsG );
-
- const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
- painter.drawPixmap( boundsO, pixOutside, boundsO );
+ painter.drawPixmap( 0, 0, offsetDst, WHEIGHT, *paintGradient, 0, 0, offsetSrc, paintGradient->height() );
+ painter.drawPixmap( 0, 0, WLENGTH, WHEIGHT, pixOutside, 0, 0, pixOutside.width(), pixOutside.height() );
painter.setPen( foreground );
painter.setFont( textfont );
diff --git a/modules/gui/qt/util/input_slider.hpp b/modules/gui/qt/util/input_slider.hpp
index a9559c9dad..2c593603b4 100644
--- a/modules/gui/qt/util/input_slider.hpp
+++ b/modules/gui/qt/util/input_slider.hpp
@@ -145,9 +145,6 @@ public:
void setMuted( bool ); /* Set Mute status */
protected:
- const static int paddingL = 3;
- const static int paddingR = 2;
-
void paintEvent( QPaintEvent *) Q_DECL_OVERRIDE;
void wheelEvent( QWheelEvent *event ) Q_DECL_OVERRIDE;
void mousePressEvent( QMouseEvent * ) Q_DECL_OVERRIDE;
--
2.14.1
More information about the vlc-devel
mailing list