oprava dvojiteho connectu + smazani promenne url
[ctkuk.git] / timebufferedslider.cpp
blob39d748c5ce32f794596b62838f006348ce7e8c65
1 #include "timebufferedslider.h"
3 #include <QPainter>
5 /*======================== Contructors / Destructor =============================*/
7 TimeBufferedSlider::TimeBufferedSlider( QWidget* parent ): Slider( parent )
9 m_sliding = false;
10 m_outside = false;
11 m_prevValue = 0;
12 m_bufferValue = 0;
13 m_pMediaObject = 0;
15 setRange( 0, 100 );
18 TimeBufferedSlider::~TimeBufferedSlider()
24 /*======================== Public slots =============================*/
26 void TimeBufferedSlider::setBufferValue( int value)
28 m_bufferValue = value;
30 this->repaint();
33 void TimeBufferedSlider::setMediaObject ( Phonon::MediaObject * media )
35 m_pMediaObject = media;
36 m_pMediaObject->setTickInterval(1000);
37 setMinimum(0);
40 connect(media,SIGNAL(hasVideoChanged(bool)),this,SLOT(mediaVideoChanged(bool)));
44 void TimeBufferedSlider::mediaVideoChanged(bool hasVideo)
46 setEnabled(hasVideo);
47 if (hasVideo)
49 connect(m_pMediaObject,SIGNAL(tick( qint64)),this,SLOT(setValue( qint64 )));
51 else
53 disconnect(m_pMediaObject,SIGNAL(tick( qint64)),this,SLOT(setValue( qint64 )));
58 /*======================== Public functions =============================*/
61 int TimeBufferedSlider::valueBuffer() const
63 return m_bufferValue;
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)
96 p->setPen(Qt::white);
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;
110 qint64 _xpos = -6;
112 if (isEnabled())
114 qint64 diff = maximum() - minimum();
115 _xpos = ((diff == 0) ? 0 : (width*value()/diff))-6;
116 _bufferValue = m_bufferValue;
118 if (_xpos > width-13)
119 _xpos = width-13;
120 if (_xpos < 0)
121 _xpos = 0;
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);