TTKMusicPlayer  4.3.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  painter.setRenderHint(QPainter::Antialiasing);
24 
25  QLinearGradient gradient;
26  gradient.setStart(0, 32);
27  gradient.setFinalStop(0, height());
28  gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
29  gradient.setColorAt(0.9, QColor(180, 180, 180, 50));
30  painter.fillRect(0, 32, width(), height(), gradient);
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::updatePlayedRows(const TTK::IndexPropertyList &rows)
79 {
80  m_playlist->update(rows);
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  if(index == m_songList.count())
189  {
190  m_songList.append(song);
191  }
192  else
193  {
194  m_songList.insert(index, song);
195  }
196  m_playlist->appendQueue(playlistRow, song.path());
197 
198  const int row = m_tableWidget->playRowIndex();
201 
204 
205  for(const MusicPlayItem &item : qAsConst(m_playlist->queueList()))
206  {
207  m_tableWidget->setQueueState(item.m_playlistRow);
208  }
209 }
210 
211 void MusicPlayedListPopWidget::insert(int playlistRow, int index, const MusicSongList &songs)
212 {
213  if(index < 0 || index > m_songList.count())
214  {
215  return;
216  }
217 
218  for(int i = songs.count() - 1; i >= 0; --i)
219  {
220  const MusicSong &song = songs[i];
221  if(index == m_songList.count())
222  {
223  m_songList.append(song);
224  }
225  else
226  {
227  m_songList.insert(index, song);
228  }
229  m_playlist->appendQueue(playlistRow, song.path());
230  }
231 
232  const int row = m_tableWidget->playRowIndex();
235 
238 
239  for(const MusicPlayItem &item : qAsConst(m_playlist->queueList()))
240  {
241  m_tableWidget->setQueueState(item.m_playlistRow);
242  }
243 }
244 
246 {
247  return (index < 0 || index >= m_songList.count()) ? QString() : m_songList[index].path();
248 }
249 
251 {
252  const int index = m_playlist->currentIndex();
253  m_tableWidget->selectRow(index);
254 }
255 
256 void MusicPlayedListPopWidget::selectCurrentMedia(int playlistRow, const MusicSong &song)
257 {
258  m_playlist->setCurrentIndex(playlistRow, song.path());
260 }
261 
263 {
264  QPoint pos = mapToGlobal(QPoint(0, 0));
265  pos.setY(pos.y() - m_containWidget->height() - 10);
266  pos.setX(pos.x() - m_containWidget->width() + width() + 3);
267 
269  m_menu->exec(pos);
270 }
271 
273 {
274  if(rows.isEmpty())
275  {
276  return;
277  }
278 
279  clearQueueState();
280 
281  const int id = m_tableWidget->playRowIndex();
282  bool contains = false;
283 
284  for(int i = rows.count() - 1; i >= 0; --i)
285  {
286  const int row = rows[i];
287  if(id == row)
288  {
289  contains = true;
290  }
291  m_playlist->remove(row);
292  }
293 
294  if(contains)
295  {
297  if(w->isPlaying())
298  {
299  w->playNext();
300  }
301  else
302  {
304  }
305 
306  if(m_playlist->isEmpty())
307  {
308  clearPlaylist();
309  }
310  }
311  else
312  {
313  int offset = 0;
314  for(int i = 0; i < rows.count(); ++i)
315  {
316  if(rows[i] >= id)
317  {
318  break;
319  }
320  ++offset;
321  }
322  m_tableWidget->selectRow(id - offset);
323  }
324 
325  setPlaylistCount(m_songList.count());
326 }
327 
329 {
330  if(m_songList.isEmpty())
331  {
332  return;
333  }
334 
336  const int count = m_tableWidget->rowCount();
337  for(int i = 0; i < count; ++i)
338  {
339  m_tableWidget->removeRow(0);
340  }
341 
342  clearPlaylist();
343 }
344 
346 {
347  const int row = m_tableWidget->currentRow();
348  if(row < 0)
349  {
350  return;
351  }
352 
353  clearQueueState();
356 }
357 
359 {
360  Q_UNUSED(row);
361  Q_UNUSED(column);
363 }
364 
366 {
367  QHBoxLayout *layout = new QHBoxLayout(this);
368  layout->setContentsMargins(0, 0, 0, 0);
369  layout->setSpacing(2);
370 
371  layout->addStretch(2);
372  for(int i = 0; i < MAX_SIZE; ++i)
373  {
374  QLabel *label = new QLabel(this);
375  label->setFixedWidth(9);
376  label->setPixmap(QPixmap(":/tiny/lb_number0"));
377  layout->addWidget(label);
378  m_labels << label;
379  }
380  layout->addStretch(1);
381 
382  setLayout(layout);
383 
384  m_containWidget->setFixedSize(LEFT_SIDE_WIDTH_MIN, 400);
385  QVBoxLayout *containLayout = new QVBoxLayout(m_containWidget);
386  containLayout->setContentsMargins(0, 0, 0, 0);
387  containLayout->setSpacing(0);
388  containLayout->addWidget(createContainerWidget());
389 
390  m_scrollArea = new QScrollArea(this);
391 
392  const QString &background = TTK::UI::BackgroundStyle10;
393  QWidget *view = m_scrollArea->viewport();
394  view->setObjectName("Viewport");
395  view->setStyleSheet(QString("#%1{ %2 }").arg(view->objectName(), background));
396 
399  connect(m_tableWidget, SIGNAL(deleteItemAt(TTKIntList)), SLOT(removeItemAt(TTKIntList)));
400  connect(m_tableWidget, SIGNAL(cellDoubleClicked(int,int)), SLOT(itemDoubleClicked(int,int)));
401 
402  QWidget *playedListContainer = new QWidget(m_scrollArea);
403  QVBoxLayout *playedListLayout = new QVBoxLayout(playedListContainer);
404  playedListLayout->setContentsMargins(0, 0, 0, 0);
405  playedListLayout->setSpacing(0);
406  playedListLayout->addWidget(m_tableWidget);
407  playedListContainer->setLayout(playedListLayout);
408 
410  m_tableWidget->setMovedScrollBar(m_scrollArea->verticalScrollBar());
411 
412  containLayout->addWidget(m_scrollArea);
413  m_containWidget->setLayout(containLayout);
414 }
415 
417 {
419 #ifdef Q_OS_UNIX
420  topWidget->setObjectName("TopWidget");
421  topWidget->setStyleSheet(QString("#%1{ %2 }").arg(topWidget->objectName(), TTK::UI::BackgroundStyle10));
422 #endif
423  QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
424  topWidgetLayout->setSpacing(15);
425  QLabel *label = new QLabel(tr("Played List"), topWidget);
427 
428  QPushButton *shareButton = new QPushButton(this);
429  shareButton->setFixedSize(16, 16);
430  shareButton->setToolTip(tr("Share List"));
431  shareButton->setCursor(QCursor(Qt::PointingHandCursor));
432  shareButton->setStyleSheet(TTK::UI::TinyBtnShare);
433 
434  QPushButton *deleteButton = new QPushButton(this);
435  deleteButton->setFixedSize(16, 16);
436  deleteButton->setToolTip(tr("Clear List"));
437  deleteButton->setCursor(QCursor(Qt::PointingHandCursor));
438  deleteButton->setStyleSheet(TTK::UI::TinyBtnDelete);
439  connect(deleteButton, SIGNAL(clicked()), SLOT(clearItems()));
440 
441 #ifdef Q_OS_UNIX
442  shareButton->setFocusPolicy(Qt::NoFocus);
443  deleteButton->setFocusPolicy(Qt::NoFocus);
444 #endif
445 
446  QToolButton *closeButton = new QToolButton(this);
447  closeButton->setFixedSize(16, 16);
448  closeButton->setToolTip(tr("Close List"));
449  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
450  closeButton->setStyleSheet(TTK::UI::TinyBtnClose);
451  connect(closeButton, SIGNAL(clicked()), m_menu, SLOT(close()));
452 
453  topWidgetLayout->addWidget(label);
454  topWidgetLayout->addStretch(1);
455  topWidgetLayout->addWidget(shareButton);
456  topWidgetLayout->addWidget(deleteButton);
457  topWidgetLayout->addWidget(closeButton);
458  topWidget->setLayout(topWidgetLayout);
459 
460  return topWidget;
461 }
462 
464 {
465  setPlaylistCount(m_songList.count());
467 }
468 
470 {
471  if(count >= 1000)
472  {
473  for(int i = MAX_SIZE - 1; i >= 0; --i)
474  {
475  m_labels[i]->setPixmap(QPixmap(QString(":/tiny/lb_number%1").arg(9)));
476  }
477  }
478  else
479  {
480  for(int i = MAX_SIZE - 1; i >= 0; --i)
481  {
482  m_labels[i]->setPixmap(QPixmap(QString(":/tiny/lb_number%1").arg(count % 10)));
483  count /= 10;
484  }
485  }
486 }
487 
489 {
491  m_songList.clear();
492  setPlaylistCount(0);
493 
495 }
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.
const MusicPlayItemList & queueList() const noexcept
static MusicApplication * instance()
static const QString FontStyle03
#define TTK_LOW_LEVEL
Definition: ttkglobal.h:332
QString path() const noexcept
Definition: musicsong.h:89
static constexpr const char * TinyBtnShare
virtual void selectRow(int index) overridefinal
void removeItemAt(const TTKIntList &rows)
bool isEmpty() const noexcept
MusicSongsListPlayedTableWidget * m_tableWidget
MusicToolMenu * m_menu
static constexpr int MAX_SIZE
void playIndexBy(int row)
The class of the app main widget.
static constexpr const char * BtnPlayedList
bool remove(int index)
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
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
#define qAsConst
Definition: ttkqtglobal.h:57
void removeQueue() noexcept
The class of the played list pop widget.
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:189
virtual void setSongsList(MusicSongList *songs)
#define TTK_NORMAL_LEVEL
Definition: ttkglobal.h:333
QString currentMediaPath(int index) const
The class of the songs played queue list table widget.
#define TTK_SLOT
Definition: ttkqtglobal.h:177
static const QString ColorStyle08
Definition: musicuiobject.h:58
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
void setCurrentIndex(int index)
static const QString BackgroundStyle10
void updatePlayedRows(const TTK::IndexPropertyList &rows)
void append(const MusicSongList &songs)
void setPlaylist(MusicPlaylist *playlist)
int currentIndex() const noexcept
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 update(const TTK::IndexPropertyList &rows)
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:174