TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongslistplayedtablewidget.cpp
Go to the documentation of this file.
3 
4 #include <qmath.h>
5 
8  m_songsPlayWidget(nullptr)
9 {
10  setSelectionMode(QAbstractItemView::ExtendedSelection);
11  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
12  setColumnCount(5);
13 
14  QHeaderView *headerView = horizontalHeader();
15  headerView->resizeSection(0, 20);
16  headerView->resizeSection(1, 197);
17  headerView->resizeSection(2, 25);
18  headerView->resizeSection(3, 25);
19  headerView->resizeSection(4, 45);
20 
21  TTK::Widget::setTransparent(this, 255);
22 }
23 
25 {
26  removeItems();
27  delete m_songsPlayWidget;
28 }
29 
30 void MusicSongsListPlayedTableWidget::updateSongsList(const MusicSongList &songs)
31 {
32  const int count = rowCount();
33  setRowCount(songs.count());
34 
35  QHeaderView *headerView = horizontalHeader();
36  for(int i = count; i < songs.count(); ++i)
37  {
38  const MusicSong &v = songs[i];
39 
40  QTableWidgetItem *item = new QTableWidgetItem;
41  setItem(i, 0, item);
42 
43  item = new QTableWidgetItem;
44  item->setToolTip(v.name());
45  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 15));
46  item->setForeground(QColor(TTK::UI::Color01));
47  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
48  setItem(i, 1, item);
49 
50  item = new QTableWidgetItem;
51  setItem(i, 2, item);
52 
53  item = new QTableWidgetItem;
54  setItem(i, 3, item);
55 
56  item = new QTableWidgetItem(v.duration());
57  item->setForeground(QColor(TTK::UI::Color01));
58  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
59  setItem(i, 4, item);
60  }
61 
62  setFixedHeight(qMax(365, totalHeight()));
63 }
64 
66 {
67  if(index < 0 || rowCount() <= 0)
68  {
69  return;
70  }
71 
73 
75  for(int i = 0; i < columnCount(); ++i)
76  {
77  delete takeItem(index, i);
78  }
79 
80  const QString &name = !m_songs->isEmpty() ? m_songs->at(index).name() : QString();
81 
84 
85  setSpan(index, 0, 1, 5);
86  setCellWidget(index, 0, m_songsPlayWidget);
87  m_playRowIndex = index;
88 
89  setFixedHeight(qMax(365, totalHeight()));
90 
91  if(m_scrollBar)
92  {
93  m_scrollBar->setSliderPosition(index * 30);
94  }
95 }
96 
98 {
99  if(row < 0 || row >= rowCount())
100  {
101  return;
102  }
103 
104  QTableWidgetItem *it = item(row, 0);
105  if(it)
106  {
107  it->setIcon(QIcon(":/tiny/lb_playlater"));
108  }
109 }
110 
112 {
113  for(int i = 0; i < rowCount(); ++i)
114  {
115  QTableWidgetItem *it = item(i, 0);
116  if(it)
117  {
118  it->setIcon(QIcon());
119  }
120  }
121 }
122 
124 {
126 }
127 
129 {
130  if(m_playRowIndex >= rowCount() || m_playRowIndex < 0)
131  {
132  return;
133  }
134 
135  const QString &name = !m_songs->isEmpty() ? m_songs->at(m_playRowIndex).name() : QString();
136 
137  removeCellWidget(m_playRowIndex, 0);
138  delete takeItem(m_playRowIndex, 0);
139  clearSpans();
140 
141  QHeaderView *headerView = horizontalHeader();
142  QTableWidgetItem *item = new QTableWidgetItem;
143  setItem(m_playRowIndex, 0, item);
144 
145  item = new QTableWidgetItem;
146  item->setToolTip(name);
147  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 15));
148  item->setForeground(QColor(TTK::UI::Color01));
149  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
150 
151  setItem(m_playRowIndex, 1, item);
152  setItem(m_playRowIndex, 2, new QTableWidgetItem);
153  setItem(m_playRowIndex, 3, new QTableWidgetItem);
154 
155  item = new QTableWidgetItem((*m_songs)[m_playRowIndex].duration());
156  item->setForeground(QColor(TTK::UI::Color01));
157  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
158  setItem(m_playRowIndex, 4, item);
159 
160  delete m_songsPlayWidget;
161  m_songsPlayWidget = nullptr;
162 
163  setFixedHeight(qMax(365, totalHeight()));
164 }
165 
167 {
168  QTableWidgetItem *it = item(m_previousColorRow, 2);
169  if(it)
170  {
171  it->setIcon(QIcon());
172  }
173 
174  it = item(m_previousColorRow, 3);
175  if(it)
176  {
177  it->setIcon(QIcon());
178  }
179 
180  it = item(m_previousColorRow, 4);
181  if(it)
182  {
183  it->setIcon(QIcon());
184  it->setText((*m_songs)[m_previousColorRow].duration());
185  }
186 
188  if(it = item(row, 2))
189  {
190  it->setIcon(QIcon(":/contextMenu/btn_download"));
191  }
192 
193  if(it = item(row, 3))
194  {
195  it->setIcon(QIcon(":/tiny/btn_delete_normal"));
196  }
197 
198  if(it = item(row, 4))
199  {
200  it->setText({});
201  it->setIcon(QIcon(":/tiny/btn_more_normal"));
202  }
203 
204  if(column == 2 || column == 3 || column == 4)
205  {
206  setCursor(QCursor(Qt::PointingHandCursor));
207  }
208  else
209  {
210  unsetCursor();
211  }
212 
214 }
215 
217 {
218  if(row == m_playRowIndex)
219  {
220  return;
221  }
222 
223  switch(column)
224  {
225  case 2: showDownloadWidget(); break;
226  case 3: removeItemAt(); break;
227  case 4:
228  {
229  QMenu menu(this);
230  createMoreMenu(&menu);
231  menu.exec(QCursor::pos());
232  break;
233  }
234  default: break;
235  }
236 }
237 
239 {
240 // if(m_playRowIndex < 0)
241 // {
242 // return;
243 // }
244 
245  //Remove play widget
246  removeCellWidget(m_playRowIndex, 0);
247 
248  delete m_songsPlayWidget;
249  m_songsPlayWidget = nullptr;
250 
251  m_playRowIndex = -1;
252  //Remove all the original item
254  setColumnCount(5);
255 }
256 
258 {
259  const TTKIntList deletedList(selectedIndexList());
260  if(deletedList.isEmpty())
261  {
262  return;
263  }
264 
265  if(deletedList.contains(m_playRowIndex) || deletedList[0] < m_playRowIndex)
266  {
268  }
269 
270  for(int i = deletedList.count() - 1; i >= 0; --i)
271  {
272  const int index = deletedList[i];
273  removeRow(index);
274  m_songs->removeAt(index);
275  }
276 
277  setFixedHeight(qMax(365, totalHeight()));
278  Q_EMIT deleteItemAt(deletedList);
279 }
280 
282 {
283  Q_UNUSED(event);
284  QMenu menu(this);
285  menu.setStyleSheet(TTK::UI::MenuStyle02);
286  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"), this, SLOT(playClicked()));
287  menu.addAction(tr("Download More..."), this, SLOT(showDownloadWidget()));
288  menu.addSeparator();
289 
290  createMoreMenu(&menu);
291 
292  const bool status = !(m_songs->isEmpty() || TTK::String::isNetworkUrl(currentSongPath()));
293  menu.addAction(tr("Song Info..."), this, SLOT(showFileInformation()))->setEnabled(status);
294  menu.addAction(QIcon(":/contextMenu/btn_local_file"), tr("Open File Dir"), this, SLOT(openFileDir()))->setEnabled(status);
295  menu.addAction(QIcon(":/contextMenu/btn_ablum"), tr("Ablum"), this, SLOT(showAlbumQueryWidget()));
296  menu.addSeparator();
297 
298  menu.addAction(QIcon(":/contextMenu/btn_delete"), tr("Delete"), this, SLOT(removeItemAt()));
299  menu.addSeparator();
300 
301  menu.exec(QCursor::pos());
302 }
MusicSongsListPlayedWidget * m_songsPlayWidget
void deleteItemAt(const TTKIntList &index)
MusicSongsListPlayedTableWidget(QWidget *parent=nullptr)
virtual void selectRow(int index) overridefinal
#define QtItemSetTextAlignment(p, a)
Item text alignment.
Definition: ttkqtcompat.h:45
virtual void itemCellClicked(int row, int column) overridefinal
QList< int > TTKIntList
Definition: ttkqtglobal.h:204
const char * name
Definition: http_parser.c:458
TTK_MODULE_EXPORT void setTransparent(QWidget *widget, int alpha)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
virtual void itemCellEntered(int row, int column)
QString duration() const noexcept
Definition: musicsong.h:106
QString name() const noexcept
Definition: musicsong.h:82
static const QString MenuStyle02
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
void initialize(const QString &name)
virtual void itemCellEntered(int row, int column) overridefinal
TTKIntList selectedIndexList() const
static constexpr unsigned int Color01
Color QRgb.
Definition: musicuiobject.h:32
The class of the music song info.
Definition: musicsong.h:28
The class of the song list played widget.
The class of the songs list abstract table widget.
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path)
virtual void updateSongsList(const MusicSongList &songs) overridefinal