-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyslider.cpp
68 lines (59 loc) · 1.88 KB
/
myslider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "myslider.h"
#include "Singleton.h"
#include "mediaplay.h"
#include <QMouseEvent>
#include <QDebug>
MySlider::MySlider(QWidget *parent, Qt::Orientation orientation) : QSlider(orientation, parent)
,m_changeable(false)
{
//this->setRange(0, 1000);
std::shared_ptr<MediaPlay> media = Singleton<MediaPlay>::GetInstance();
connect(&m_Timer, &QTimer::timeout, [=](){
if (media->GetCurrentState() == STOPPED)
{
if (this->isEnabled())
{
this->setEnabled(false);
}
return ;
}
if (!this->isEnabled())
{
this->setEnabled(true);
}
this->setValue(int(media->GetCurrentFrame()));
});
connect(this, &MySlider::valueChanged, [=](){
if (/*m_changeable && */media->GetCurrentState() != STOPPED)
{
media->SetPlayPosition(this->value());
}
});
m_Timer.start(1000);
}
void MySlider::mousePressEvent(QMouseEvent *ev)
{
if (ev->type()==QEvent::MouseButtonPress) //ÅжÏÀàÐÍ
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(ev);
if (mouseEvent->button() == Qt::LeftButton) //ÅжÏ×ó¼ü
{
int dur = this->maximum() - this->minimum();
int pos = this->minimum() + dur * ((double)mouseEvent->x() / this->width());
qDebug() << mouseEvent->x() << " " << this->width()<< " " << pos << dur;
if(pos != this->sliderPosition())
{
std::shared_ptr<MediaPlay> media = Singleton<MediaPlay>::GetInstance();
media->Pause();
this->setValue(pos);
}
}
}
QSlider::mousePressEvent(ev);
}
void MySlider::mouseReleaseEvent(QMouseEvent *ev)
{
std::shared_ptr<MediaPlay> media = Singleton<MediaPlay>::GetInstance();
media->Play();
QSlider::mouseReleaseEvent(ev);
}