]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/input_slider.hpp
Qt: improve look and feel of the seek handle
[vlc] / modules / gui / qt4 / util / input_slider.hpp
1 /*****************************************************************************
2  * input_slider.hpp : VolumeSlider and SeekSlider
3  ****************************************************************************
4  * Copyright (C) 2006-2011 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Ludovic Fauvet <etix@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _INPUTSLIDER_H_
27 #define _INPUTSLIDER_H_
28
29 #include <vlc_common.h>
30 #include "timetooltip.hpp"
31
32 #include <QSlider>
33
34 #define MSTRTIME_MAX_SIZE 22
35
36 class QMouseEvent;
37 class QWheelEvent;
38 class QHideEvent;
39 class QTimer;
40 class SeekPoints;
41
42 /* Input Slider derived from QSlider */
43 class SeekSlider : public QSlider
44 {
45     Q_OBJECT
46 public:
47     SeekSlider( QWidget *_parent );
48     SeekSlider( Qt::Orientation q, QWidget *_parent );
49     ~SeekSlider();
50     void setChapters( SeekPoints * );
51
52 protected:
53     virtual void mouseMoveEvent( QMouseEvent *event );
54     virtual void mousePressEvent( QMouseEvent* event );
55     virtual void mouseReleaseEvent( QMouseEvent *event );
56     virtual void wheelEvent( QWheelEvent *event );
57     virtual void enterEvent( QEvent * );
58     virtual void leaveEvent( QEvent * );
59     virtual void hideEvent( QHideEvent * );
60
61     virtual void paintEvent( QPaintEvent* event );
62     virtual bool eventFilter( QObject *obj, QEvent *event );
63
64     QSize handleSize() const;
65     QSize sizeHint() const;
66
67 private:
68     bool b_isSliding;       /* Whether we are currently sliding by user action */
69     bool b_is_jumping;      /* if we requested a jump to another chapter */
70     int inputLength;        /* InputLength that can change */
71     char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */
72     QTimer *seekLimitTimer;
73     TimeTooltip *mTimeTooltip;
74     float f_buffering;
75     SeekPoints* chapters;
76
77 public slots:
78     void setPosition( float, int64_t, int );
79     void updateBuffering( float );
80
81 private slots:
82     void startSeekTimer();
83     void updatePos();
84
85 signals:
86     void sliderDragged( float );
87 };
88
89
90 /* Sound Slider inherited directly from QAbstractSlider */
91 class QPaintEvent;
92
93 class SoundSlider : public QAbstractSlider
94 {
95     Q_OBJECT
96 public:
97     SoundSlider( QWidget *_parent, int _i_step, bool b_softamp, char * );
98     void setMuted( bool ); /* Set Mute status */
99
100 protected:
101     const static int paddingL = 3;
102     const static int paddingR = 2;
103
104     virtual void paintEvent( QPaintEvent *);
105     virtual void wheelEvent( QWheelEvent *event );
106     virtual void mousePressEvent( QMouseEvent * );
107     virtual void mouseMoveEvent( QMouseEvent * );
108     virtual void mouseReleaseEvent( QMouseEvent * );
109
110 private:
111     bool b_isSliding; /* Whether we are currently sliding by user action */
112     bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */
113     int i_oldvalue; /* Store the old Value before changing */
114     float f_step; /* How much do we increase each time we wheel */
115     bool b_isMuted;
116
117     QPixmap pixGradient; /* Gradient pix storage */
118     QPixmap pixGradient2; /* Muted Gradient pix storage */
119     QPixmap pixOutside; /* OutLine pix storage */
120
121     void changeValue( int x ); /* Function to modify the value from pixel x() */
122 };
123
124 #endif