2018-02-27 18:06:05 +01:00
/***************************************************************************
amarokslider . h - description
- - - - - - - - - - - - - - - - - - -
begin : Dec 15 2003
copyright : ( C ) 2003 by Mark Kretschmann
email : markey @ web . de
copyright : ( C ) 2005 by Gábor Lehel
email : illissius @ gmail . com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***************************************************************************
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2019-03-09 16:48:45 +01:00
# ifndef VOLUMESLIDER_H
# define VOLUMESLIDER_H
2018-02-27 18:06:05 +01:00
2018-05-01 00:41:33 +02:00
# include "config.h"
# include <QtGlobal>
# include <QObject>
# include <QWidget>
# include <QList>
# include <QString>
2018-02-27 18:06:05 +01:00
# include <QPixmap>
2018-05-01 00:41:33 +02:00
# include <QColor>
# include <QPalette>
2018-02-27 18:06:05 +01:00
# include <QSlider>
2020-02-09 02:29:35 +01:00
class QTimer ;
2018-05-01 00:41:33 +02:00
class QEvent ;
class QMouseEvent ;
class QPaintEvent ;
class QWheelEvent ;
class QContextMenuEvent ;
2020-09-05 19:20:43 +02:00
class QEnterEvent ;
2018-02-27 18:06:05 +01:00
2019-03-09 16:48:45 +01:00
class SliderSlider : public QSlider {
2018-02-27 18:06:05 +01:00
Q_OBJECT
public :
2021-10-30 02:21:29 +02:00
explicit SliderSlider ( const Qt : : Orientation , QWidget * , const int max = 0 ) ;
2018-02-27 18:06:05 +01:00
virtual void setValue ( int ) ;
2019-03-09 16:48:45 +01:00
// WARNING non-virtual - and thus only really intended for internal use this is a major flaw in the class presently, however it suits our current needs fine
2018-02-27 18:06:05 +01:00
int value ( ) const { return adjustValue ( QSlider : : value ( ) ) ; }
2020-06-15 21:55:05 +02:00
signals :
2019-03-09 16:48:45 +01:00
// we emit this when the user has specifically changed the slider so connect to it if valueChanged() is too generic Qt also emits valueChanged(int)
2021-06-20 19:04:08 +02:00
void sliderReleased ( int ) ; // clazy:exclude=overloaded-signal
2018-02-27 18:06:05 +01:00
protected :
2020-06-15 21:55:05 +02:00
void wheelEvent ( QWheelEvent * ) override ;
void mouseMoveEvent ( QMouseEvent * ) override ;
void mouseReleaseEvent ( QMouseEvent * ) override ;
void mousePressEvent ( QMouseEvent * ) override ;
2018-02-27 18:06:05 +01:00
virtual void slideEvent ( QMouseEvent * ) ;
2021-06-12 16:06:30 +02:00
bool sliding_ ;
2018-02-27 18:06:05 +01:00
/// we flip the value for vertical sliders
int adjustValue ( int v ) const {
int mp = ( minimum ( ) + maximum ( ) ) / 2 ;
return orientation ( ) = = Qt : : Vertical ? mp - ( v - mp ) : v ;
}
private :
2021-06-12 16:06:30 +02:00
bool outside_ ;
int prev_value_ ;
2018-02-27 18:06:05 +01:00
2019-03-09 16:48:45 +01:00
SliderSlider ( const SliderSlider & ) ; // undefined
2021-06-12 20:53:23 +02:00
SliderSlider & operator = ( const SliderSlider & ) ; // undefined
2018-02-27 18:06:05 +01:00
} ;
2019-03-09 16:48:45 +01:00
class PrettySlider : public SliderSlider {
2018-02-27 18:06:05 +01:00
Q_OBJECT
public :
typedef enum {
Normal , // Same behavior as Slider *unless* there's a moodbar
Pretty
} SliderMode ;
2021-06-12 20:53:23 +02:00
explicit PrettySlider ( const Qt : : Orientation orientation , const SliderMode mode , QWidget * parent , const uint max = 0 ) ;
2018-02-27 18:06:05 +01:00
protected :
2020-06-15 21:55:05 +02:00
void slideEvent ( QMouseEvent * ) override ;
void mousePressEvent ( QMouseEvent * ) override ;
2018-02-27 18:06:05 +01:00
private :
PrettySlider ( const PrettySlider & ) ; // undefined
2021-06-12 20:53:23 +02:00
PrettySlider & operator = ( const PrettySlider & ) ; // undefined
2018-02-27 18:06:05 +01:00
SliderMode m_mode ;
} ;
2019-03-09 16:48:45 +01:00
class VolumeSlider : public SliderSlider {
2018-02-27 18:06:05 +01:00
Q_OBJECT
public :
2020-04-07 16:49:15 +02:00
explicit VolumeSlider ( QWidget * parent , uint max = 0 ) ;
2019-03-09 16:48:45 +01:00
void SetEnabled ( const bool enabled ) ;
2018-02-27 18:06:05 +01:00
protected :
2020-06-15 21:55:05 +02:00
void paintEvent ( QPaintEvent * ) override ;
2020-09-05 19:20:43 +02:00
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void enterEvent ( QEnterEvent * ) override ;
# else
2020-06-15 21:55:05 +02:00
void enterEvent ( QEvent * ) override ;
2020-09-05 19:20:43 +02:00
# endif
2020-06-15 21:55:05 +02:00
void leaveEvent ( QEvent * ) override ;
2018-02-27 18:06:05 +01:00
virtual void paletteChange ( const QPalette & ) ;
2020-06-15 21:55:05 +02:00
void slideEvent ( QMouseEvent * ) override ;
void mousePressEvent ( QMouseEvent * ) override ;
void contextMenuEvent ( QContextMenuEvent * ) override ;
2021-06-12 20:53:23 +02:00
void wheelEvent ( QWheelEvent * e ) override ;
2018-02-27 18:06:05 +01:00
private slots :
virtual void slotAnimTimer ( ) ;
private :
void generateGradient ( ) ;
QPixmap drawVolumePixmap ( ) const ;
void drawVolumeSliderHandle ( ) ;
VolumeSlider ( const VolumeSlider & ) ; // undefined
2021-02-02 21:08:58 +01:00
VolumeSlider & operator = ( const VolumeSlider & ) ; // undefined
2018-02-27 18:06:05 +01:00
////////////////////////////////////////////////////////////////
static const int ANIM_INTERVAL = 18 ;
static const int ANIM_MAX = 18 ;
2021-06-12 16:06:30 +02:00
bool anim_enter_ ;
int anim_count_ ;
QTimer * timer_anim_ ;
2018-02-27 18:06:05 +01:00
2021-06-12 16:06:30 +02:00
QPixmap pixmap_inset_ ;
QPixmap pixmap_gradient_ ;
2018-02-27 18:06:05 +01:00
2021-06-12 16:06:30 +02:00
QColor previous_theme_text_color_ ;
QColor previous_theme_highlight_color_ ;
2018-02-27 18:06:05 +01:00
2021-06-12 16:06:30 +02:00
QList < QPixmap > handle_pixmaps_ ;
2018-02-27 18:06:05 +01:00
} ;
2019-03-09 16:48:45 +01:00
# endif // VOLUMESLIDER_H