]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/input_slider.hpp
Qt: SeekSlider: don't show buffering < 1s
[vlc] / modules / gui / qt4 / util / input_slider.hpp
index cc7c5d5368aae145f7c113389c0584bac61ecc1f..c8e48feacf7b7957845a0aef503067459c11931e 100644 (file)
@@ -1,10 +1,12 @@
 /*****************************************************************************
- * input_slider.hpp : A slider that controls an input
+ * input_slider.hpp : VolumeSlider and SeekSlider
  ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2011 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
+ *          Jean-Baptiste Kempf <jb@videolan.org>
+ *          Ludovic Fauvet <etix@videolan.org>
  *
  * 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
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifndef _INPUTSLIDER_H_
 #define _INPUTSLIDER_H_
 
-#include "util/directslider.hpp"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include "timetooltip.hpp"
+#include "styles/seekstyle.hpp"
+
+#include <QSlider>
+#include <QPainter>
+#include <QTime>
+
+#define MSTRTIME_MAX_SIZE 22
 
-class InputSlider : public DirectSlider
+class QMouseEvent;
+class QWheelEvent;
+class QHideEvent;
+class QTimer;
+class SeekPoints;
+class QPropertyAnimation;
+class QStyleOption;
+class QCommonStyle;
+
+/* Input Slider derived from QSlider */
+class SeekSlider : public QSlider
 {
     Q_OBJECT
+    Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
 public:
-    InputSlider( QWidget *_parent );
-    InputSlider( Qt::Orientation q,QWidget *_parent );
-    virtual ~InputSlider()   {};
+    SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false );
+    ~SeekSlider();
+    void setChapters( SeekPoints * );
+
 protected:
-    void mouseMoveEvent(QMouseEvent *event);
+    virtual void mouseMoveEvent( QMouseEvent *event );
+    virtual void mousePressEvent( QMouseEvent* event );
+    virtual void mouseReleaseEvent( QMouseEvent *event );
+    virtual void wheelEvent( QWheelEvent *event );
+    virtual void enterEvent( QEvent * );
+    virtual void leaveEvent( QEvent * );
+    virtual void hideEvent( QHideEvent * );
+    virtual void paintEvent(QPaintEvent *ev);
+
+    virtual bool eventFilter( QObject *obj, QEvent *event );
+
+    virtual QSize sizeHint() const;
+
+    void processReleasedButton();
+    qreal handleOpacity() const;
+    void setHandleOpacity( qreal opacity );
+    int handleLength();
+
 private:
-    bool mymove;
-    int inputLength;
+    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 */
+    QTimer *seekLimitTimer;
+    TimeTooltip *mTimeTooltip;
+    float f_buffering;
+    QTime bufferingStart;
+    SeekPoints* chapters;
+    bool b_classic;
+    bool b_seekable;
+    int mHandleLength;
+
+    /* Colors & gradients */
+    QSize gradientsTargetSize;
+    QLinearGradient backgroundGradient;
+    QLinearGradient foregroundGradient;
+    QLinearGradient handleGradient;
+    QColor tickpointForeground;
+    QColor shadowDark;
+    QColor shadowLight;
+    QCommonStyle *alternativeStyle;
+
+    /* Handle's animation */
+    qreal mHandleOpacity;
+    QPropertyAnimation *animHandle;
+    QTimer *hideHandleTimer;
+
 public slots:
-    void setPosition( float, int, int );
+    void setPosition( float, int64_t, int );
+    void setSeekable( bool b ) { b_seekable = b ; }
+    void updateBuffering( float );
+    void hideHandle();
+
 private slots:
-    void userDrag( int );
+    void startSeekTimer();
+    void updatePos();
+
 signals:
     void sliderDragged( float );
-};
 
+};
 
+/* Sound Slider inherited directly from QAbstractSlider */
 class QPaintEvent;
-#include <QAbstractSlider>
+
+#define SOUNDMAX  125 // % (+6dB)
 
 class SoundSlider : public QAbstractSlider
 {
     Q_OBJECT
 public:
-    SoundSlider( QWidget *_parent, bool b_softamp );
-    virtual ~SoundSlider() {};
+    SoundSlider(QWidget *_parent, float _i_step, char *psz_colors, int max = SOUNDMAX );
+    void setMuted( bool ); /* Set Mute status */
+
 protected:
-    int padding;
-    virtual void paintEvent(QPaintEvent *);
+    const static int paddingL = 3;
+    const static int paddingR = 2;
+
+    virtual void paintEvent( QPaintEvent *);
     virtual void wheelEvent( QWheelEvent *event );
     virtual void mousePressEvent( QMouseEvent * );
     virtual void mouseMoveEvent( QMouseEvent * );
     virtual void mouseReleaseEvent( QMouseEvent * );
+
+    void processReleasedButton();
+
 private:
-    bool b_sliding;
-    bool b_outside;
-    int i_oldvalue;
-    void changeValue( int x );
-    QPixmap pixGradient;
-    QPixmap pixLimit;
+    bool isSliding; /* Whether we are currently sliding by user action */
+    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 */
+    bool b_isMuted;
+
+    QPixmap pixGradient; /* Gradient pix storage */
+    QPixmap pixGradient2; /* Muted Gradient pix storage */
+    QPixmap pixOutside; /* OutLine pix storage */
+    QPainter painter;
+    QColor background;
+    QColor foreground;
+    QFont textfont;
+    QRect textrect;
+
+    void changeValue( int x ); /* Function to modify the value from pixel x() */
 };
 
 #endif