TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongslistfunctionwidget.cpp
Go to the documentation of this file.
2 #include "musicapplication.h"
3 #include "musictinyuiobject.h"
4 #include "musicwidgetheaders.h"
5 
6 #include <QPropertyAnimation>
7 
9  : QLabel(parent),
10  m_currentAnimationValue(1)
11 {
12  setWindowFlags(Qt::FramelessWindowHint);
13  setAttribute(Qt::WA_TranslucentBackground);
14 
15  QHBoxLayout *layout = new QHBoxLayout(this);
16  m_mainWidget = new QWidget(this);
17  m_mainWidget->setObjectName("MainWidget");
18  m_mainWidget->setStyleSheet("#MainWidget{border-image: url(:/tiny/lb_function_normal); }");
19  layout->setContentsMargins(0, 0, 0, 0);
20  layout->setSpacing(0);
21  layout->addWidget(m_mainWidget);
22  setLayout(layout);
23 
24  resize(55, 26);
25 
26  QToolButton *locationButton = new QToolButton(m_mainWidget);
27  QToolButton *searchButton = new QToolButton(m_mainWidget);
28  locationButton->setStyleSheet(TTK::UI::TinyBtnLocation);
29  locationButton->setCursor(QCursor(Qt::PointingHandCursor));
30  locationButton->setGeometry(1, 1, 24, 24);
31  searchButton->setStyleSheet(TTK::UI::TinyBtnLocalSearch);
32  searchButton->setCursor(QCursor(Qt::PointingHandCursor));
33  searchButton->setGeometry(29, 1, 24, 24);
34 
35  connect(locationButton, SIGNAL(clicked()), MusicApplication::instance(), SLOT(currentPlayLocation()));
36  connect(searchButton, SIGNAL(clicked()), parent, SLOT(showSearchWidget()));
37 
38  m_timer.setInterval(3 * TTK_DN_S2MS);
39  connect(&m_timer, SIGNAL(timeout()), SLOT(leaveTimeout()));
40 
41  m_animation = new QPropertyAnimation(this, "windowOpacity", this);
42  m_animation->setDuration(TTK_DN_S2MS);
43  connect(m_animation, SIGNAL(finished()), SLOT(animationFinished()));
44 
45  m_timer.start();
46 }
47 
49 {
50  delete m_mainWidget;
51  delete m_animation;
52 }
53 
55 {
56  m_timer.stop();
57  m_timer.start();
58 }
59 
60 void MusicSongsListFunctionWidget::start(bool play, int end)
61 {
62  if(m_animation->state() == QAbstractAnimation::Running)
63  {
64  m_currentAnimationValue = m_animation->currentValue().toFloat();
65  }
66 
67  m_animation->stop();
68  play ? m_timer.start() : m_timer.stop();
69  m_animation->setStartValue(m_currentAnimationValue);
70  m_animation->setEndValue(end);
71  m_animation->start();
72 }
73 
75 {
77  start(false, 0);
78 }
79 
81 {
82  m_currentAnimationValue = m_animation->currentValue().toFloat();
84  {
86  }
87 }
88 
90 {
91  QLabel::enterEvent(event);
93  {
94  start(false, 1);
95  }
96  m_mainWidget->setStyleSheet("#MainWidget{border-image: url(:/tiny/lb_function_hover); }");
97 }
98 
100 {
101  QLabel::leaveEvent(event);
102  start(true, 0);
103  m_mainWidget->setStyleSheet("#MainWidget{border-image: url(:/tiny/lb_function_normal); }");
104 }
#define TTK_SIGNAL
Definition: ttkqtglobal.h:164
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
static MusicApplication * instance()
static constexpr const char * TinyBtnLocalSearch
virtual void enterEvent(QtEnterEvent *event) overridefinal
virtual void leaveEvent(QEvent *event) overridefinal
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
static constexpr const char * TinyBtnLocation
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
MusicSongsListFunctionWidget(QWidget *parent=nullptr)