diff options
author | Michele Calgaro <[email protected]> | 2020-06-13 22:45:28 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-06-13 22:45:28 +0900 |
commit | 5f44f7b187093ef290315b7f8766b540a31de35f (patch) | |
tree | 27ffb7b218199ca04f240c390c52426c65f45dce /src/app/slider.cpp | |
download | codeine-5f44f7b187093ef290315b7f8766b540a31de35f.tar.gz codeine-5f44f7b187093ef290315b7f8766b540a31de35f.zip |
Initial code import from debian snapshot
https://snapshot.debian.org/package/codeine/1.0.1-3.dfsg-3.1/
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/app/slider.cpp')
-rw-r--r-- | src/app/slider.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/app/slider.cpp b/src/app/slider.cpp new file mode 100644 index 0000000..89b5ced --- /dev/null +++ b/src/app/slider.cpp @@ -0,0 +1,145 @@ +// (c) 2004 Max Howell ([email protected]) +// See COPYING file for licensing information + +#include "debug.h" +#include "slider.h" +#include <qapplication.h> +#include <qlabel.h> +#include <qsize.h> +#include <qtooltip.h> + +#include <qpainter.h> +#include "xineEngine.h" + +using Codeine::Slider; + + +Slider *Slider::s_instance = 0; + + +Slider::Slider( QWidget *parent, uint max ) + : QSlider( Qt::Horizontal, parent ) + , m_sliding( false ) + , m_outside( false ) + , m_prevValue( 0 ) +{ + s_instance = this; + + setRange( 0, max ); + setFocusPolicy( NoFocus ); + setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); +} + +void +Slider::wheelEvent( QWheelEvent *e ) +{ + //if you use this class elsewhere, NOTE this is Codeine specific + e->ignore(); //pass to VideoWindow +} + +void +Slider::mouseMoveEvent( QMouseEvent *e ) +{ + if( m_sliding ) + { + //feels better, but using set value of 20 is bad of course + QRect rect = this->rect(); + rect.addCoords( -20, -20, 20, 20 ); + + if( !rect.contains( e->pos() ) ) { + if( !m_outside ) + QSlider::setValue( m_prevValue ); + m_outside = true; + } else { + m_outside = false; + + QSlider::setValue( + QRangeControl::valueFromPosition( + e->pos().x() - sliderRect().width()/2, + width() - sliderRect().width() ) ); + + emit sliderMoved( value() ); + } + } + else + QSlider::mouseMoveEvent( e ); +} + +void +Slider::mousePressEvent( QMouseEvent *e ) +{ + m_sliding = true; + m_prevValue = QSlider::value(); + + if( !sliderRect().contains( e->pos() ) ) + mouseMoveEvent( e ); +} + +void +Slider::mouseReleaseEvent( QMouseEvent* ) +{ + if( !m_outside && QSlider::value() != m_prevValue ) + emit sliderReleased( value() ); + + m_sliding = false; + m_outside = false; +} + +static inline QString timeAsString( const int s ) +{ + #define zeroPad( n ) n < 10 ? QString("0%1").arg( n ) : QString::number( n ) + using Codeine::engine; + + const int m = s / 60; + const int h = m / 60; + + QString time; + time.prepend( zeroPad( s % 60 ) ); //seconds + time.prepend( ':' ); + time.prepend( zeroPad( m % 60 ) ); //minutes + time.prepend( ':' ); + time.prepend( QString::number( h ) ); //hours + + return time; +} + +void +Slider::setValue( int newValue ) +{ + static QLabel *w1 = 0; + static QLabel *w2 = 0; + + if (!w1) { + w1 = new QLabel( this ); + w1->setPalette( QToolTip::palette() ); + w1->setFrameStyle( QFrame::Plain | QFrame::Box ); + + w2 = new QLabel( this ); + w2->setPalette( QToolTip::palette() ); + w2->setFrameStyle( QFrame::Plain | QFrame::Box ); + } + + //TODO stupidly inefficeint! :) + w1->setShown( mainWindow()->isFullScreen() ); + w2->setShown( mainWindow()->isFullScreen() ); + + + //don't adjust the slider while the user is dragging it! + + if( !m_sliding || m_outside ) { + const int l = engine()->length() / 1000; + const int left = int(l * (newValue / 65535.0)); + const int right = l - left; + + QSlider::setValue( newValue ); + w1->move( 0, height() - w1->height() - 1 ); + w1->setText( timeAsString( left ) + ' ' ); + w1->adjustSize(); + + w2->move( width() - w2->width(), height() - w1->height() - 1 ); + w2->setText( timeAsString( right ) + ' ' ); + w2->adjustSize(); + } + else + m_prevValue = newValue; +} |