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 @@
#include <vlc_vout.h>
#include <vlc_osd.h>
#include <vlc_charset.h> /* us_strtod */
#if 0
class ConfClickHandler : public QObject
......
......@@ -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 );
......
......@@ -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
......@@ -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;
......
......@@ -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
......@@ -36,8 +36,6 @@
#include <QSettings>
#include "qt4.hpp"
#include <vlc_common.h>
#include <vlc_charset.h>
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