TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicitemquerytablewidget.cpp
Go to the documentation of this file.
4 #include "musictoastlabel.h"
5 #include "musicrightareawidget.h"
6 
8  : MusicQueryTableWidget(parent)
9 {
10  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
11  setColumnCount(8);
12 
13  QHeaderView *headerView = horizontalHeader();
14  headerView->resizeSection(0, 30);
15  headerView->resizeSection(1, 342);
16  headerView->resizeSection(2, 110);
17  headerView->resizeSection(3, 47);
18  headerView->resizeSection(4, 26);
19  headerView->resizeSection(5, 26);
20  headerView->resizeSection(6, 26);
21  headerView->resizeSection(7, 26);
22 }
23 
25 {
26  removeItems();
27 }
28 
30 {
31  if(!G_NETWORK_PTR->isOnline())
32  {
33  removeItems();
34  return;
35  }
36 
38 }
39 
41 {
42  if(!isValid(row))
43  {
44  return;
45  }
46 
47  MusicDownloadWidget *widget = new MusicDownloadWidget(this);
48  widget->initialize(m_networkRequest, row);
49  widget->show();
50 }
51 
53 {
54  if(column <= 0 || row < 0 || row >= rowCount() - 1)
55  {
56  return;
57  }
58 
59  addSearchMusicToPlaylist(row, true);
60 }
61 
63 {
64  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
65  const TTKIntList &list = checkedIndexList();
66  if(list.isEmpty())
67  {
68  MusicToastLabel::popup(tr("Please select one item first"));
69  return;
70  }
71 
72  for(int i = 0; i < list.count(); ++i)
73  {
74  const int index = list[i];
75  if(index >= songInfos.count())
76  {
77  continue;
78  }
79 
80  downloadDataFrom(&songInfos[index], play && (i == 0 /* first item row */));
81  }
82 }
83 
85 {
86  const TTKIntList &list = checkedIndexList();
87  if(list.isEmpty())
88  {
89  MusicToastLabel::popup(tr("Please select one item first"));
90  return;
91  }
92 
94  widget.initialize(m_networkRequest, list);
95  widget.exec();
96 }
97 
99 {
100  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
101  QHeaderView *headerView = horizontalHeader();
102  headerView->resizeSection(1, 342 + (width - WINDOW_WIDTH_MIN) / 2.0);
103  headerView->resizeSection(2, 110 + (width - WINDOW_WIDTH_MIN) / 2.0);
104 
105  for(int i = 0; i < rowCount(); ++i)
106  {
107  QTableWidgetItem *it = item(i, 1);
108  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
109 
110  it = item(i, 2);
111  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
112  }
113 }
114 
116 {
117  const int row = currentRow();
118  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
119  if(!isValid(row) || row >= songInfos.count())
120  {
121  return;
122  }
123 
124  const TTK::MusicSongInformation &info = songInfos[row];
125  switch(action->data().toInt())
126  {
127  case 0: addSearchMusicToPlaylist(row, true); break;
128  case 1: addSearchMusicToPlaylist(row, false); break;
129  case 2: downloadQueryResult(row); break;
133  case 6: MusicRightAreaWidget::instance()->showSongSearchedFound(item(row, 1)->toolTip()); break;
134  default: break;
135  }
136 }
137 
138 void MusicItemQueryTableWidget::resizeEvent(QResizeEvent *event)
139 {
141  resizeSection();
142 }
143 
144 void MusicItemQueryTableWidget::contextMenuEvent(QContextMenuEvent *event)
145 {
146  MusicQueryTableWidget::contextMenuEvent(event);
147 
148  QMenu menu;
149  menu.setStyleSheet(TTK::UI::MenuStyle02);
150 
151  const int row = currentRow();
152  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
153  if(!isValid(row) || row >= songInfos.count())
154  {
155  return;
156  }
157 
158  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"))->setData(0);
159  menu.addAction(tr("Add to list"))->setData(1);
160  menu.addAction(tr("Download More..."))->setData(2);
161 
162  menu.addSeparator();
163 
164  const TTK::MusicSongInformation &info = songInfos[row];
165  menu.addAction(tr("Search '%1'").arg(info.m_artistName))->setData(3);
166  menu.addAction(tr("Search '%1'").arg(info.m_songName))->setData(4);
167  menu.addAction(tr("Search '%1'").arg(info.m_albumName))->setData(5);
168  menu.addAction(tr("Search '%1 - %2'").arg(info.m_artistName, info.m_songName))->setData(6);
169  connect(&menu, SIGNAL(triggered(QAction*)), SLOT(menuActionChanged(QAction*)));
170 
171  menu.exec(QCursor::pos());
172 }
173 
175 {
177  if(column == 5 || column == 6 || column == 7)
178  {
179  setCursor(QCursor(Qt::PointingHandCursor));
180  }
181  else
182  {
183  unsetCursor();
184  }
185 }
186 
188 {
190 
191  switch(column)
192  {
193  case 5: addSearchMusicToPlaylist(row, true); break;
194  case 6: addSearchMusicToPlaylist(row, false); break;
195  case 7: downloadQueryResult(row); break;
196  default: break;
197  }
198 }
199 
201 {
203  setColumnCount(8);
204 }
205 
207 {
208  const int count = rowCount();
209  setRowCount(count + 1);
210 
211  QHeaderView *headerView = horizontalHeader();
212  QTableWidgetItem *item = new QTableWidgetItem;
213  item->setData(TTK_CHECKED_ROLE, Qt::Unchecked);
214  setItem(count, 0, item);
215 
216  item = new QTableWidgetItem;
217  item->setToolTip(TTK::generateSongName(songItem.m_songName, songItem.m_artistName));
218  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
219  item->setForeground(QColor(TTK::UI::Color02));
220  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
221  setItem(count, 1, item);
222 
223  item = new QTableWidgetItem;
224  item->setToolTip(songItem.m_albumName);
225  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
226  item->setForeground(QColor(TTK::UI::Color02));
227  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
228  setItem(count, 2, item);
229 
230  item = new QTableWidgetItem(songItem.m_duration);
231  item->setForeground(QColor(TTK::UI::Color02));
232  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
233  setItem(count, 3, item);
234 
235  item = new QTableWidgetItem;
236  item->setIcon(QIcon(":/tiny/lb_server_type"));
237  item->setToolTip(songItem.m_type);
238  setItem(count, 4, item);
239 
240  item = new QTableWidgetItem;
241  item->setIcon(QIcon(":/contextMenu/btn_play"));
242  setItem(count, 5, item);
243 
244  item = new QTableWidgetItem;
245  item->setIcon(QIcon(":/contextMenu/btn_add"));
246  setItem(count, 6, item);
247 
248  item = new QTableWidgetItem;
249  item->setIcon(QIcon(":/contextMenu/btn_download"));
250  setItem(count, 7, item);
251 
252  setFixedHeight(rowHeight(0) * (rowCount() + 1));
253 }
254 
256 {
257  if(!isValid(row))
258  {
259  MusicToastLabel::popup(tr("Please select one item first"));
260  return;
261  }
262 
263  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
264  if(row >= songInfos.count())
265  {
266  return;
267  }
268 
269  downloadDataFrom(&songInfos[row], play);
270 }
271 
273 {
274  if(!G_NETWORK_PTR->isOnline())
275  {
276  MusicToastLabel::popup(tr("No resource found"));
277  return false;
278  }
279 
281 
282  if(info->m_songProps.isEmpty())
283  {
284  MusicToastLabel::popup(tr("No resource found"));
285  return false;
286  }
287 
288  const TTK::MusicSongProperty &prop = info->m_songProps.front();
289 
290  MusicResultDataItem item;
292  item.m_time = info->m_duration;
293  item.m_id = info->m_songId;
294  item.m_nickName = prop.m_url;
295  item.m_description = prop.m_format;
296  item.m_count = prop.m_size;
297  item.m_title = play ? MUSIC_PLAY_NOW : MUSIC_PLAY_LATER;
298 
299  if(m_networkRequest)
300  {
301  item.m_id = m_networkRequest->queryServer() + item.m_id;
302  }
303 
305  return true;
306 }
static MusicRightAreaWidget * instance()
The class of the download batch widget.
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:105
void addSearchMusicToPlaylist(int row, bool play)
The class of the search result data item.
The class of the download widget.
virtual void resizeEvent(QResizeEvent *event) override
The class of the music song property.
Definition: musicobject.h:225
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
#define QtItemSetTextAlignment(p, a)
Item text alignment.
Definition: ttkqtcompat.h:45
static constexpr unsigned int Color02
Definition: musicuiobject.h:34
void showSongSearchedFound(const QString &text)
virtual void itemCellClicked(int row, int column) override
static void popup(const QString &text)
void initialize(const QString &name)
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
#define MUSIC_PLAY_NOW
virtual void itemDoubleClicked(int row, int column) override
QList< int > TTKIntList
Definition: ttkqtglobal.h:204
virtual void itemCellEntered(int row, int column) overridefinal
void showArtistFound(const QString &text, const QString &id)
void initialize(MusicAbstractQueryRequest *request, const TTKIntList &items)
static MusicSongsContainerWidget * instance()
virtual void removeItems() overridefinal
MusicItemQueryTableWidget(QWidget *parent=nullptr)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
virtual void itemCellEntered(int row, int column)
void showAlbumFound(const QString &text, const QString &id)
void addSongBufferToPlaylist(const MusicResultDataItem &item)
static const QString MenuStyle02
virtual void contextMenuEvent(QContextMenuEvent *event) override
virtual void downloadQueryResult(int row) override
virtual void removeItems() override
The class of the search result info item.
#define MUSIC_PLAY_LATER
#define G_NETWORK_PTR
virtual void startToSearchByText(const QString &text) overridefinal
virtual void resizeEvent(QResizeEvent *event) overridefinal
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:155
The class of the query table widget.
virtual void createResultItem(const MusicResultInfoItem &songItem) override
virtual void itemCellClicked(int row, int column) override
virtual void startToSearch(const QString &value)=0
const TTK::MusicSongInformationList & items() const
MusicAbstractQueryRequest * m_networkRequest
#define TTK_CHECKED_ROLE
The class of the music song information.
Definition: musicobject.h:283
#define TTK_BN_128
Definition: ttkglobal.h:353
#define G_SETTING_PTR