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