Commit 6ea38362 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: seekstyle: pass parameters through options.

parent 2893fcef
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
#define RADIUS 3 #define RADIUS 3
#define CHAPTERSSPOTSIZE 3 #define CHAPTERSSPOTSIZE 3
SeekStyle::SeekStyleOption::SeekStyleOption()
: QStyleOptionSlider(), buffering( 1.0 ), length(0), animate(false), animationopacity( 1.0 )
{
}
SeekStyle::SeekStyle() : QProxyStyle( QStyleFactory::create( QLatin1String("Windows") ) ) SeekStyle::SeekStyle() : QProxyStyle( QStyleFactory::create( QLatin1String("Windows") ) )
{ {
...@@ -54,14 +60,14 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -54,14 +60,14 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
{ {
painter->setRenderHints( QPainter::Antialiasing ); painter->setRenderHints( QPainter::Antialiasing );
if ( const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>( option ) ) if ( const SeekStyle::SeekStyleOption *slideroptions =
qstyleoption_cast<const SeekStyle::SeekStyleOption *>( option ) )
{ {
const SeekSlider *seekSlider = qobject_cast<const SeekSlider*>( widget );
qreal sliderPos = -1; qreal sliderPos = -1;
/* Get the needed subcontrols to draw the slider */ /* Get the needed subcontrols to draw the slider */
QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); QRect groove = subControlRect(CC_Slider, slideroptions, SC_SliderGroove, widget);
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); QRect handle = subControlRect(CC_Slider, slideroptions, SC_SliderHandle, widget);
/* Adjust the size of the groove so the handle stays centered */ /* Adjust the size of the groove so the handle stays centered */
groove.adjust( handle.width() / 2, 0, -handle.width() / 2, 0 ); groove.adjust( handle.width() / 2, 0, -handle.width() / 2, 0 );
...@@ -72,14 +78,14 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -72,14 +78,14 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
// had to remove 1 from the rect bottom. // had to remove 1 from the rect bottom.
groove.adjust( 0, (qreal)groove.height() / 3.7, 0, (qreal)-groove.height() / 3.7 - 1 ); groove.adjust( 0, (qreal)groove.height() / 3.7, 0, (qreal)-groove.height() / 3.7 - 1 );
if ( ( slider->subControls & SC_SliderGroove ) && groove.isValid() ) if ( ( slideroptions->subControls & SC_SliderGroove ) && groove.isValid() )
{ {
sliderPos = ( ( (qreal)groove.width() ) / (qreal)slider->maximum ) sliderPos = ( ( (qreal)groove.width() ) / (qreal)slideroptions->maximum )
* (qreal)slider->sliderPosition; * (qreal)slideroptions->sliderPosition;
/* set the background color and gradient */ /* set the background color and gradient */
QColor backgroundBase( slider->palette.window().color() ); QColor backgroundBase( slideroptions->palette.window().color() );
QLinearGradient backgroundGradient( 0, 0, 0, slider->rect.height() ); QLinearGradient backgroundGradient( 0, 0, 0, slideroptions->rect.height() );
backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) ); backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) );
backgroundGradient.setColorAt( 1.0, backgroundBase ); backgroundGradient.setColorAt( 1.0, backgroundBase );
...@@ -105,7 +111,7 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -105,7 +111,7 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
valueRect.setWidth( sliderPos ); valueRect.setWidth( sliderPos );
/* draw foreground */ /* draw foreground */
if ( slider->sliderPosition > slider->minimum && slider->sliderPosition <= slider->maximum ) if ( slideroptions->sliderPosition > slideroptions->minimum && slideroptions->sliderPosition <= slideroptions->maximum )
{ {
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
painter->setBrush( foregroundGradient ); painter->setBrush( foregroundGradient );
...@@ -113,10 +119,10 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -113,10 +119,10 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
} }
/* draw buffering overlay */ /* draw buffering overlay */
if ( seekSlider && seekSlider->f_buffering < 1.0 ) if ( slideroptions->buffering < 1.0 )
{ {
QRect innerRect = groove.adjusted( 1, 1, QRect innerRect = groove.adjusted( 1, 1,
groove.width() * ( -1.0 + seekSlider->f_buffering ) - 1, 0 ); groove.width() * ( -1.0 + slideroptions->buffering ) - 1, 0 );
QColor overlayColor = QColor( "Orange" ); QColor overlayColor = QColor( "Orange" );
overlayColor.setAlpha( 128 ); overlayColor.setAlpha( 128 );
painter->setBrush( overlayColor ); painter->setBrush( overlayColor );
...@@ -124,39 +130,38 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -124,39 +130,38 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
} }
} }
if ( slider->subControls & SC_SliderTickmarks ) { if ( slideroptions->subControls & SC_SliderTickmarks ) {
QStyleOptionSlider tmpSlider = *slider; QStyleOptionSlider tmpSlider = *slideroptions;
tmpSlider.subControls = SC_SliderTickmarks; tmpSlider.subControls = SC_SliderTickmarks;
QProxyStyle::drawComplexControl(cc, &tmpSlider, painter, widget); QProxyStyle::drawComplexControl(cc, &tmpSlider, painter, widget);
} }
if ( slider->subControls & SC_SliderHandle && handle.isValid() ) if ( slideroptions->subControls & SC_SliderHandle && handle.isValid() )
{ {
/* Useful for debugging */ /* Useful for debugging */
//painter->setBrush( QColor( 0, 0, 255, 150 ) ); //painter->setBrush( QColor( 0, 0, 255, 150 ) );
//painter->drawRect( handle ); //painter->drawRect( handle );
if ( option->state & QStyle::State_MouseOver || (seekSlider && seekSlider->isAnimationRunning() ) ) if ( option->state & QStyle::State_MouseOver || slideroptions->animate )
{ {
QPalette p = slider->palette; QPalette p = slideroptions->palette;
/* draw chapters tickpoints */ /* draw chapters tickpoints */
if ( seekSlider->chapters && seekSlider->inputLength && groove.width() ) if ( slideroptions->points.size() && slideroptions->length && groove.width() )
{ {
QColor background = p.color( QPalette::Active, QPalette::Window ); QColor background = p.color( QPalette::Active, QPalette::Window );
QColor foreground = p.color( QPalette::Active, QPalette::WindowText ); QColor foreground = p.color( QPalette::Active, QPalette::WindowText );
foreground.setHsv( foreground.hue(), foreground.setHsv( foreground.hue(),
( background.saturation() + foreground.saturation() ) / 2, ( background.saturation() + foreground.saturation() ) / 2,
( background.value() + foreground.value() ) / 2 ); ( background.value() + foreground.value() ) / 2 );
if ( slider->orientation == Qt::Horizontal ) /* TODO: vertical */ if ( slideroptions->orientation == Qt::Horizontal ) /* TODO: vertical */
{ {
QList<SeekPoint> points = seekSlider->chapters->getPoints(); foreach( int64_t time, slideroptions->points )
foreach( SeekPoint point, points )
{ {
int x = groove.x() + point.time / 1000000.0 / seekSlider->inputLength * groove.width(); int x = groove.x() + time / 1000000.0 / slideroptions->length * groove.width();
painter->setPen( foreground ); painter->setPen( foreground );
painter->setBrush( Qt::NoBrush ); painter->setBrush( Qt::NoBrush );
painter->drawLine( x, slider->rect.height(), x, slider->rect.height() - CHAPTERSSPOTSIZE ); painter->drawLine( x, slideroptions->rect.height(), x, slideroptions->rect.height() - CHAPTERSSPOTSIZE );
} }
} }
} }
...@@ -190,8 +195,7 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -190,8 +195,7 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
shadowGradient.setColorAt( 1.0, shadowLight ); shadowGradient.setColorAt( 1.0, shadowLight );
painter->setPen( Qt::NoPen ); painter->setPen( Qt::NoPen );
if ( seekSlider != NULL ) painter->setOpacity( slideroptions->animationopacity );
painter->setOpacity( seekSlider->mHandleOpacity );
/* draw the handle's shadow */ /* draw the handle's shadow */
painter->setBrush( shadowGradient ); painter->setBrush( shadowGradient );
......
...@@ -24,11 +24,23 @@ ...@@ -24,11 +24,23 @@
#define SEEKSTYLE_HPP #define SEEKSTYLE_HPP
#include <QProxyStyle> #include <QProxyStyle>
#include <QStyleOptionSlider>
class SeekStyle : public QProxyStyle class SeekStyle : public QProxyStyle
{ {
Q_OBJECT Q_OBJECT
public:
class SeekStyleOption : public QStyleOptionSlider
{
public:
SeekStyleOption();
float buffering;
int length;
bool animate;
qreal animationopacity;
QList<int64_t> points;
};
public: public:
SeekStyle(); SeekStyle();
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0) const; virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0) const;
......
...@@ -380,6 +380,30 @@ void SeekSlider::leaveEvent( QEvent * ) ...@@ -380,6 +380,30 @@ void SeekSlider::leaveEvent( QEvent * )
} }
} }
void SeekSlider::paintEvent( QPaintEvent *ev )
{
if ( alternativeStyle )
{
SeekStyle::SeekStyleOption option;
option.initFrom( this );
option.buffering = f_buffering;
option.length = inputLength;
option.animate = ( animHandle->state() == QAbstractAnimation::Running
|| hideHandleTimer->isActive() );
option.animationopacity = mHandleOpacity;
option.sliderPosition = sliderPosition();
option.sliderValue = value();
option.maximum = maximum();
option.minimum = minimum();
foreach( const SeekPoint &point, chapters->getPoints() )
option.points << point.time;
QPainter painter( this );
style()->drawComplexControl( QStyle::CC_Slider, &option, &painter, this );
}
else
QSlider::paintEvent( ev );
}
void SeekSlider::hideEvent( QHideEvent * ) void SeekSlider::hideEvent( QHideEvent * )
{ {
mTimeTooltip->hide(); mTimeTooltip->hide();
...@@ -444,12 +468,6 @@ void SeekSlider::hideHandle() ...@@ -444,12 +468,6 @@ void SeekSlider::hideHandle()
animHandle->start(); animHandle->start();
} }
bool SeekSlider::isAnimationRunning() const
{
return animHandle->state() == QAbstractAnimation::Running
|| hideHandleTimer->isActive();
}
/* This work is derived from Amarok's work under GPLv2+ /* This work is derived from Amarok's work under GPLv2+
- Mark Kretschmann - Mark Kretschmann
......
...@@ -66,13 +66,13 @@ protected: ...@@ -66,13 +66,13 @@ protected:
virtual void enterEvent( QEvent * ); virtual void enterEvent( QEvent * );
virtual void leaveEvent( QEvent * ); virtual void leaveEvent( QEvent * );
virtual void hideEvent( QHideEvent * ); virtual void hideEvent( QHideEvent * );
virtual void paintEvent(QPaintEvent *ev);
virtual bool eventFilter( QObject *obj, QEvent *event ); virtual bool eventFilter( QObject *obj, QEvent *event );
virtual QSize sizeHint() const; virtual QSize sizeHint() const;
void processReleasedButton(); void processReleasedButton();
bool isAnimationRunning() const;
qreal handleOpacity() const; qreal handleOpacity() const;
void setHandleOpacity( qreal opacity ); void setHandleOpacity( qreal opacity );
int handleLength(); int handleLength();
...@@ -118,8 +118,6 @@ private slots: ...@@ -118,8 +118,6 @@ private slots:
signals: signals:
void sliderDragged( float ); void sliderDragged( float );
friend class SeekStyle;
}; };
/* Sound Slider inherited directly from QAbstractSlider */ /* Sound Slider inherited directly from QAbstractSlider */
......
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