TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongslistplaywidget.cpp
Go to the documentation of this file.
2 #include "musicsongmeta.h"
3 #include "musicitemrenameedit.h"
4 #include "musicwidgetutils.h"
5 #include "musicsettingmanager.h"
6 #include "musicapplication.h"
7 #include "musicleftareawidget.h"
8 #include "musictinyuiobject.h"
10 #include "musicwidgetheaders.h"
11 #include "musicsong.h"
12 
13 #include <QTimer>
14 
16  : QWidget(parent),
17  m_noCover(false),
18  m_currentPlayIndex(index),
19  m_renameEdit(nullptr)
20 {
21  QPalette plt(palette());
22  plt.setBrush(QPalette::Base, QBrush(QColor(0, 0, 0, 40)));
23  setPalette(plt);
24  setAutoFillBackground(true);
25 
26  QPushButton *addButton = new QPushButton(this);
27  addButton->setGeometry(2, 25, 16, 16);
28  addButton->setStyleSheet(TTK::UI::TinyBtnPlayLater);
29  addButton->setCursor(QCursor(Qt::PointingHandCursor));
30  addButton->setToolTip(tr("Play Later"));
31 
32  m_artistPictureLabel = new QLabel(this);
33  m_artistPictureLabel->setFixedSize(60, 60);
34  m_artistPictureLabel->setAttribute(Qt::WA_TranslucentBackground);
35  m_artistPictureLabel->setGeometry(20, 0, 60, 60);
36 
38  m_songNameLabel->setAttribute(Qt::WA_TranslucentBackground);
39  m_songNameLabel->setStyleSheet(TTK::UI::LabelStyle02);
40  m_songNameLabel->setGeometry(85, 5, 200, 25);
41 
42  m_durationLabel = new QLabel(this);
43  m_durationLabel->setFixedSize(100, 20);
44  m_durationLabel->setAttribute(Qt::WA_TranslucentBackground);
45  m_durationLabel->setStyleSheet(TTK::UI::ColorStyle06);
46  m_durationLabel->setGeometry(85, 37, 100, 20);
47 
48  m_downloadButton = new QPushButton(this);
49  m_downloadButton->setGeometry(175, 40, 16, 16);
50  m_downloadButton->setCursor(QCursor(Qt::PointingHandCursor));
51  m_downloadButton->setToolTip(tr("Download"));
53 
54  m_showMVButton = new QPushButton(this);
55  m_showMVButton->setGeometry(211, 39, 16, 16);
56  m_showMVButton->setStyleSheet(TTK::UI::TinyBtnMV);
57  m_showMVButton->setCursor(QCursor(Qt::PointingHandCursor));
58  m_showMVButton->setToolTip(tr("Show Movie"));
59 
60  m_loveButton = new QPushButton(this);
61  m_loveButton->setGeometry(231, 40, 16, 16);
62  m_loveButton->setCursor(QCursor(Qt::PointingHandCursor));
63  m_loveButton->setToolTip(tr("Add To Lovest"));
65 
66  m_deleteButton = new QPushButton(this);
67  m_deleteButton->setGeometry(251, 40, 16, 16);
68  m_deleteButton->setStyleSheet(TTK::UI::TinyBtnDelete);
69  m_deleteButton->setCursor(QCursor(Qt::PointingHandCursor));
70  m_deleteButton->setToolTip(tr("Delete"));
71 
72  m_moreButton = new QPushButton(this);
73  m_moreButton->setGeometry(271, 39, 16, 16);
75  m_moreButton->setCursor(QCursor(Qt::PointingHandCursor));
76  m_moreButton->setToolTip(tr("More"));
77 
78 #ifdef Q_OS_UNIX
79  addButton->setFocusPolicy(Qt::NoFocus);
80  m_downloadButton->setFocusPolicy(Qt::NoFocus);
81  m_showMVButton->setFocusPolicy(Qt::NoFocus);
82  m_loveButton->setFocusPolicy(Qt::NoFocus);
83  m_deleteButton->setFocusPolicy(Qt::NoFocus);
84  m_moreButton->setFocusPolicy(Qt::NoFocus);
85 #endif
86 
87  QMenu *menu = new QMenu(this);
88  createMoreMenu(menu);
89  m_moreButton->setMenu(menu);
90 
91  connect(m_loveButton, SIGNAL(clicked()), MusicApplication::instance(), SLOT(addSongToLovestList()));
92  connect(m_downloadButton, SIGNAL(clicked()), MusicLeftAreaWidget::instance(), SLOT(downloadSongToLocal()));
93  connect(m_deleteButton, SIGNAL(clicked()), parent, SLOT(removeItemAt()));
94  connect(this, SIGNAL(renameFinished(QString)), parent, SLOT(itemRenameFinished(QString)));
95  connect(this, SIGNAL(enterChanged(int,int)), parent, SLOT(itemCellEntered(int,int)));
96  connect(m_showMVButton, SIGNAL(clicked()), parent, SLOT(showPlayedMovieQueryWidget()));
97  connect(addButton, SIGNAL(clicked()), parent, SLOT(addToPlayLater()));
98 
99  connect(MusicLeftAreaWidget::instance(), SIGNAL(currentLoveStateChanged()), SLOT(currentLoveStateClicked()));
100  connect(MusicLeftAreaWidget::instance(), SIGNAL(currentDownloadStateChanged()), SLOT(currentDownloadStateClicked()));
101 }
102 
104 {
105  delete m_renameEdit;
106  delete m_artistPictureLabel;
107  delete m_songNameLabel;
108  delete m_durationLabel;
109  delete m_loveButton;
110  delete m_deleteButton;
111  delete m_showMVButton;
112  delete m_downloadButton;
113  delete m_moreButton;
114 }
115 
116 void MusicSongsListPlayWidget::updateDurationLabel(const QString &current, const QString &total)
117 {
118  m_durationLabel->setText(current + total);
119 }
120 
122 {
124  {
125  return;
126  }
127 
128  const QString &name = m_songNameLabel->toolTip().trimmed();
130  {
131  m_artistPictureLabel->setPixmap(QPixmap(":/image/lb_default_art").scaled(60, 60));
132  }
133 }
134 
135 void MusicSongsListPlayWidget::initialize(const QString &name, const QString &path, QString &time)
136 {
137  MusicSongMeta meta;
138  const bool state = meta.read(path);
139  m_songNameLabel->setText(TTK::Widget::elidedText(font(), name, Qt::ElideRight, 198));
140  m_songNameLabel->setToolTip(name);
141 
142  if(state)
143  {
144  time = meta.duration();
145  }
146  else
147  {
148  time = TTK_TIME_INIT;
149  m_noCover = true;
150  }
151 
153 
154  if(state && G_SETTING_PTR->value(MusicSettingManager::OtherReadAlbumCover).toBool())
155  {
156  const QPixmap &pix = meta.cover();
157  if(pix.isNull())
158  {
159  m_noCover = true;
160  }
161  else
162  {
163  m_noCover = false;
164  m_artistPictureLabel->setPixmap(pix.scaled(60, 60));
165  return;
166  }
167  }
168 
170  {
171  m_artistPictureLabel->setPixmap(QPixmap(":/image/lb_default_art").scaled(60, 60));
172  }
173 }
174 
176 {
177  m_renameEdit = new MusicItemRenameEidt(m_songNameLabel->toolTip(), this);
178  connect(m_renameEdit, SIGNAL(renameFinished(QString)), SLOT(changItemName(QString)));
179  m_renameEdit->setGeometry(85, 5, 200, 25);
180  m_renameEdit->show();
181 }
182 
184 {
185  delete m_renameEdit;
186  m_renameEdit = nullptr;
187 }
188 
190 {
191  m_songNameLabel->setText(TTK::Widget::elidedText(font(), name, Qt::ElideRight, 198));
192  m_songNameLabel->setToolTip(name);
193  Q_EMIT renameFinished(name);
195 }
196 
198 {
200  m_loveButton->setStyleSheet(state ? TTK::UI::TinyBtnLove : TTK::UI::TinyBtnUnLove);
201 }
202 
204 {
205  bool state = false;
208 }
209 
211 {
212  QWidget::enterEvent(event);
213  Q_EMIT enterChanged(m_currentPlayIndex, -1);
214 }
215 
217 {
218  menu->setStyleSheet(TTK::UI::MenuStyle02);
219  menu->addAction(QIcon(":/contextMenu/btn_similar"), tr("Similar"), parent(), SLOT(showPlayedSimilarQueryWidget()));
220  menu->addAction(QIcon(":/contextMenu/btn_share"), tr("Share"), parent(), SLOT(showPlayedSongSharedWidget()));
221 }
222 
224 {
225  const QPixmap originPath(QString(ART_DIR_FULL + name + SKN_FILE));
226  if(!originPath.isNull())
227  {
228  m_artistPictureLabel->setPixmap(originPath.scaled(60, 60));
229  return true;
230  }
231  return false;
232 }
bool containsLovestItem() const
static const QString ColorStyle06
Definition: musicuiobject.h:52
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
bool read(const QString &url)
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:128
static MusicApplication * instance()
static constexpr const char * TinyBtnUnDownload
static constexpr const char * TinyBtnPlayLater
bool showArtistPicture(const QString &name) const
void enterChanged(int row, int column)
#define ART_DIR_FULL
Definition: musicobject.h:128
static constexpr const char * TinyBtnDownload
void renameFinished(const QString &text)
static constexpr const char * TinyBtnUnLove
static constexpr const char * TinyBtnDelete
TTK_MODULE_EXPORT QString generateSongTitle(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:117
The class of the item rename edit.
#define TTK_TIME_INIT
Definition: ttkglobal.h:222
const char * name
Definition: http_parser.c:458
static constexpr const char * TinyBtnLove
static constexpr const char * TinyBtnMV
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
virtual void enterEvent(QtEnterEvent *event) overridefinal
#define TTK_SEPARATOR
Definition: ttkglobal.h:195
MusicItemRenameEidt * m_renameEdit
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
static constexpr const char * TinyBtnMore
#define TTK_SLOT
Definition: ttkqtglobal.h:165
void initialize(const QString &name, const QString &path, QString &time)
static MusicLeftAreaWidget * instance()
static const QString MenuStyle02
void changItemName(const QString &name)
The class of the split item clicked widget.
static const QString LabelStyle02
QPixmap cover() noexcept
MusicSongsListPlayWidget(int index, QWidget *parent=nullptr)
QString duration() noexcept
void updateDurationLabel(const QString &current, const QString &total)
#define TTK_STR_CAT(...)
Definition: ttkglobal.h:167
static const QString PushButtonStyle10
QString containsDownloadItem(bool &contains) const
The class of the music song meta.
Definition: musicsongmeta.h:30
#define SKN_FILE
Definition: musicobject.h:61
state
Definition: http_parser.c:279
#define G_SETTING_PTR
MusicSplitItemClickedLabel * m_songNameLabel