TTKMusicPlayer  4.3.0.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 
6  m_songsPlayWidget(nullptr)
7 {
8  setSelectionMode(QAbstractItemView::ExtendedSelection);
9  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
10  setColumnCount(5);
11 
12  QHeaderView *headerView = horizontalHeader();
13  headerView->resizeSection(0, 20);
14  headerView->resizeSection(1, 197);
15  headerView->resizeSection(2, 25);
16  headerView->resizeSection(3, 25);
17  headerView->resizeSection(4, 45);
18 
19  TTK::Widget::setTransparent(this, 255);
20 }
21 
23 {
24  removeItems();
25  delete m_songsPlayWidget;
26 }
27 
28 void MusicSongsListPlayedTableWidget::updateSongsList(const MusicSongList &songs)
29 {
30  const int count = rowCount();
31  setRowCount(songs.count());
32 
33  QHeaderView *headerView = horizontalHeader();
34  for(int i = count; i < songs.count(); ++i)
35  {
36  const MusicSong &v = songs[i];
37 
38  QTableWidgetItem *item = new QTableWidgetItem;
39  setItem(i, 0, item);
40 
41  item = new QTableWidgetItem;
42  item->setToolTip(v.name());
43  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 15));
44  item->setForeground(QColor(TTK::UI::Color01));
45  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
46  setItem(i, 1, item);
47 
48  item = new QTableWidgetItem;
49  setItem(i, 2, item);
50 
51  item = new QTableWidgetItem;
52  setItem(i, 3, item);
53 
54  item = new QTableWidgetItem(v.duration());
55  item->setForeground(QColor(TTK::UI::Color01));
56  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
57  setItem(i, 4, item);
58  }
59 
60  setFixedHeight(qMax(365, totalRowHeight()));
61 }
62 
64 {
65  if(index < 0 || rowCount() <= 0)
66  {
67  return;
68  }
69 
71 
73  for(int i = 0; i < columnCount(); ++i)
74  {
75  delete takeItem(index, i);
76  }
77 
78  const QString &name = songName(index);
79 
82 
83  setSpan(index, 0, 1, 5);
84  setCellWidget(index, 0, m_songsPlayWidget);
85  m_playRowIndex = index;
86 
87  setFixedHeight(qMax(365, totalRowHeight()));
88 
89  if(scrollBar())
90  {
91  scrollBar()->setSliderPosition(index * 30);
92  }
93 }
94 
96 {
97  if(index < 0 || index >= rowCount())
98  {
99  return;
100  }
101 
102  QTableWidgetItem *it = item(index, 0);
103  if(it)
104  {
105  it->setIcon(QIcon(":/tiny/lb_playlater"));
106  }
107 }
108 
110 {
111  for(int i = 0; i < rowCount(); ++i)
112  {
113  QTableWidgetItem *it = item(i, 0);
114  if(it)
115  {
116  it->setIcon(QIcon());
117  }
118  }
119 }
120 
122 {
124 }
125 
127 {
128  if(m_playRowIndex >= rowCount() || m_playRowIndex < 0)
129  {
130  return;
131  }
132 
133  const QString &name = songName(m_playRowIndex);
134 
135  removeCellWidget(m_playRowIndex, 0);
136  delete takeItem(m_playRowIndex, 0);
137  clearSpans();
138 
139  QHeaderView *headerView = horizontalHeader();
140  QTableWidgetItem *item = new QTableWidgetItem;
141  setItem(m_playRowIndex, 0, item);
142 
143  item = new QTableWidgetItem;
144  item->setToolTip(name);
145  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 15));
146  item->setForeground(QColor(TTK::UI::Color01));
147  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
148 
149  setItem(m_playRowIndex, 1, item);
150  setItem(m_playRowIndex, 2, new QTableWidgetItem);
151  setItem(m_playRowIndex, 3, new QTableWidgetItem);
152 
153  item = new QTableWidgetItem((*m_songs)[m_playRowIndex].duration());
154  item->setForeground(QColor(TTK::UI::Color01));
155  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
156  setItem(m_playRowIndex, 4, item);
157 
158  delete m_songsPlayWidget;
159  m_songsPlayWidget = nullptr;
160 
161  setFixedHeight(qMax(365, totalRowHeight()));
162 }
163 
165 {
166  QTableWidgetItem *it = item(m_previousColorRow, 2);
167  if(it)
168  {
169  it->setIcon(QIcon());
170  }
171 
172  it = item(m_previousColorRow, 3);
173  if(it)
174  {
175  it->setIcon(QIcon());
176  }
177 
178  it = item(m_previousColorRow, 4);
179  if(it)
180  {
181  it->setIcon(QIcon());
182  it->setText((*m_songs)[m_previousColorRow].duration());
183  }
184 
186  if(it = item(row, 2))
187  {
188  it->setIcon(QIcon(":/contextMenu/btn_download"));
189  }
190 
191  if(it = item(row, 3))
192  {
193  it->setIcon(QIcon(":/tiny/btn_delete_normal"));
194  }
195 
196  if(it = item(row, 4))
197  {
198  it->setText({});
199  it->setIcon(QIcon(":/tiny/btn_more_normal"));
200  }
201 
202  if(column == 2 || column == 3 || column == 4)
203  {
204  setCursor(QCursor(Qt::PointingHandCursor));
205  }
206  else
207  {
208  unsetCursor();
209  }
210 
212 }
213 
215 {
216  if(row == m_playRowIndex)
217  {
218  return;
219  }
220 
221  switch(column)
222  {
223  case 2: showDownloadWidget(); break;
224  case 3: removeItemAt(); break;
225  case 4:
226  {
227  QMenu menu(this);
228  createMoreMenu(&menu);
229  menu.exec(QCursor::pos());
230  break;
231  }
232  default: break;
233  }
234 }
235 
237 {
238 // if(m_playRowIndex < 0)
239 // {
240 // return;
241 // }
242 
243  //Remove play widget
244  removeCellWidget(m_playRowIndex, 0);
245 
246  delete m_songsPlayWidget;
247  m_songsPlayWidget = nullptr;
248 
249  m_playRowIndex = -1;
250  //Remove all the original item
252  setColumnCount(5);
253 }
254 
256 {
257  const TTKIntList deletedRows(selectedRows());
258  if(deletedRows.isEmpty())
259  {
260  return;
261  }
262 
263  if(deletedRows.contains(m_playRowIndex) || deletedRows[0] < m_playRowIndex)
264  {
266  }
267 
268  for(int i = deletedRows.count() - 1; i >= 0; --i)
269  {
270  const int row = deletedRows[i];
271  removeRow(row);
272  m_songs->removeAt(row);
273  }
274 
275  setFixedHeight(qMax(365, totalRowHeight()));
276  Q_EMIT deleteItemAt(deletedRows);
277 }
278 
280 {
281  Q_UNUSED(event);
282  QMenu menu(this);
283  menu.setStyleSheet(TTK::UI::MenuStyle02);
284  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"), this, SLOT(playClicked()));
285 
287  menu.addAction(tr("Download More..."), this, SLOT(showDownloadWidget()))->setEnabled(!status);
288  menu.addSeparator();
289 
290  createMoreMenu(&menu);
291 
292  status = !(m_songs->isEmpty() || status);
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  menu.exec(QCursor::pos());
301 }
MusicSongsListPlayedWidget * m_songsPlayWidget
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
TTKIntList selectedRows() const
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
const char * name
Definition: http_parser.c:458
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path) noexcept
TTK_MODULE_EXPORT void setTransparent(QWidget *widget, int alpha)
void deleteItemAt(const TTKIntList &rows)
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:105
QString name() const noexcept
Definition: musicsong.h:81
static const QString MenuStyle02
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
void initialize(const QString &name)
virtual void itemCellEntered(int row, int column) overridefinal
QScrollBar * scrollBar() const noexcept
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.
virtual void updateSongsList(const MusicSongList &songs) overridefinal