Commit 3a64ba7e authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: input slider and other widgets cleaning.

Code comments, remove useless include, document and rename a few variables.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent c142e6ec
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <vlc_vout.h> #include <vlc_vout.h>
#include <vlc_osd.h> #include <vlc_osd.h>
#include <vlc_charset.h> /* us_strtod */
#if 0 #if 0
class ConfClickHandler : public QObject class ConfClickHandler : public QObject
......
...@@ -62,7 +62,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -62,7 +62,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
layout->setSpacing( 0 ); layout->setMargin( 0 ); layout->setSpacing( 0 ); layout->setMargin( 0 );
/* Create and configure the QTreeView */ /* Create and configure the QTreeView */
view = new QVLCTreeView( 0 ); view = new QVLCTreeView;
view->header()->setSortIndicator( 0 , Qt::AscendingOrder ); view->header()->setSortIndicator( 0 , Qt::AscendingOrder );
view->setSortingEnabled( true ); view->setSortingEnabled( true );
view->setModel( model ); view->setModel( model );
......
...@@ -66,15 +66,13 @@ private: ...@@ -66,15 +66,13 @@ private:
#include <QPoint> #include <QPoint>
#include <QModelIndex> #include <QModelIndex>
/**
Special QTreeView that can emit rightClicked()
*/
class QVLCTreeView : public QTreeView class QVLCTreeView : public QTreeView
{ {
Q_OBJECT; Q_OBJECT;
public: public:
QVLCTreeView( QWidget * parent ) : QTreeView( parent )
{
};
virtual ~QVLCTreeView() {};
void mouseReleaseEvent( QMouseEvent* e ) void mouseReleaseEvent( QMouseEvent* e )
{ {
if( e->button() & Qt::RightButton ) if( e->button() & Qt::RightButton )
...@@ -94,15 +92,20 @@ public: ...@@ -94,15 +92,20 @@ public:
} }
QTreeView::mousePressEvent( e ); QTreeView::mousePressEvent( e );
} }
signals: signals:
void rightClicked( QModelIndex, QPoint ); void rightClicked( QModelIndex, QPoint );
}; };
/* VLC Key/Wheel hotkeys interactions */
class QKeyEvent; class QKeyEvent;
class QWheelEvent; class QWheelEvent;
int qtKeyModifiersToVLC( QInputEvent* e ); int qtKeyModifiersToVLC( QInputEvent* e );
int qtEventToVLCKey( QKeyEvent *e ); int qtEventToVLCKey( QKeyEvent *e );
int qtWheelEventToVLCKey( QWheelEvent *e ); int qtWheelEventToVLCKey( QWheelEvent *e );
QString VLCKeyToString( int val ); QString VLCKeyToString( int val );
#endif #endif
...@@ -31,17 +31,16 @@ ...@@ -31,17 +31,16 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QBitmap> #include <QBitmap>
#include <QStyle>
InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent ) InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent )
{ {
InputSlider::InputSlider( Qt::Horizontal, _parent ); InputSlider::InputSlider( Qt::Horizontal, _parent );
} }
InputSlider::InputSlider( Qt::Orientation q,QWidget *_parent ) : InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
QSlider( q, _parent ) QSlider( q, _parent )
{ {
b_sliding = false; b_isSliding = false;
setMinimum( 0 ); setMinimum( 0 );
setMouseTracking(true); setMouseTracking(true);
setMaximum( 1000 ); setMaximum( 1000 );
...@@ -61,14 +60,15 @@ void InputSlider::setPosition( float pos, int a, int b ) ...@@ -61,14 +60,15 @@ void InputSlider::setPosition( float pos, int a, int b )
else else
setEnabled( true ); setEnabled( true );
if( !b_sliding ) if( !b_isSliding )
setValue( (int)(pos * 1000.0 ) ); setValue( (int)(pos * 1000.0 ) );
inputLength = b; inputLength = b;
} }
void InputSlider::userDrag( int new_value ) void InputSlider::userDrag( int new_value )
{ {
if( b_sliding ) if( b_isSliding )
{ {
float f_pos = (float)(new_value)/1000.0; float f_pos = (float)(new_value)/1000.0;
emit sliderDragged( f_pos ); emit sliderDragged( f_pos );
...@@ -77,12 +77,12 @@ void InputSlider::userDrag( int new_value ) ...@@ -77,12 +77,12 @@ void InputSlider::userDrag( int new_value )
void InputSlider::mouseReleaseEvent( QMouseEvent *event ) void InputSlider::mouseReleaseEvent( QMouseEvent *event )
{ {
b_sliding = false; b_isSliding = false;
} }
void InputSlider::mousePressEvent(QMouseEvent* event) void InputSlider::mousePressEvent(QMouseEvent* event)
{ {
b_sliding = true ; b_isSliding = true ;
if( event->button() != Qt::LeftButton && if( event->button() != Qt::LeftButton &&
event->button() != Qt::MidButton ) event->button() != Qt::MidButton )
{ {
...@@ -99,7 +99,7 @@ void InputSlider::mousePressEvent(QMouseEvent* event) ...@@ -99,7 +99,7 @@ void InputSlider::mousePressEvent(QMouseEvent* event)
void InputSlider::mouseMoveEvent(QMouseEvent *event) void InputSlider::mouseMoveEvent(QMouseEvent *event)
{ {
if( b_sliding ) if( b_isSliding )
{ {
QSlider::mouseMoveEvent( event ); QSlider::mouseMoveEvent( event );
} }
...@@ -111,7 +111,7 @@ void InputSlider::mouseMoveEvent(QMouseEvent *event) ...@@ -111,7 +111,7 @@ void InputSlider::mouseMoveEvent(QMouseEvent *event)
void InputSlider::wheelEvent( QWheelEvent *event) void InputSlider::wheelEvent( QWheelEvent *event)
{ {
/* Don't do anything if we are for somehow reason sliding */ /* 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 setValue( value() + event->delta()/12 ); /* 12 = 8 * 15 / 10
Since delta is in 1/8 of ° and mouse have steps of 15 ° 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, ...@@ -140,8 +140,8 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ; f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX ); setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX );
setMouseTracking( true ); setMouseTracking( true );
b_sliding = false; b_isSliding = false;
b_outside = true; b_mouseOutside = true;
pixOutside = QPixmap( ":/volslide-outside" ); pixOutside = QPixmap( ":/volslide-outside" );
...@@ -191,7 +191,7 @@ void SoundSlider::mousePressEvent( QMouseEvent *event ) ...@@ -191,7 +191,7 @@ void SoundSlider::mousePressEvent( QMouseEvent *event )
if( event->button() != Qt::RightButton ) if( event->button() != Qt::RightButton )
{ {
/* We enter the sliding mode */ /* We enter the sliding mode */
b_sliding = true; b_isSliding = true;
i_oldvalue = value(); i_oldvalue = value();
emit sliderPressed(); emit sliderPressed();
changeValue( event->x() - paddingL ); changeValue( event->x() - paddingL );
...@@ -202,31 +202,31 @@ void SoundSlider::mouseReleaseEvent( QMouseEvent *event ) ...@@ -202,31 +202,31 @@ void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
{ {
if( event->button() != Qt::RightButton ) if( event->button() != Qt::RightButton )
{ {
if( !b_outside && value() != i_oldvalue ) if( !b_mouseOutside && value() != i_oldvalue )
{ {
emit sliderReleased(); emit sliderReleased();
setValue( value() ); setValue( value() );
} }
b_sliding = false; b_isSliding = false;
b_outside = false; b_mouseOutside = false;
} }
} }
void SoundSlider::mouseMoveEvent( QMouseEvent *event ) void SoundSlider::mouseMoveEvent( QMouseEvent *event )
{ {
if( b_sliding ) if( b_isSliding )
{ {
QRect rect( paddingL - 15, -1, QRect rect( paddingL - 15, -1,
WLENGTH + 15 * 2 , WHEIGHT + 5 ); WLENGTH + 15 * 2 , WHEIGHT + 5 );
if( !rect.contains( event->pos() ) ) if( !rect.contains( event->pos() ) )
{ /* We are outside */ { /* We are outside */
if ( !b_outside ) if ( !b_mouseOutside )
setValue( i_oldvalue ); setValue( i_oldvalue );
b_outside = true; b_mouseOutside = true;
} }
else else
{ /* We are inside */ { /* We are inside */
b_outside = false; b_mouseOutside = false;
changeValue( event->x() - paddingL ); changeValue( event->x() - paddingL );
emit sliderMoved( value() ); emit sliderMoved( value() );
} }
...@@ -244,7 +244,7 @@ void SoundSlider::changeValue( int x ) ...@@ -244,7 +244,7 @@ void SoundSlider::changeValue( int x )
setValue( (x * maximum() + 40 ) / WLENGTH ); setValue( (x * maximum() + 40 ) / WLENGTH );
} }
void SoundSlider::paintEvent(QPaintEvent *e) void SoundSlider::paintEvent( QPaintEvent *e )
{ {
QPainter painter( this ); QPainter painter( this );
const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL; const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
......
...@@ -39,28 +39,29 @@ class InputSlider : public QSlider ...@@ -39,28 +39,29 @@ class InputSlider : public QSlider
Q_OBJECT Q_OBJECT
public: public:
InputSlider( QWidget *_parent ); InputSlider( QWidget *_parent );
InputSlider( Qt::Orientation q,QWidget *_parent ); InputSlider( Qt::Orientation q, QWidget *_parent );
virtual ~InputSlider() {}; virtual ~InputSlider() {};
protected: protected:
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event);
virtual void wheelEvent(QWheelEvent *event); virtual void wheelEvent(QWheelEvent *event);
private: private:
bool b_sliding; bool b_isSliding; /* Whether we are currently sliding by user action */
int inputLength; int inputLength; /* InputLength that can change */
char psz_length[MSTRTIME_MAX_SIZE]; char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */
public slots: public slots:
void setPosition( float, int, int ); void setPosition( float, int, int );
private slots: private slots:
void userDrag( int ); void userDrag( int );
signals: signals:
void sliderDragged( float ); void sliderDragged( float );
}; };
/* Sound Slider inherited directly from QAbstractSlider */ /* Sound Slider inherited directly from QAbstractSlider */
class QPaintEvent; class QPaintEvent;
class SoundSlider : public QAbstractSlider class SoundSlider : public QAbstractSlider
...@@ -73,19 +74,23 @@ public: ...@@ -73,19 +74,23 @@ public:
protected: protected:
const static int paddingL = 3; const static int paddingL = 3;
const static int paddingR = 2; const static int paddingR = 2;
virtual void paintEvent(QPaintEvent *); virtual void paintEvent(QPaintEvent *);
virtual void wheelEvent( QWheelEvent *event ); virtual void wheelEvent( QWheelEvent *event );
virtual void mousePressEvent( QMouseEvent * ); virtual void mousePressEvent( QMouseEvent * );
virtual void mouseMoveEvent( QMouseEvent * ); virtual void mouseMoveEvent( QMouseEvent * );
virtual void mouseReleaseEvent( QMouseEvent * ); virtual void mouseReleaseEvent( QMouseEvent * );
private: private:
bool b_sliding; bool b_isSliding; /* Whether we are currently sliding by user action */
bool b_outside; bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */
int i_oldvalue; int i_oldvalue; /* Store the old Value before changing */
float f_step; float f_step; /* How much do we increase each time we wheel */
void changeValue( int x );
QPixmap pixGradient; QPixmap pixGradient; /* Gradient pix storage */
QPixmap pixOutside; QPixmap pixOutside; /* OutLine pix storage */
void changeValue( int x ); /* Function to modify the value from pixel x() */
}; };
#endif #endif
...@@ -36,8 +36,6 @@ ...@@ -36,8 +36,6 @@
#include <QSettings> #include <QSettings>
#include "qt4.hpp" #include "qt4.hpp"
#include <vlc_common.h>
#include <vlc_charset.h>
class QVLCTools class QVLCTools
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment