#include <QPaintEvent>
#include <QPainter>
#include <QBitmap>
-#include <QPainter>
#include <QStyleOptionSlider>
#include <QLinearGradient>
#include <QTimer>
f_buffering = 1.0;
mHandleOpacity = 1.0;
chapters = NULL;
+ mHandleLength = -1;
+
+ // prepare some static colors
+ QPalette p = palette();
+ QColor background = p.color( QPalette::Active, QPalette::Background );
+ tickpointForeground = p.color( QPalette::Active, QPalette::WindowText );
+ tickpointForeground.setHsv( tickpointForeground.hue(),
+ ( background.saturation() + tickpointForeground.saturation() ) / 2,
+ ( background.value() + tickpointForeground.value() ) / 2 );
+
+ // set the background color and gradient
+ QColor backgroundBase( p.window().color() );
+ backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) );
+ backgroundGradient.setColorAt( 1.0, backgroundBase );
+
+ // set the foreground color and gradient
+ QColor foregroundBase( 50, 156, 255 );
+ foregroundGradient.setColorAt( 0.0, foregroundBase );
+ foregroundGradient.setColorAt( 1.0, foregroundBase.darker( 140 ) );
+
+ // prepare the handle's gradient
+ handleGradient.setColorAt( 0.0, p.window().color().lighter( 120 ) );
+ handleGradient.setColorAt( 0.9, p.window().color().darker( 120 ) );
+
+ // prepare the handle's shadow gradient
+ QColor shadowBase = p.shadow().color();
+ if( shadowBase.lightness() > 100 )
+ shadowBase = QColor( 60, 60, 60 ); // Palette's shadow is too bright
+ shadowDark = shadowBase.darker( 150 );
+ shadowLight = shadowBase.lighter( 180 );
+ shadowLight.setAlpha( 50 );
/* Timer used to fire intermediate updatePos() when sliding */
seekLimitTimer = new QTimer( this );
setTracking( true );
setFocusPolicy( Qt::NoFocus );
+ /* Use the new/classic style */
+ if( !b_classic )
+ setStyle( new SeekStyle );
+
/* Init to 0 */
setPosition( -1.0, 0, 0 );
secstotimestr( psz_length, 0 );
if( pos == -1.0 )
{
setEnabled( false );
+ mTimeTooltip->hide();
isSliding = false;
}
else
}
isSliding = true ;
- setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false ) );
+
+ setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x() - handleLength() / 2, width() - handleLength(), false ) );
emit sliderMoved( value() );
event->accept();
}
{
if( isSliding )
{
- setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false) );
+ setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x() - handleLength() / 2, width() - handleLength(), false) );
emit sliderMoved( value() );
}
/* Tooltip */
if ( inputLength > 0 )
{
- int posX = qMax( rect().left(), qMin( rect().right(), event->x() ) );
+ int margin = handleLength() / 2;
+ int posX = qMax( rect().left() + margin, qMin( rect().right() - margin, event->x() ) );
QString chapterLabel;
QPoint target( event->globalX() - ( event->x() - posX ),
QWidget::mapToGlobal( pos() ).y() );
- secstotimestr( psz_length, ( posX * inputLength ) / size().width() );
+ secstotimestr( psz_length, ( ( posX - margin ) * inputLength ) / ( size().width() - handleLength() ) );
mTimeTooltip->setTip( target, psz_length, chapterLabel );
}
event->accept();
QSize SeekSlider::sizeHint() const
{
+ if ( b_classic )
+ return QSlider::sizeHint();
return ( orientation() == Qt::Horizontal ) ? QSize( 100, 18 )
: QSize( 18, 100 );
}
-QSize SeekSlider::handleSize() const
-{
- const int size = ( orientation() == Qt::Horizontal ? height() : width() );
- return QSize( size, size );
-}
-
-void SeekSlider::paintEvent( QPaintEvent *event )
-{
- if( b_classic )
- return QSlider::paintEvent( event );
-
- QStyleOptionSlider option;
- initStyleOption( &option );
-
- /* */
- QPainter painter( this );
- painter.setRenderHints( QPainter::Antialiasing );
-
- // draw bar
- const int barCorner = 3;
- qreal sliderPos = -1;
- int range = MAXIMUM;
- QRect barRect = rect();
-
- // adjust positions based on the current orientation
- if ( option.sliderPosition != 0 )
- {
- switch ( orientation() )
- {
- case Qt::Horizontal:
- sliderPos = ( ( (qreal)width() ) / (qreal)range )
- * (qreal)option.sliderPosition;
- break;
- case Qt::Vertical:
- sliderPos = ( ( (qreal)height() ) / (qreal)range )
- * (qreal)option.sliderPosition;
- break;
- }
- }
-
- switch ( orientation() )
- {
- case Qt::Horizontal:
- barRect.setHeight( height() /2 );
- break;
- case Qt::Vertical:
- barRect.setWidth( width() /2 );
- break;
- }
-
- barRect.moveCenter( rect().center() );
-
- // set the background color and gradient
- QColor backgroundBase( palette().window().color() );
- QLinearGradient backgroundGradient( 0, 0, 0, height() );
- backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) );
- backgroundGradient.setColorAt( 1.0, backgroundBase );
-
- // set the foreground color and gradient
- QColor foregroundBase( 50, 156, 255 );
- QLinearGradient foregroundGradient( 0, 0, 0, height() );
- foregroundGradient.setColorAt( 0.0, foregroundBase );
- foregroundGradient.setColorAt( 1.0, foregroundBase.darker( 140 ) );
-
- // draw a slight 3d effect on the bottom
- painter.setPen( QColor( 230, 230, 230 ) );
- painter.setBrush( Qt::NoBrush );
- painter.drawRoundedRect( barRect.adjusted( 0, 2, 0, 0 ), barCorner, barCorner );
-
- // draw background
- painter.setPen( Qt::NoPen );
- painter.setBrush( backgroundGradient );
- painter.drawRoundedRect( barRect, barCorner, barCorner );
-
- // adjusted foreground rectangle
- QRect valueRect = barRect.adjusted( 1, 1, -1, 0 );
-
- switch ( orientation() )
- {
- case Qt::Horizontal:
- valueRect.setWidth( qMin( width(), int( sliderPos ) ) );
- break;
- case Qt::Vertical:
- valueRect.setHeight( qMin( height(), int( sliderPos ) ) );
- valueRect.moveBottom( rect().bottom() );
- break;
- }
-
- if ( option.sliderPosition > minimum() && option.sliderPosition <= maximum() )
- {
- // draw foreground
- painter.setPen( Qt::NoPen );
- painter.setBrush( foregroundGradient );
- painter.drawRoundedRect( valueRect, barCorner, barCorner );
- }
-
- // draw buffering overlay
- if ( f_buffering < 1.0 )
- {
- QRect innerRect = barRect.adjusted( 1, 1,
- barRect.width() * ( -1.0 + f_buffering ) - 1, 0 );
- QColor overlayColor = QColor( "Orange" );
- overlayColor.setAlpha( 128 );
- painter.setBrush( overlayColor );
- painter.drawRoundedRect( innerRect, barCorner, barCorner );
- }
-
- if ( option.state & QStyle::State_MouseOver || isAnimationRunning() )
- {
- /* draw chapters tickpoints */
- if ( chapters && inputLength && size().width() )
- {
- QColor background = palette().color( QPalette::Active, QPalette::Background );
- QColor foreground = palette().color( QPalette::Active, QPalette::WindowText );
- foreground.setHsv( foreground.hue(),
- ( background.saturation() + foreground.saturation() ) / 2,
- ( background.value() + foreground.value() ) / 2 );
- if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
- {
- QList<SeekPoint> points = chapters->getPoints();
- foreach( SeekPoint point, points )
- {
- int x = point.time / 1000000.0 / inputLength * size().width();
- painter.setPen( foreground );
- painter.setBrush( Qt::NoBrush );
- painter.drawLine( x, height(), x, height() - CHAPTERSSPOTSIZE );
- }
- }
- }
-
- // draw handle
- if ( sliderPos != -1 )
- {
- const int margin = 0;
- QSize hSize = handleSize() - QSize( 6, 6 );
- QPoint pos;
-
- switch ( orientation() )
- {
- case Qt::Horizontal:
- pos = QPoint( sliderPos - ( hSize.width() / 2 ), 2 );
- pos.rx() = qMax( margin, pos.x() );
- pos.rx() = qMin( width() - hSize.width() - margin, pos.x() );
- break;
- case Qt::Vertical:
- pos = QPoint( 2, height() - ( sliderPos + ( hSize.height() / 2 ) ) );
- pos.ry() = qMax( margin, pos.y() );
- pos.ry() = qMin( height() - hSize.height() - margin, pos.y() );
- break;
- }
-
- QPalette p;
- QPoint shadowPos( pos - QPoint( 2, 2 ) );
- QSize sSize( handleSize() - QSize( 2, 2 ) );
-
- // prepare the handle's gradient
- QLinearGradient handleGradient( 0, 0, 0, hSize.height() );
- handleGradient.setColorAt( 0.0, p.window().color().lighter( 120 ) );
- handleGradient.setColorAt( 0.9, p.window().color().darker( 120 ) );
-
- // prepare the handle's shadow gradient
- QColor shadowBase = p.shadow().color();
- if( shadowBase.lightness() > 100 )
- shadowBase = QColor( 60, 60, 60 ); // Palette's shadow is too bright
- QColor shadowDark( shadowBase.darker( 150 ) );
- QColor shadowLight( shadowBase.lighter( 180 ) );
- shadowLight.setAlpha( 50 );
-
- QRadialGradient shadowGradient( shadowPos.x() + ( sSize.width() / 2 ),
- shadowPos.y() + ( sSize.height() / 2 ),
- qMax( sSize.width(), sSize.height() ) / 2 );
- shadowGradient.setColorAt( 0.4, shadowDark );
- shadowGradient.setColorAt( 1.0, shadowLight );
-
- painter.setPen( Qt::NoPen );
- painter.setOpacity( mHandleOpacity );
-
- // draw the handle's shadow
- painter.setBrush( shadowGradient );
- painter.drawEllipse( shadowPos.x(), shadowPos.y() + 1, sSize.width(), sSize.height() );
-
- // finally draw the handle
- painter.setBrush( handleGradient );
- painter.drawEllipse( pos.x(), pos.y(), hSize.width(), hSize.height() );
- }
- }
-}
-
qreal SeekSlider::handleOpacity() const
{
return mHandleOpacity;
update();
}
+inline int SeekSlider::handleLength()
+{
+ if ( mHandleLength > 0 )
+ return mHandleLength;
+
+ /* Ask for the length of the handle to the underlying style */
+ QStyleOptionSlider option;
+ initStyleOption( &option );
+ mHandleLength = style()->pixelMetric( QStyle::PM_SliderLength, &option );
+ return mHandleLength;
+}
+
void SeekSlider::hideHandle()
{
/* If pause is called while not running Qt will complain */
|| hideHandleTimer->isActive();
}
+
/* This work is derived from Amarok's work under GPLv2+
- Mark Kretschmann
- Gábor Lehel
add_color( gradient1, range, c1, c2, c3 ); \
add_desaturated_color( gradient2, range, c1, c2, c3 );
+ float f_mid_point = ( 100.0 / maximum() );
QColor * foo;
add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
- add_colors( gradient, gradient2, 0.45, 3, 4, 5 );
- add_colors( gradient, gradient2, 0.55, 6, 7, 8 );
+ add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
+ add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
add_colors( gradient, gradient2, 1.0, 9, 10, 11 );
painter.begin( &pixGradient );