input_slider.hpp 5.5 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1
/*****************************************************************************
2
 * input_slider.hpp : VolumeSlider and SeekSlider
Clément Stenac's avatar
Clément Stenac committed
3
 ****************************************************************************
4
 * Copyright (C) 2006-2011 the VideoLAN team
5
 * $Id$
Clément Stenac's avatar
Clément Stenac committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Ludovic Fauvet <etix@videolan.org>
Clément Stenac's avatar
Clément Stenac committed
10 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
22 23
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24
 *****************************************************************************/
Clément Stenac's avatar
Clément Stenac committed
25

26 27
#ifndef VLC_QT_INPUT_SLIDER_HPP_
#define VLC_QT_INPUT_SLIDER_HPP_
Clément Stenac's avatar
Clément Stenac committed
28

Rafaël Carré's avatar
Rafaël Carré committed
29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include "styles/seekstyle.hpp"
34

35
#include <QSlider>
36
#include <QPainter>
37
#include <QTime>
38

39 40 41 42
#define MSTRTIME_MAX_SIZE 22

class QMouseEvent;
class QWheelEvent;
43
class QHideEvent;
44
class QTimer;
45
class SeekPoints;
46
class QPropertyAnimation;
47
class QCommonStyle;
48
class TimeTooltip;
49
class QSequentialAnimationGroup;
Clément Stenac's avatar
Clément Stenac committed
50

51
/* Input Slider derived from QSlider */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52
class SeekSlider : public QSlider
Clément Stenac's avatar
Clément Stenac committed
53 54
{
    Q_OBJECT
55
    Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
56
    Q_PROPERTY(qreal loadingProperty READ loading WRITE setLoading)
Clément Stenac's avatar
Clément Stenac committed
57
public:
58
    SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false );
59
    virtual ~SeekSlider();
60
    void setChapters( SeekPoints * );
61

62
protected:
63 64 65 66 67 68 69 70
    void mouseMoveEvent( QMouseEvent *event ) Q_DECL_OVERRIDE;
    void mousePressEvent( QMouseEvent* event ) Q_DECL_OVERRIDE;
    void mouseReleaseEvent( QMouseEvent *event ) Q_DECL_OVERRIDE;
    void wheelEvent( QWheelEvent *event ) Q_DECL_OVERRIDE;
    void enterEvent( QEvent * ) Q_DECL_OVERRIDE;
    void leaveEvent( QEvent * ) Q_DECL_OVERRIDE;
    void hideEvent( QHideEvent * ) Q_DECL_OVERRIDE;
    void paintEvent(QPaintEvent *ev) Q_DECL_OVERRIDE;
71

72
    bool eventFilter( QObject *obj, QEvent *event ) Q_DECL_OVERRIDE;
73

74
    QSize sizeHint() const Q_DECL_OVERRIDE;
75

76
    void processReleasedButton();
77
    qreal handleOpacity() const;
78
    qreal loading() const;
79
    void setHandleOpacity( qreal opacity );
80
    void setLoading( qreal loading );
81
    int handleLength();
82

83
private:
84 85 86 87
    bool isSliding;        /* Whether we are currently sliding by user action */
    bool isJumping;              /* if we requested a jump to another chapter */
    int inputLength;                           /* InputLength that can change */
    char psz_length[MSTRTIME_MAX_SIZE];               /* Used for the ToolTip */
88
    QTimer *seekLimitTimer;
89
    TimeTooltip *mTimeTooltip;
90
    float f_buffering;
91
    QTime bufferingStart;
92
    SeekPoints* chapters;
93
    bool b_classic;
94
    bool b_seekable;
95
    int mHandleLength;
96

97 98 99 100 101 102 103 104
    /* Colors & gradients */
    QSize gradientsTargetSize;
    QLinearGradient backgroundGradient;
    QLinearGradient foregroundGradient;
    QLinearGradient handleGradient;
    QColor tickpointForeground;
    QColor shadowDark;
    QColor shadowLight;
105 106
    QCommonStyle *alternativeStyle;

107 108
    /* Handle's animation */
    qreal mHandleOpacity;
109
    qreal mLoading;
110
    QPropertyAnimation *animHandle;
111
    QSequentialAnimationGroup *animLoading;
112
    QTimer *hideHandleTimer;
113
    QTimer *startAnimLoadingTimer;
114

Clément Stenac's avatar
Clément Stenac committed
115
public slots:
116
    void setPosition( float, int64_t, int );
117
    void setSeekable( bool b ) { b_seekable = b ; }
118
    void updateBuffering( float );
119
    void hideHandle();
120

Clément Stenac's avatar
Clément Stenac committed
121
private slots:
122
    void startSeekTimer();
123
    void updatePos();
124
    void inputUpdated( bool );
125
    void startAnimLoading();
126

Clément Stenac's avatar
Clément Stenac committed
127
signals:
128
    void sliderDragged( float );
129

130 131
};

132
/* Sound Slider inherited directly from QAbstractSlider */
133 134
class QPaintEvent;

135 136
#define SOUNDMAX  125 // % (+6dB)

137 138 139 140
class SoundSlider : public QAbstractSlider
{
    Q_OBJECT
public:
141
    SoundSlider(QWidget *_parent, float _i_step, char *psz_colors, int max = SOUNDMAX );
142
    void setMuted( bool ); /* Set Mute status */
143

144
protected:
145
    const static int paddingL = 3;
146
    const static int paddingR = 2;
147

148 149 150 151 152
    void paintEvent( QPaintEvent *) Q_DECL_OVERRIDE;
    void wheelEvent( QWheelEvent *event ) Q_DECL_OVERRIDE;
    void mousePressEvent( QMouseEvent * ) Q_DECL_OVERRIDE;
    void mouseMoveEvent( QMouseEvent * ) Q_DECL_OVERRIDE;
    void mouseReleaseEvent( QMouseEvent * ) Q_DECL_OVERRIDE;
153

154 155
    void processReleasedButton();

156
private:
157
    bool isSliding; /* Whether we are currently sliding by user action */
158 159 160
    bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */
    int i_oldvalue; /* Store the old Value before changing */
    float f_step; /* How much do we increase each time we wheel */
161
    bool b_isMuted;
162 163
    int wlength;
    int wheight;
164 165

    QPixmap pixGradient; /* Gradient pix storage */
166
    QPixmap pixGradient2; /* Muted Gradient pix storage */
167
    QPixmap pixOutside; /* OutLine pix storage */
168 169 170 171 172
    QPainter painter;
    QColor background;
    QColor foreground;
    QFont textfont;
    QRect textrect;
173 174

    void changeValue( int x ); /* Function to modify the value from pixel x() */
175 176
};

Clément Stenac's avatar
Clément Stenac committed
177
#endif