[vlc-commits] qt: Volume slider rendering using vector graphics
Pierre Lamot
git at videolan.org
Sat Oct 14 22:28:22 CEST 2017
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Sep 29 10:25:08 2017 +0200| [c8bdc42669a0316b9573d7c18d3d16bdc66b1043] | committer: Jean-Baptiste Kempf
qt: Volume slider rendering using vector graphics
Close #18649
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c8bdc42669a0316b9573d7c18d3d16bdc66b1043
---
modules/gui/qt/util/input_slider.cpp | 49 ++++++++++++++++++++----------------
modules/gui/qt/util/input_slider.hpp | 3 ---
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index 08638e3399..e501e10f34 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -33,6 +33,7 @@
#include "util/timetooltip.hpp"
#include "adapters/seekpoints.hpp"
#include "input_manager.hpp"
+#include "imagehelper.hpp"
#include <QPaintEvent>
#include <QPainter>
@@ -49,6 +50,7 @@
#include <QPropertyAnimation>
#include <QApplication>
#include <QDebug>
+#include <QScreen>
#include <QSequentialAnimationGroup>
namespace {
@@ -573,8 +575,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,
@@ -589,19 +593,21 @@ SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
b_mouseOutside = true;
b_isMuted = false;
- pixOutside = QPixmap( ":/toolbar/volslide-outside" );
+ setFixedSize( WLENGTH, WHEIGHT );
- const QPixmap temp( ":/toolbar/volslide-inside" );
- const QBitmap mask( temp.createHeuristicMask() );
+ pixOutside = ImageHelper::loadSvgToPixmap(":/toolbar/volslide-outside", width(), height() );
- setFixedSize( pixOutside.size() );
+ const QPixmap temp = ImageHelper::loadSvgToPixmap(":/toolbar/volslide-inside", width(), height() );
+ const QBitmap mask( temp.createHeuristicMask() );
- pixGradient = QPixmap( mask.size() );
- pixGradient2 = QPixmap( mask.size() );
+ pixGradient = QPixmap( pixOutside.size() );
+ pixGradient.setDevicePixelRatio(QApplication::primaryScreen()->devicePixelRatio());
+ pixGradient2 = QPixmap( pixOutside.size() );
+ pixGradient2.setDevicePixelRatio(QApplication::primaryScreen()->devicePixelRatio());
/* Gradient building from the preferences */
- QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
- QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );
+ QLinearGradient gradient( PADDINGL, 2, width() - PADDINGR, 2 );
+ QLinearGradient gradient2( PADDINGL, 2, width()- PADDINGR, 2 );
QStringList colorList = qfu( psz_colors ).split( ";" );
free( psz_colors );
@@ -677,7 +683,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 +714,8 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
if( isSliding )
{
- QRect rect( paddingL - 15, -1,
- WLENGTH + 15 * 2 , WHEIGHT + 5 );
+ QRect rect( PADDINGL - 15, -1,
+ width() - PADDINGR + 15 * 2 , width() + 5 );
if( !rect.contains( event->pos() ) )
{ /* We are outside */
if ( !b_mouseOutside )
@@ -719,13 +725,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() ) / ( width() - ( PADDINGR + PADDINGL ) );
i = __MIN( __MAX( 0, i ), maximum() );
setToolTip( QString("%1 %" ).arg( i ) );
}
@@ -733,7 +739,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
void SoundSlider::changeValue( int x )
{
- setValue( (x * maximum() + 40 ) / WLENGTH );
+ setValue( ( ( x - PADDINGL ) * maximum() ) / ( width() - ( PADDINGR + PADDINGL ) ) );
}
void SoundSlider::setMuted( bool m )
@@ -752,13 +758,12 @@ void SoundSlider::paintEvent( QPaintEvent *e )
painter.begin( this );
- const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
-
- const QRectF boundsG( 0, 0, offset , paintGradient->height() );
- painter.drawPixmap( boundsG, *paintGradient, boundsG );
+ float f_scale = paintGradient->width() / float( width() );
+ const int offsetDst = int( ( ( width() - ( PADDINGR + PADDINGL ) ) * value() + 100 ) / maximum() ) + PADDINGL;
+ const int offsetSrc = int( ( ( paintGradient->width() - ( PADDINGR + PADDINGL ) * f_scale ) * value() + 100 ) / maximum() + PADDINGL * f_scale );
- const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
- painter.drawPixmap( boundsO, pixOutside, boundsO );
+ painter.drawPixmap( 0, 0, offsetDst, height(), *paintGradient, 0, 0, offsetSrc, paintGradient->height() );
+ painter.drawPixmap( 0, 0, width(), height(), 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;
More information about the vlc-commits
mailing list