]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/input_slider.hpp
2a60643afd63d9e466f80779723a62779b948dec
[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 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include "timetooltip.hpp"
35 #include "styles/seekstyle.hpp"
36
37 #include <QSlider>
38 #include <QPainter>
39
40 #define MSTRTIME_MAX_SIZE 22
41
42 class QMouseEvent;
43 class QWheelEvent;
44 class QHideEvent;
45 class QTimer;
46 class SeekPoints;
47 class QPropertyAnimation;
48 class QStyleOption;
49
50 /* Input Slider derived from QSlider */
51 class SeekSlider : public QSlider
52 {
53     Q_OBJECT
54     Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
55 public:
56     SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false );
57     ~SeekSlider();
58     void setChapters( SeekPoints * );
59
60 protected:
61     virtual void mouseMoveEvent( QMouseEvent *event );
62     virtual void mousePressEvent( QMouseEvent* event );
63     virtual void mouseReleaseEvent( QMouseEvent *event );
64     virtual void wheelEvent( QWheelEvent *event );
65     virtual void enterEvent( QEvent * );
66     virtual void leaveEvent( QEvent * );
67     virtual void hideEvent( QHideEvent * );
68
69     virtual bool eventFilter( QObject *obj, QEvent *event );
70
71     virtual QSize sizeHint() const;
72
73     bool isAnimationRunning() const;
74     qreal handleOpacity() const;
75     void setHandleOpacity( qreal opacity );
76     int handleLength();
77
78 private:
79     bool isSliding;        /* Whether we are currently sliding by user action */
80     bool isJumping;              /* if we requested a jump to another chapter */
81     int inputLength;                           /* InputLength that can change */
82     char psz_length[MSTRTIME_MAX_SIZE];               /* Used for the ToolTip */
83     QTimer *seekLimitTimer;
84     TimeTooltip *mTimeTooltip;
85     float f_buffering;
86     SeekPoints* chapters;
87     bool b_classic;
88     bool b_seekable;
89     int mHandleLength;
90
91     /* Colors & gradients */
92     QSize gradientsTargetSize;
93     QLinearGradient backgroundGradient;
94     QLinearGradient foregroundGradient;
95     QLinearGradient handleGradient;
96     QColor tickpointForeground;
97     QColor shadowDark;
98     QColor shadowLight;
99     /* Handle's animation */
100     qreal mHandleOpacity;
101     QPropertyAnimation *animHandle;
102     QTimer *hideHandleTimer;
103
104 public slots:
105     void setPosition( float, int64_t, int );
106     void setSeekable( bool b ) { b_seekable = b ; }
107     void updateBuffering( float );
108     void hideHandle();
109
110 private slots:
111     void startSeekTimer();
112     void updatePos();
113
114 signals:
115     void sliderDragged( float );
116
117
118     friend class SeekStyle;
119 };
120
121 /* Sound Slider inherited directly from QAbstractSlider */
122 class QPaintEvent;
123
124 class SoundSlider : public QAbstractSlider
125 {
126     Q_OBJECT
127 public:
128     SoundSlider( QWidget *_parent, int _i_step, char * );
129     void setMuted( bool ); /* Set Mute status */
130
131 protected:
132     const static int paddingL = 3;
133     const static int paddingR = 2;
134
135     virtual void paintEvent( QPaintEvent *);
136     virtual void wheelEvent( QWheelEvent *event );
137     virtual void mousePressEvent( QMouseEvent * );
138     virtual void mouseMoveEvent( QMouseEvent * );
139     virtual void mouseReleaseEvent( QMouseEvent * );
140
141 private:
142     bool isSliding; /* Whether we are currently sliding by user action */
143     bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */
144     int i_oldvalue; /* Store the old Value before changing */
145     float f_step; /* How much do we increase each time we wheel */
146     bool b_isMuted;
147
148     QPixmap pixGradient; /* Gradient pix storage */
149     QPixmap pixGradient2; /* Muted Gradient pix storage */
150     QPixmap pixOutside; /* OutLine pix storage */
151     QPainter painter;
152     QColor background;
153     QColor foreground;
154     QFont textfont;
155     QRect textrect;
156
157     void changeValue( int x ); /* Function to modify the value from pixel x() */
158 };
159
160 #endif