X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Futil%2Finput_slider.cpp;h=260d62d71098bc741f2f60393c862e504aa69122;hb=6576b0b21a58a87207a5b7e72887659de3bd3fd1;hp=f05aced4ec0aad6853bc7c56b4a06b28989c6a0b;hpb=8b583911d65e77f365dd882816616c968864fa88;p=vlc diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp index f05aced4ec..260d62d710 100644 --- a/modules/gui/qt4/util/input_slider.cpp +++ b/modules/gui/qt4/util/input_slider.cpp @@ -20,8 +20,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include "qt4.hpp" #include "util/input_slider.hpp" #include @@ -29,21 +31,22 @@ #include #include -InputSlider::InputSlider( QWidget *_parent ) : DirectSlider( _parent ) +InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent ) { InputSlider::InputSlider( Qt::Horizontal, _parent ); } InputSlider::InputSlider( Qt::Orientation q,QWidget *_parent ) : - DirectSlider( q, _parent ) + QSlider( q, _parent ) { - mymove = false; + b_sliding = false; setMinimum( 0 ); setMouseTracking(true); setMaximum( 1000 ); setSingleStep( 2 ); setPageStep( 10 ); setTracking( true ); + secstotimestr( psz_length, 0 ); CONNECT( this, valueChanged(int), this, userDrag( int ) ); } @@ -53,28 +56,58 @@ void InputSlider::setPosition( float pos, int a, int b ) setEnabled( false ); else setEnabled( true ); - mymove = true; - setValue( (int)(pos * 1000.0 ) ); - mymove = false; + + if( !b_sliding ) + setValue( (int)(pos * 1000.0 ) ); inputLength = b; } void InputSlider::userDrag( int new_value ) { - float f_pos = (float)(new_value)/1000.0; - if( !mymove ) + if( b_sliding ) { + float f_pos = (float)(new_value)/1000.0; emit sliderDragged( f_pos ); } } +void InputSlider::mouseReleaseEvent( QMouseEvent *event ) +{ + b_sliding = false; +} + +void InputSlider::mousePressEvent(QMouseEvent* event) +{ + b_sliding = true ; + if( event->button() != Qt::LeftButton && + event->button() != Qt::MidButton ) + { + QSlider::mousePressEvent( event ); + return; + } + + QMouseEvent newEvent( event->type(), event->pos(), event->globalPos(), + Qt::MouseButton( event->button() ^ Qt::LeftButton ^ Qt::MidButton ), + Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ), + event->modifiers() ); + QSlider::mousePressEvent( &newEvent ); +} + void InputSlider::mouseMoveEvent(QMouseEvent *event) { - char psz_length[MSTRTIME_MAX_SIZE]; + if( b_sliding ) + { + QSlider::mouseMoveEvent( event ); + } + secstotimestr( psz_length, ( event->x() * inputLength) / size().width() ); setToolTip( psz_length ); } +/* This work is derived from Amarok's work under GPLv2+ + - Mark Kretschmann + - Gábor Lehel + */ #define WLENGTH 90 // px #define WHEIGHT 25 // px #define SOUNDMIN 0 // % @@ -188,6 +221,13 @@ void SoundSlider::paintEvent(QPaintEvent *e) const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() ); painter.drawPixmap( boundsO, pixOutside, boundsO ); + painter.setPen( palette().color( QPalette::Active, QPalette::Mid ) ); + QFont font; font.setPixelSize( 9 ); + painter.setFont( font ); + const QRect rect( 0, 0, 34, 15 ); + painter.drawText( rect, Qt::AlignRight | Qt::AlignVCenter, + QString::number( value() ) + '%' ); + painter.end(); }