TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicplayedlistpopwidget.cpp
Go to the documentation of this file.
4 #include "musictinyuiobject.h"
5 #include "musicapplication.h"
6 #include "musicplaylist.h"
7 #include "musicwidgetheaders.h"
8 
9 #include <QTimer>
10 
11 static constexpr int MAX_SIZE = 3;
12 
14  : QFrame(parent)
15 {
16  setFixedHeight(37);
17 }
18 
20 {
21  QFrame::paintEvent(event);
22  QPainter painter(this);
23 
24  QLinearGradient gradient;
25  gradient.setStart(0, 32);
26  gradient.setFinalStop(0, height());
27  gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
28  gradient.setColorAt(0.9, QColor(180, 180, 180, 50));
29  painter.fillRect(0, 32, width(), height(), gradient);
30 
31  painter.fillRect(QRect(0, 0, width(), height() - 3), QColor(0xED, 0xF8, 0xFE));
32 }
33 
34 
35 
37 
39  : MusicToolMenuWidget(parent),
40  m_playlist(nullptr)
41 {
42  m_instance = this;
43 
44  setToolTip(tr("Played List"));
45  setStyleSheet(TTK::UI::BtnPlayedList);
46 
47  initialize();
48 }
49 
51 {
52  delete m_tableWidget;
53  qDeleteAll(m_labels);
54 }
55 
57 {
58  return m_instance;
59 }
60 
62 {
63  m_playlist = playlist;
64 }
65 
67 {
68  m_songList.clear();
71 }
72 
74 {
76 }
77 
78 void MusicPlayedListPopWidget::updatePlayedList(const TTK::IndexPropertyList &indexs)
79 {
80  m_playlist->update(indexs);
81 }
82 
84 {
85  if(index < 0 || index >= m_songList.count())
86  {
87  return;
88  }
89 
91  m_tableWidget->removeRow(index);
93 
94  m_playlist->remove(index);
95  m_songList.removeAt(index);
96 
98 }
99 
100 void MusicPlayedListPopWidget::remove(int playlistRow, const QString &path)
101 {
102  int index = -1;
104 
105  do
106  {
107  index = m_playlist->remove(playlistRow, path);
108  if(index != -1)
109  {
110  m_songList.removeAt(index);
111  m_tableWidget->removeRow(index);
112  }
113  } while(index != -1);
114 
117 }
118 
119 void MusicPlayedListPopWidget::remove(int playlistRow, const MusicSong &song)
120 {
121  remove(playlistRow, song.path());
122 }
123 
124 void MusicPlayedListPopWidget::remove(int playlistRow, const MusicSongList &songs)
125 {
126  int index = -1;
128 
129  for(const MusicSong &song : qAsConst(songs))
130  {
131  do
132  {
133  index = m_playlist->remove(playlistRow, song.path());
134  if(index != -1)
135  {
136  m_songList.removeAt(index);
137  m_tableWidget->removeRow(index);
138  }
139  } while(index != -1);
140  }
141 
144 }
145 
146 void MusicPlayedListPopWidget::append(const MusicSongList &songs)
147 {
148  clear();
149  m_songList = songs;
151 }
152 
153 void MusicPlayedListPopWidget::append(int playlistRow, const MusicSong &song)
154 {
155  m_playlist->append(playlistRow, song.path());
156  m_songList << song;
158 }
159 
160 void MusicPlayedListPopWidget::append(int playlistRow, const MusicSongList &songs)
161 {
162  for(const MusicSong &song : qAsConst(songs))
163  {
164  m_playlist->append(playlistRow, song.path());
165  }
166 
167  m_songList << songs;
169 }
170 
171 void MusicPlayedListPopWidget::insert(int playlistRow, const MusicSong &song)
172 {
173  insert(playlistRow, m_tableWidget->playRowIndex() + 1, song);
174 }
175 
176 void MusicPlayedListPopWidget::insert(int playlistRow, const MusicSongList &songs)
177 {
178  insert(playlistRow, m_tableWidget->playRowIndex() + 1, songs);
179 }
180 
181 void MusicPlayedListPopWidget::insert(int playlistRow, int index, const MusicSong &song)
182 {
183  if(index < 0 || index > m_songList.count())
184  {
185  return;
186  }
187 
188  (index != m_songList.count()) ? m_songList.insert(index, song) : m_songList.append(song);
189  m_playlist->appendQueue(playlistRow, song.path());
190 
191  const int row = m_tableWidget->playRowIndex();
194 
197 
198  for(const MusicPlayItem &item : qAsConst(m_playlist->queueList()))
199  {
200  m_tableWidget->setQueueState(item.m_playlistRow);
201  }
202 }
203 
204 void MusicPlayedListPopWidget::insert(int playlistRow, int index, const MusicSongList &songs)
205 {
206  if(index < 0 || index > m_songList.count())
207  {
208  return;
209  }
210 
211  for(int i = songs.count() - 1; i >= 0; --i)
212  {
213  const MusicSong &song = songs[i];
214  (index != m_songList.count()) ? m_songList.insert(index, song) : m_songList.append(song);
215  m_playlist->appendQueue(playlistRow, song.path());
216  }
217 
218  const int row = m_tableWidget->playRowIndex();
221 
224 
225  for(const MusicPlayItem &item : qAsConst(m_playlist->queueList()))
226  {
227  m_tableWidget->setQueueState(item.m_playlistRow);
228  }
229 }
230 
232 {
233  const int index = m_playlist->currentIndex();
234  m_tableWidget->selectRow(index);
235 }
236 
237 void MusicPlayedListPopWidget::selectCurrentIndex(int playlistRow, const MusicSong &song)
238 {
239  m_playlist->setCurrentIndex(playlistRow, song.path());
241 }
242 
244 {
245  QPoint pos = mapToGlobal(QPoint(0, 0));
246  pos.setY(pos.y() - m_containWidget->height() - 10);
247  pos.setX(pos.x() - m_containWidget->width() + width() + 3);
248 
250  m_menu->exec(pos);
251 }
252 
254 {
255  if(index.isEmpty())
256  {
257  return;
258  }
259 
260  clearQueueState();
261 
262  const int id = m_tableWidget->playRowIndex();
263  bool contains = false;
264 
265  for(int i = index.count() - 1; i >= 0; --i)
266  {
267  const int row = index[i];
268  if(id == row)
269  {
270  contains = true;
271  }
272  m_playlist->remove(row);
273  }
274 
275  if(contains)
276  {
278  if(w->isPlaying())
279  {
280  w->playNext();
281  }
282  else
283  {
285  }
286 
287  if(m_playlist->isEmpty())
288  {
289  clearPlaylist();
290  }
291  }
292  else
293  {
294  int offset = 0;
295  for(int i = 0; i < index.count(); ++i)
296  {
297  if(index[i] >= id)
298  {
299  break;
300  }
301  ++offset;
302  }
303  m_tableWidget->selectRow(id - offset);
304  }
305 
306  setPlaylistCount(m_songList.count());
307 }
308 
310 {
311  if(m_songList.isEmpty())
312  {
313  return;
314  }
315 
317  const int count = m_tableWidget->rowCount();
318  for(int i = 0; i < count; ++i)
319  {
320  m_tableWidget->removeRow(0);
321  }
322 
323  clearPlaylist();
324 }
325 
327 {
328  const int row = m_tableWidget->currentRow();
329  if(row < 0)
330  {
331  return;
332  }
333 
334  clearQueueState();
337 }
338 
340 {
341  Q_UNUSED(row);
342  Q_UNUSED(column);
344 }
345 
347 {
348  QHBoxLayout *layout = new QHBoxLayout(this);
349  layout->setContentsMargins(0, 0, 0, 0);
350  layout->setSpacing(2);
351 
352  layout->addStretch(2);
353  for(int i = 0; i < MAX_SIZE; ++i)
354  {
355  QLabel *label = new QLabel(this);
356  label->setFixedWidth(9);
357  label->setPixmap(QPixmap(":/tiny/lb_number0"));
358  layout->addWidget(label);
359  m_labels << label;
360  }
361  layout->addStretch(1);
362 
363  setLayout(layout);
364 
365  m_containWidget->setFixedSize(LEFT_SIDE_WIDTH_MIN, 400);
366  QVBoxLayout *containLayout = new QVBoxLayout(m_containWidget);
367  containLayout->setContentsMargins(0, 0, 0, 0);
368  containLayout->setSpacing(0);
369  containLayout->addWidget(createContainerWidget());
370 
371  m_scrollArea = new QScrollArea(this);
372 
373  const QString &background = TTK::UI::BackgroundStyle10;
374  QWidget *view = m_scrollArea->viewport();
375  view->setObjectName("Viewport");
376  view->setStyleSheet(QString("#Viewport{%1}").arg(background));
377 
380  connect(m_tableWidget, SIGNAL(deleteItemAt(TTKIntList)), SLOT(removeItemAt(TTKIntList)));
381  connect(m_tableWidget, SIGNAL(cellDoubleClicked(int,int)), SLOT(itemDoubleClicked(int,int)));
382 
383  QWidget *playedListContainer = new QWidget(m_scrollArea);
384  QVBoxLayout *playedListLayout = new QVBoxLayout(playedListContainer);
385  playedListLayout->setContentsMargins(0, 0, 0, 0);
386  playedListLayout->setSpacing(0);
387  playedListLayout->addWidget(m_tableWidget);
388  playedListContainer->setLayout(playedListLayout);
389 
391  m_tableWidget->setMovedScrollBar(m_scrollArea->verticalScrollBar());
392 
393  containLayout->addWidget(m_scrollArea);
394  m_containWidget->setLayout(containLayout);
395 }
396 
398 {
400 #ifdef Q_OS_UNIX
401  topWidget->setObjectName("TopWidget");
402  topWidget->setStyleSheet(QString("#TopWidget{%1}").arg(TTK::UI::BackgroundStyle10));
403 #endif
404  QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
405  topWidgetLayout->setSpacing(15);
406  QLabel *label = new QLabel(tr("Played List"), topWidget);
408 
409  QPushButton *shareButton = new QPushButton(this);
410  shareButton->setFixedSize(16, 16);
411  shareButton->setToolTip(tr("Share List"));
412  shareButton->setCursor(QCursor(Qt::PointingHandCursor));
413  shareButton->setStyleSheet(TTK::UI::TinyBtnShare);
414 
415  QPushButton *deleteButton = new QPushButton(this);
416  deleteButton->setFixedSize(16, 16);
417  deleteButton->setToolTip(tr("Clear List"));
418  deleteButton->setCursor(QCursor(Qt::PointingHandCursor));
419  deleteButton->setStyleSheet(TTK::UI::TinyBtnDelete);
420  connect(deleteButton, SIGNAL(clicked()), SLOT(clearItems()));
421 
422 #ifdef Q_OS_UNIX
423  shareButton->setFocusPolicy(Qt::NoFocus);
424  deleteButton->setFocusPolicy(Qt::NoFocus);
425 #endif
426 
427  QToolButton *closeButton = new QToolButton(this);
428  closeButton->setFixedSize(16, 16);
429  closeButton->setToolTip(tr("Close List"));
430  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
431  closeButton->setStyleSheet(TTK::UI::TinyBtnClose);
432  connect(closeButton, SIGNAL(clicked()), m_menu, SLOT(close()));
433 
434  topWidgetLayout->addWidget(label);
435  topWidgetLayout->addStretch(1);
436  topWidgetLayout->addWidget(shareButton);
437  topWidgetLayout->addWidget(deleteButton);
438  topWidgetLayout->addWidget(closeButton);
439  topWidget->setLayout(topWidgetLayout);
440 
441  return topWidget;
442 }
443 
445 {
446  setPlaylistCount(m_songList.count());
448 }
449 
451 {
452  if(count >= 1000)
453  {
454  for(int i = MAX_SIZE - 1; i >= 0; --i)
455  {
456  m_labels[i]->setPixmap(QPixmap(QString(":/tiny/lb_number%1").arg(9)));
457  }
458  }
459  else
460  {
461  for(int i = MAX_SIZE - 1; i >= 0; --i)
462  {
463  m_labels[i]->setPixmap(QPixmap(QString(":/tiny/lb_number%1").arg(count % 10)));
464  count /= 10;
465  }
466  }
467 }
468 
470 {
472  m_songList.clear();
473  setPlaylistCount(0);
474 
476 }
void appendQueue(int playlistRow, const QString &content)
MusicPlayedListTopContainerWidget(QWidget *parent=nullptr)
The class of the played list top container widget.
static MusicPlayedListPopWidget * m_instance
The class of the music play item.
Definition: musicplaylist.h:27
The class of the tool menu base widget.
static MusicApplication * instance()
static const QString FontStyle03
#define TTK_LOW_LEVEL
Definition: ttkglobal.h:253
QString path() const noexcept
Definition: musicsong.h:90
static constexpr const char * TinyBtnShare
virtual void selectRow(int index) overridefinal
MusicSongsListPlayedTableWidget * m_tableWidget
MusicToolMenu * m_menu
static constexpr int MAX_SIZE
void updatePlayedList(const TTK::IndexPropertyList &indexs)
void playIndexBy(int row)
The class of the app main widget.
static constexpr const char * BtnPlayedList
static constexpr const char * TinyBtnDelete
virtual void popupMenu() overridefinal
static MusicPlayedListPopWidget * instance()
static const QString FontStyle01
Font.
MusicPlayedListPopWidget(QWidget *parent=nullptr)
void setMovedScrollBar(QScrollBar *bar=nullptr)
void playedIndexBy(int row)
voidpf uLong offset
Definition: ioapi.h:142
bool remove(int pos)
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
#define qAsConst
Definition: ttkqtglobal.h:53
bool isEmpty() const
const MusicPlayItemList & queueList() const
The class of the played list pop widget.
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
int currentIndex() const
virtual void setSongsList(MusicSongList *songs)
#define TTK_NORMAL_LEVEL
Definition: ttkglobal.h:254
The class of the songs played queue list table widget.
#define TTK_SLOT
Definition: ttkqtglobal.h:165
static const QString ColorStyle08
Definition: musicuiobject.h:58
void setCurrentIndex(int index)
static const QString BackgroundStyle10
void append(const MusicSongList &songs)
void setPlaylist(MusicPlaylist *playlist)
void update(const TTK::IndexPropertyList &indexs)
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
void append(int playlistRow, const QString &content)
bool isPlaying() const
void insert(int playlistRow, const MusicSong &song)
The class of the music song info.
Definition: musicsong.h:28
The class of the music play list.
Definition: musicplaylist.h:63
void removeItemAt(const TTKIntList &index)
virtual void paintEvent(QPaintEvent *event) overridefinal
static constexpr const char * TinyBtnClose
virtual void updateSongsList(const MusicSongList &songs) overridefinal
#define LEFT_SIDE_WIDTH_MIN
Definition: musicobject.h:155