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

Qt: seekstyle: pass parameters through options.

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