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