1 #include "timebufferedslider.h"
5 /*======================== Contructors / Destructor =============================*/
7 TimeBufferedSlider::TimeBufferedSlider( QWidget
* parent
): Slider( parent
)
18 TimeBufferedSlider::~TimeBufferedSlider()
24 /*======================== Public slots =============================*/
26 void TimeBufferedSlider::setBufferValue( int value
)
28 m_bufferValue
= value
;
33 void TimeBufferedSlider::setMediaObject ( Phonon::MediaObject
* media
)
35 m_pMediaObject
= media
;
36 m_pMediaObject
->setTickInterval(1000);
40 connect(media
,SIGNAL(hasVideoChanged(bool)),this,SLOT(mediaVideoChanged(bool)));
44 void TimeBufferedSlider::mediaVideoChanged(bool hasVideo
)
49 connect(m_pMediaObject
,SIGNAL(tick( qint64
)),this,SLOT(setValue( qint64
)));
53 disconnect(m_pMediaObject
,SIGNAL(tick( qint64
)),this,SLOT(setValue( qint64
)));
58 /*======================== Public functions =============================*/
61 int TimeBufferedSlider::valueBuffer() const
67 int TimeBufferedSlider::maximumBuffer() const
69 return m_bufferMaximum
;
72 int TimeBufferedSlider::minimumBuffer() const
74 return m_bufferMinimum
;
77 void TimeBufferedSlider::setMaximumBuffer(int max
)
79 m_bufferMaximum
= max
;
82 void TimeBufferedSlider::setMinimumBuffer(int min
)
84 m_bufferMinimum
= min
;
88 void TimeBufferedSlider::setRangeBuffer(int min
, int max
)
90 setMinimumBuffer(min
);
91 setMaximumBuffer(max
);
94 void TimeBufferedSlider::paintCustomSlider( QPainter
*p
, int x
, int y
, int width
, int height
)
97 QLinearGradient
linearGrad(QPointF(width
, 0), QPointF(width
, height
));
98 linearGrad
.setColorAt(0, Qt::gray
);
99 linearGrad
.setColorAt(isEnabled() ? 1 : 0.7, Qt::white
);
100 p
->setBrush(linearGrad
);
102 p
->drawRoundedRect(0,height
/2-5,width
-1,10,5,5);
105 linearGrad
.setColorAt(0, Qt::red
);
106 linearGrad
.setColorAt(.7, Qt::white
);
107 p
->setBrush(linearGrad
);
109 int _bufferValue
= m_bufferMinimum
;
114 qint64 diff
= maximum() - minimum();
115 _xpos
= ((diff
== 0) ? 0 : (width
*value()/diff
))-6;
116 _bufferValue
= m_bufferValue
;
118 if (_xpos
> width
-13)
123 if (_bufferValue
> 0)
125 qint64 diff
= m_bufferMaximum
- m_bufferMinimum
;
126 p
->drawRoundedRect(2,height
/2-3,((diff
== 0) ? 0 : ((width
-1)*_bufferValue
/diff
))-5,6,2,2);
129 QRadialGradient
radialGrad(QPointF(_xpos
+3,height
/2-6), 12);
130 radialGrad
.setColorAt(0, Qt::white
);
131 radialGrad
.setColorAt(1, isEnabled() ? Qt::black
: Qt::gray
);
132 p
->setBrush(radialGrad
);
135 p
->drawEllipse(_xpos
,height
/2-6,12,12);