TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicmovinglabelslider.cpp
Go to the documentation of this file.
2 #include "ttktime.h"
3 
5  : MusicMovingLabelSlider(Qt::Horizontal, parent)
6 {
7 
8 }
9 
10 MusicMovingLabelSlider::MusicMovingLabelSlider(Qt::Orientation orientation, QWidget *parent)
11  : MusicMovingClickedSlider(orientation, parent)
12 {
13  m_textLabel = new QLabel(this);
14  m_textLabel->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
15  m_textLabel->setGeometry(0, 0, 40, 20);
16  m_textLabel->setAlignment(Qt::AlignCenter);
17  m_textLabel->setFocusPolicy(Qt::NoFocus);
18  m_textLabel->setStyleSheet(TTK::UI::LabelStyle01);
19 }
20 
22 {
23  delete m_textLabel;
24 }
25 
27 {
29 #ifdef Q_OS_UNIX
30  m_textLabel->show();
31 #endif
32  m_textLabel->raise();
33 }
34 
36 {
38 
39  const QPoint &curPos = mapFromGlobal(QCursor::pos());
40  const QPoint &glbPos = mapToGlobal(QPoint(0, 0));
41  const QSize &sizePos = size();
42  QPoint changePos;
43 
44  if(orientation() == Qt::Vertical)
45  {
46  changePos = limitLableGeometry(curPos.y(), glbPos.y(), sizePos.height());
47  m_textLabel->move((glbPos + QPoint(sizePos.width(), 0)).x(), changePos.x());
48  }
49  else
50  {
51  changePos = limitLableGeometry(curPos.x(), glbPos.x(), sizePos.width());
52  m_textLabel->move(changePos.x(), (glbPos - QPoint(0, m_textLabel->height())).y());
53  }
54  m_textLabel->setText(TTKTime::formatDuration(changePos.y()));
55 }
56 
58 {
59  MusicMovingClickedSlider::enterEvent(event);
60 #ifndef Q_OS_UNIX
61  m_textLabel->show();
62 #endif
63 }
64 
66 {
67  MusicMovingClickedSlider::leaveEvent(event);
68  m_textLabel->hide();
69 }
70 
71 QPoint MusicMovingLabelSlider::limitLableGeometry(int x, int y, int z)
72 {
73  QPoint pt;
74  if(0 < x && x < z)
75  {
76  pt.setX(y + x);
77  pt.setY(qint64(x) * maximum() / z);
78  }
79  if(x <= 0)
80  {
81  pt.setX(y);
82  pt.setY(0);
83  }
84  if(x >= z)
85  {
86  pt.setX(y + z);
87  pt.setY(maximum());
88  }
89  return pt;
90 }
virtual void leaveEvent(QEvent *event) overridefinal
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
voidpf void uLong size
Definition: ioapi.h:136
The class of the slider that can show such as tooltip.
MusicMovingLabelSlider(QWidget *parent=nullptr)
virtual void mouseMoveEvent(QMouseEvent *event) override
static const QString LabelStyle01
Label.
virtual void enterEvent(QtEnterEvent *event) overridefinal
virtual void mousePressEvent(QMouseEvent *event) override
QPoint limitLableGeometry(int x, int y, int z)
virtual void mousePressEvent(QMouseEvent *event) overridefinal
The class of the slider moving clicked slider.
virtual void mouseMoveEvent(QMouseEvent *event) overridefinal
static qint64 formatDuration(const QString &time) noexcept
Definition: ttktime.cpp:123