[vlc-devel] commit: Qt: input slider and other widgets cleaning. (Jean-Baptiste Kempf )

git version control git at videolan.org
Tue Dec 30 13:21:08 CET 2008


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Dec 25 17:55:06 2008 +0100| [3a64ba7eb65f426c5d2666a03f4ab3bc90272bbe] | committer: Jean-Baptiste Kempf 

Qt: input slider and other widgets cleaning.

Code comments, remove useless include, document and rename a few variables.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3a64ba7eb65f426c5d2666a03f4ab3bc90272bbe
---

 modules/gui/qt4/components/extended_panels.cpp     |    1 +
 .../gui/qt4/components/playlist/standardpanel.cpp  |    2 +-
 modules/gui/qt4/util/customwidgets.hpp             |   13 ++++--
 modules/gui/qt4/util/input_slider.cpp              |   40 ++++++++++----------
 modules/gui/qt4/util/input_slider.hpp              |   31 +++++++++------
 modules/gui/qt4/util/qvlcframe.hpp                 |    2 -
 6 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp
index 1aa6ead..a03747a 100644
--- a/modules/gui/qt4/components/extended_panels.cpp
+++ b/modules/gui/qt4/components/extended_panels.cpp
@@ -45,6 +45,7 @@
 #include <vlc_vout.h>
 #include <vlc_osd.h>
 
+#include <vlc_charset.h> /* us_strtod */
 
 #if 0
 class ConfClickHandler : public QObject
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 767169b..19215f9 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -62,7 +62,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     layout->setSpacing( 0 ); layout->setMargin( 0 );
 
     /* Create and configure the QTreeView */
-    view = new QVLCTreeView( 0 );
+    view = new QVLCTreeView;
     view->header()->setSortIndicator( 0 , Qt::AscendingOrder );
     view->setSortingEnabled( true );
     view->setModel( model );
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index 411c33a..4d6fff1 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -66,15 +66,13 @@ private:
 #include <QPoint>
 #include <QModelIndex>
 
+/**
+  Special QTreeView that can emit rightClicked()
+  */
 class QVLCTreeView : public QTreeView
 {
     Q_OBJECT;
 public:
-    QVLCTreeView( QWidget * parent ) : QTreeView( parent )
-    {
-    };
-    virtual ~QVLCTreeView()   {};
-
     void mouseReleaseEvent( QMouseEvent* e )
     {
         if( e->button() & Qt::RightButton )
@@ -94,15 +92,20 @@ public:
         }
         QTreeView::mousePressEvent( e );
     }
+
 signals:
     void rightClicked( QModelIndex, QPoint  );
 };
 
+/* VLC Key/Wheel hotkeys interactions */
+
 class QKeyEvent;
 class QWheelEvent;
+
 int qtKeyModifiersToVLC( QInputEvent* e );
 int qtEventToVLCKey( QKeyEvent *e );
 int qtWheelEventToVLCKey( QWheelEvent *e );
 QString VLCKeyToString( int val );
 
 #endif
+
diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp
index b9b26f6..c5e490c 100644
--- a/modules/gui/qt4/util/input_slider.cpp
+++ b/modules/gui/qt4/util/input_slider.cpp
@@ -31,17 +31,16 @@
 #include <QPaintEvent>
 #include <QPainter>
 #include <QBitmap>
-#include <QStyle>
 
 InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent )
 {
     InputSlider::InputSlider( Qt::Horizontal, _parent );
 }
 
-InputSlider::InputSlider( Qt::Orientation q,QWidget *_parent ) :
+InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
                                  QSlider( q, _parent )
 {
-    b_sliding = false;
+    b_isSliding = false;
     setMinimum( 0 );
     setMouseTracking(true);
     setMaximum( 1000 );
@@ -61,14 +60,15 @@ void InputSlider::setPosition( float pos, int a, int b )
     else
         setEnabled( true );
 
-    if( !b_sliding )
+    if( !b_isSliding )
         setValue( (int)(pos * 1000.0 ) );
+
     inputLength = b;
 }
 
 void InputSlider::userDrag( int new_value )
 {
-    if( b_sliding )
+    if( b_isSliding )
     {
         float f_pos = (float)(new_value)/1000.0;
         emit sliderDragged( f_pos );
@@ -77,12 +77,12 @@ void InputSlider::userDrag( int new_value )
 
 void InputSlider::mouseReleaseEvent( QMouseEvent *event )
 {
-    b_sliding = false;
+    b_isSliding = false;
 }
 
 void InputSlider::mousePressEvent(QMouseEvent* event)
 {
-    b_sliding = true ;
+    b_isSliding = true ;
     if( event->button() != Qt::LeftButton &&
         event->button() != Qt::MidButton )
     {
@@ -99,7 +99,7 @@ void InputSlider::mousePressEvent(QMouseEvent* event)
 
 void InputSlider::mouseMoveEvent(QMouseEvent *event)
 {
-    if( b_sliding )
+    if( b_isSliding )
     {
         QSlider::mouseMoveEvent( event );
     }
@@ -111,7 +111,7 @@ void InputSlider::mouseMoveEvent(QMouseEvent *event)
 void InputSlider::wheelEvent( QWheelEvent *event)
 {
     /* Don't do anything if we are for somehow reason sliding */
-    if( !b_sliding )
+    if( !b_isSliding )
     {
         setValue( value() + event->delta()/12 ); /* 12 = 8 * 15 / 10
          Since delta is in 1/8 of ° and mouse have steps of 15 °
@@ -140,8 +140,8 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
     f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
     setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX  );
     setMouseTracking( true );
-    b_sliding = false;
-    b_outside = true;
+    b_isSliding = false;
+    b_mouseOutside = true;
 
     pixOutside = QPixmap( ":/volslide-outside" );
 
@@ -191,7 +191,7 @@ void SoundSlider::mousePressEvent( QMouseEvent *event )
     if( event->button() != Qt::RightButton )
     {
         /* We enter the sliding mode */
-        b_sliding = true;
+        b_isSliding = true;
         i_oldvalue = value();
         emit sliderPressed();
         changeValue( event->x() - paddingL );
@@ -202,31 +202,31 @@ void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
 {
     if( event->button() != Qt::RightButton )
     {
-        if( !b_outside && value() != i_oldvalue )
+        if( !b_mouseOutside && value() != i_oldvalue )
         {
             emit sliderReleased();
             setValue( value() );
         }
-        b_sliding = false;
-        b_outside = false;
+        b_isSliding = false;
+        b_mouseOutside = false;
     }
 }
 
 void SoundSlider::mouseMoveEvent( QMouseEvent *event )
 {
-    if( b_sliding )
+    if( b_isSliding )
     {
         QRect rect( paddingL - 15,    -1,
                     WLENGTH + 15 * 2 , WHEIGHT + 5 );
         if( !rect.contains( event->pos() ) )
         { /* We are outside */
-            if ( !b_outside )
+            if ( !b_mouseOutside )
                 setValue( i_oldvalue );
-            b_outside = true;
+            b_mouseOutside = true;
         }
         else
         { /* We are inside */
-            b_outside = false;
+            b_mouseOutside = false;
             changeValue( event->x() - paddingL );
             emit sliderMoved( value() );
         }
@@ -244,7 +244,7 @@ void SoundSlider::changeValue( int x )
     setValue( (x * maximum() + 40 ) / WLENGTH );
 }
 
-void SoundSlider::paintEvent(QPaintEvent *e)
+void SoundSlider::paintEvent( QPaintEvent *e )
 {
     QPainter painter( this );
     const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
diff --git a/modules/gui/qt4/util/input_slider.hpp b/modules/gui/qt4/util/input_slider.hpp
index fa6214d..4ebf5fe 100644
--- a/modules/gui/qt4/util/input_slider.hpp
+++ b/modules/gui/qt4/util/input_slider.hpp
@@ -39,28 +39,29 @@ class InputSlider : public QSlider
     Q_OBJECT
 public:
     InputSlider( QWidget *_parent );
-    InputSlider( Qt::Orientation q,QWidget *_parent );
-    virtual ~InputSlider()   {};
+    InputSlider( Qt::Orientation q, QWidget *_parent );
+    virtual ~InputSlider() {};
 protected:
     virtual void mouseMoveEvent(QMouseEvent *event);
     virtual void mousePressEvent(QMouseEvent* event);
     virtual void mouseReleaseEvent(QMouseEvent* event);
     virtual void wheelEvent(QWheelEvent *event);
 private:
-    bool b_sliding;
-    int inputLength;
-    char psz_length[MSTRTIME_MAX_SIZE];
+    bool b_isSliding; /* Whether we are currently sliding by user action */
+    int inputLength;  /* InputLength that can change */
+    char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */
+
 public slots:
     void setPosition( float, int, int );
 private slots:
     void userDrag( int );
+
 signals:
     void sliderDragged( float );
 };
 
 
 /* Sound Slider inherited directly from QAbstractSlider */
-
 class QPaintEvent;
 
 class SoundSlider : public QAbstractSlider
@@ -73,19 +74,23 @@ public:
 protected:
     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 * );
+
 private:
-    bool b_sliding;
-    bool b_outside;
-    int i_oldvalue;
-    float f_step;
-    void changeValue( int x );
-    QPixmap pixGradient;
-    QPixmap pixOutside;
+    bool b_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 */
+
+    QPixmap pixGradient; /* Gradient pix storage */
+    QPixmap pixOutside; /* OutLine pix storage */
+
+    void changeValue( int x ); /* Function to modify the value from pixel x() */
 };
 
 #endif
diff --git a/modules/gui/qt4/util/qvlcframe.hpp b/modules/gui/qt4/util/qvlcframe.hpp
index b5f8e48..ddc271d 100644
--- a/modules/gui/qt4/util/qvlcframe.hpp
+++ b/modules/gui/qt4/util/qvlcframe.hpp
@@ -36,8 +36,6 @@
 #include <QSettings>
 
 #include "qt4.hpp"
-#include <vlc_common.h>
-#include <vlc_charset.h>
 
 class QVLCTools
 {




More information about the vlc-devel mailing list