TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongsearchonlinewidget.cpp
Go to the documentation of this file.
4 #include "musicconnectionpool.h"
6 #include "musicrightareawidget.h"
7 #include "musictoastlabel.h"
8 #include "musicapplication.h"
9 #include "musicwidgetheaders.h"
10 
11 #include <QButtonGroup>
12 
15 {
16  setColumnCount(9);
17 
18  QHeaderView *headerView = horizontalHeader();
19  headerView->resizeSection(0, 30);
20  headerView->resizeSection(1, 273);
21  headerView->resizeSection(2, 105);
22  headerView->resizeSection(3, 105);
23  headerView->resizeSection(4, 55);
24  headerView->resizeSection(5, 23);
25  headerView->resizeSection(6, 26);
26  headerView->resizeSection(7, 26);
27  headerView->resizeSection(8, 26);
28 
29  G_CONNECTION_PTR->setValue(MusicQueryTableWidget::className(), this);
30 }
31 
33 {
34  removeItems();
35 }
36 
38 {
39  if(!G_NETWORK_PTR->isOnline()) //no network connection
40  {
41  removeItems();
42  return;
43  }
44 
46  if(!manager.fromFile(SEARCH_PATH_FULL))
47  {
48  return;
49  }
50 
51  MusicSearchRecordList records;
52  manager.readBuffer(records);
53 
54  MusicSearchRecord record;
55  record.m_name = text;
56  record.m_timestamp = QString::number(TTKDateTime::currentTimestamp());
57  records.insert(0, record);
58 
59  manager.reset();
60  manager.writeBuffer(records);
61 
63 
66 }
67 
69 {
70  if(!isValid(row))
71  {
72  return;
73  }
74 
75  MusicDownloadWidget *widget = new MusicDownloadWidget(this);
76  widget->initialize(m_networkRequest, row);
77  widget->show();
78 }
79 
81 {
82  if(!G_NETWORK_PTR->isOnline()) //no network connection
83  {
84  removeItems();
85  return;
86  }
87 
90 }
91 
93 {
94  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
95  QHeaderView *headerView = horizontalHeader();
96  headerView->resizeSection(1, 273 + (width - WINDOW_WIDTH_MIN) / 3.0);
97  headerView->resizeSection(2, 105 + (width - WINDOW_WIDTH_MIN) / 3.0);
98  headerView->resizeSection(3, 105 + (width - WINDOW_WIDTH_MIN) / 3.0);
99 
100  for(int i = 0; i < rowCount(); ++i)
101  {
102  QTableWidgetItem *it = item(i, 1);
103  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
104 
105  it = item(i, 2);
106  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
107 
108  it = item(i, 3);
109  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(3) - 31));
110  }
111 }
112 
114 {
116  if(column == 7 || column == 8)
117  {
118  setCursor(QCursor(Qt::PointingHandCursor));
119  }
120  else
121  {
122  unsetCursor();
123  }
124 }
125 
127 {
129  switch(column)
130  {
131  case 7: addSearchMusicToPlaylist(row, false); break;
132  case 8: downloadQueryResult(row); break;
133  default: break;
134  }
135 }
136 
138 {
139  if(column <= 0 || row < 0 || row >= rowCount() - 1)
140  {
141  return;
142  }
143 
144  addSearchMusicToPlaylist(row, true);
145 }
146 
148 {
150  setColumnCount(9);
151 }
152 
154 {
155  const int count = rowCount();
156  setRowCount(count + 1);
157 
158  QHeaderView *headerView = horizontalHeader();
159  QTableWidgetItem *item = new QTableWidgetItem;
160  item->setData(TTK_CHECKED_ROLE, Qt::Unchecked);
161  setItem(count, 0, item);
162 
163  item = new QTableWidgetItem;
164  item->setToolTip(songItem.m_songName);
165  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 15));
166  item->setForeground(QColor(TTK::UI::Color02));
167  setItem(count, 1, item);
168 
169  item = new QTableWidgetItem;
170  item->setToolTip(songItem.m_artistName);
171  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 30));
172  item->setForeground(QColor(TTK::UI::Color02));
173  setItem(count, 2, item);
174 
175  item = new QTableWidgetItem;
176  item->setToolTip(songItem.m_albumName);
177  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(3) - 30));
178  item->setForeground(QColor(TTK::UI::Color02));
179  setItem(count, 3, item);
180 
181  item = new QTableWidgetItem(songItem.m_duration);
182  item->setForeground(QColor(TTK::UI::Color02));
183  setItem(count, 4, item);
184 
185  item = new QTableWidgetItem;
186  item->setIcon(QIcon(randSimulation()));
187  setItem(count, 5, item);
188 
189  item = new QTableWidgetItem;
190  item->setIcon(QIcon(":/tiny/lb_server_type"));
191  item->setToolTip(songItem.m_type);
192  setItem(count, 6, item);
193 
194  item = new QTableWidgetItem;
195  item->setIcon(QIcon(":/contextMenu/btn_add"));
196  setItem(count, 7, item);
197 
198  item = new QTableWidgetItem;
199  item->setIcon(QIcon(":/contextMenu/btn_download"));
200  setItem(count, 8, item);
201 }
202 
204 {
205  const int row = currentRow();
206  if(!m_networkRequest || row < 0 || row >= rowCount() - 1)
207  {
208  return;
209  }
210 
211  const TTK::MusicSongInformationList songInfos(m_networkRequest->items());
212  const TTK::MusicSongInformation &info = songInfos[row];
213 
214  switch(action->data().toInt())
215  {
216  case 0: downloadQueryResult(row); break;
217  case 1: Q_EMIT restartToSearchQuery(info.m_songName); break;
218  case 2: MusicRightAreaWidget::instance()->showArtistFound(info.m_artistName, info.m_artistId); break;
219  case 3: Q_EMIT restartToSearchQuery(TTK::generateSongName(info.m_songName, info.m_artistName)); break;
220  case 4: addSearchMusicToPlaylist(row, true); break;
221  case 5: MusicRightAreaWidget::instance()->showAlbumFound(info.m_albumName, info.m_albumId); break;
222  default: break;
223  }
224 }
225 
226 void MusicSongSearchTableWidget::contextMenuEvent(QContextMenuEvent *event)
227 {
228  MusicItemSearchTableWidget::contextMenuEvent(event);
229 
230  QMenu menu(this);
231  m_actionGroup->addAction(menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play")))->setData(4);
232 
233  createContextMenu(menu);
234 
235  if(!m_actionGroup->actions().isEmpty())
236  {
237  const QString &albumName = (currentRow() != -1 && rowCount() > 0) ? item(currentRow(), 3)->toolTip() : QString();
238  QAction *lastAction = m_actionGroup->actions().back();
239  QAction *action = m_actionGroup->addAction(tr("Search '%1'").arg(albumName));
240  action->setData(5);
241  menu.insertAction(lastAction, action);
242  }
243  menu.exec(QCursor::pos());
244 }
245 
247 {
248  if(!G_NETWORK_PTR->isOnline()) //no network connection
249  {
250  MusicToastLabel::popup(tr("No resource found"));
251  return;
252  }
253 
254  if(!isValid(row))
255  {
256  MusicToastLabel::popup(tr("Please select one item first"));
257  return;
258  }
259 
260  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
261  if(row >= songInfos.count())
262  {
263  return;
264  }
265 
266  TTK::MusicSongInformation &songInfo = songInfos[row];
268 
269  if(songInfo.m_songProps.isEmpty())
270  {
271  MusicToastLabel::popup(tr("No resource found"));
272  return;
273  }
274 
275  const TTK::MusicSongProperty &prop = songInfo.m_songProps.front();
276 
277  MusicResultDataItem item;
278  item.m_name = TTK::generateSongName(this->item(row, 1)->toolTip(), this->item(row, 2)->toolTip());
279  item.m_updateTime = songInfo.m_duration;
280  item.m_id = songInfo.m_songId;
281  item.m_nickName = prop.m_url;
282  item.m_description = prop.m_format;
283  item.m_count = prop.m_size;
285 
286  if(m_networkRequest)
287  {
288  item.m_id = m_networkRequest->queryServer() + item.m_id;
289  }
290 
291  Q_EMIT songBufferToPlaylist(item);
292 }
293 
294 
295 
297  : QWidget(parent)
298 {
299  QVBoxLayout *boxLayout = new QVBoxLayout(this);
300  boxLayout->setContentsMargins(0, 0, 0, 0);
301  boxLayout->setSpacing(0);
302 
303  QWidget *toolWidget = new QWidget(this);
304  toolWidget->setFixedHeight(80);
305  QPalette plt(palette());
306  plt.setColor(QPalette::Background, Qt::white);
307  toolWidget->setAutoFillBackground(true);
308  toolWidget->setPalette(plt);
309 
311  boxLayout->addWidget(toolWidget);
312 #if !TTK_QT_VERSION_CHECK(5,0,0)
313  QWidget *containerWidget = new QWidget(this);
314  containerWidget->setAutoFillBackground(true);
315  containerWidget->setPalette(plt);
316 
317  QVBoxLayout *layout = new QVBoxLayout(containerWidget);
318  layout->setContentsMargins(0, 0, 0, 0);
319  layout->setSpacing(0);
320  layout->addWidget(m_tableWidget);
321  containerWidget->setLayout(layout);
322  boxLayout->addWidget(containerWidget);
323 #else
324  boxLayout->addWidget(m_tableWidget);
325 #endif
326  setLayout(boxLayout);
327 
328  createToolWidget(toolWidget);
329  connect(m_tableWidget, SIGNAL(restartToSearchQuery(QString)), MusicRightAreaWidget::instance(), SLOT(showSongSearchedFound(QString)));
330 }
331 
333 {
334  delete m_playButton;
335  delete m_textLabel;
336  delete m_tableWidget;
337 }
338 
340 {
341  setResizeLabelText(name);
342  if(!m_resizeWidgets.isEmpty())
343  {
344  TTKObjectCast(QCheckBox*, m_resizeWidgets[0])->setChecked(false);
345  }
346 
348 }
349 
351 {
352  setResizeLabelText(name);
353  if(!m_resizeWidgets.isEmpty())
354  {
355  TTKObjectCast(QCheckBox*, m_resizeWidgets[0])->setChecked(false);
356  }
357 
359 }
360 
362 {
363  setResizeLabelText(m_textLabel->toolTip());
365 }
366 
368 {
370  list.removeOne(m_tableWidget->rowCount() - 1);
371 
372  if(list.isEmpty())
373  {
374  MusicToastLabel::popup(tr("Please select one item first"));
375  return;
376  }
377 
378  if(index == 0)
379  {
380  for(int i = 0; i < list.count(); ++i)
381  {
382  m_tableWidget->addSearchMusicToPlaylist(list[i], i == 0);
383  }
384  }
385  else if(index == 1)
386  {
387  for(int row : qAsConst(list))
388  {
390  }
391  }
392  else if(index == 2)
393  {
395  if(!d)
396  {
397  return;
398  }
399 
401  widget.initialize(d, list);
402  widget.exec();
403  }
404 }
405 
407 {
408  QVBoxLayout *wLayout = new QVBoxLayout(widget);
409  wLayout->setContentsMargins(0, 0, 0, 0);
410  wLayout->setSpacing(0);
411  widget->setLayout(wLayout);
412 
413  QWidget *funcWidget = new QWidget(widget);
414  QHBoxLayout *funcLayout = new QHBoxLayout(funcWidget);
415  funcLayout->setContentsMargins(0, 0, 10, 0);
416  funcLayout->setSpacing(10);
417 
418  m_textLabel = new QLabel(this);
419  m_textLabel->setTextFormat(Qt::RichText);
420  m_textLabel->setText(tr("&nbsp;Find no result"));
421  m_textLabel->setStyleSheet(TTK::UI::ColorStyle03);
422  funcLayout->addWidget(m_textLabel);
423 
424  m_playButton = new QPushButton(tr("Play"), this);
425  m_playButton->setIcon(QIcon(":/contextMenu/btn_play_white"));
426  m_playButton->setIconSize(QSize(14, 14));
427  m_playButton->setFixedSize(70, 25);
429  m_playButton->setCursor(QCursor(Qt::PointingHandCursor));
430  funcLayout->addWidget(m_playButton);
431 
432  QPushButton *addButton = new QPushButton(tr("Add"), this);
433  addButton->setFixedSize(70, 25);
434  addButton->setStyleSheet(TTK::UI::PushButtonStyle03);
435  addButton->setCursor(QCursor(Qt::PointingHandCursor));
436  funcLayout->addWidget(addButton);
437 
438  QPushButton *downloadButton = new QPushButton(tr("Download"), this);
439  downloadButton->setFixedSize(70, 25);
440  downloadButton->setStyleSheet(TTK::UI::PushButtonStyle03);
441  downloadButton->setCursor(QCursor(Qt::PointingHandCursor));
442  funcLayout->addWidget(downloadButton);
443 
444  QButtonGroup *buttonGroup = new QButtonGroup(this);
445  buttonGroup->addButton(m_playButton, 0);
446  buttonGroup->addButton(addButton, 1);
447  buttonGroup->addButton(downloadButton, 2);
448  QtButtonGroupConnect(buttonGroup, this, buttonClicked, TTK_SLOT);
449  funcWidget->setLayout(funcLayout);
450  wLayout->addWidget(funcWidget);
451 
452  QHeaderView *headerView = m_tableWidget->horizontalHeader();
453  //
454  QWidget *labelWidget = new QWidget(widget);
455  QHBoxLayout *labelLayout = new QHBoxLayout(labelWidget);
456  labelLayout->setContentsMargins(7, 0, 10, 0);
457  labelLayout->setSpacing(0);
458  labelWidget->setStyleSheet(TTK::UI::BackgroundStyle09);
459 
460  QCheckBox *labelCheckBox = new QCheckBox(this);
461  labelCheckBox->setStyleSheet(TTK::UI::CheckBoxStyle01);
462  connect(labelCheckBox, SIGNAL(clicked(bool)), m_tableWidget, SLOT(checkedItemsState(bool)));
463  labelLayout->addWidget(labelCheckBox, headerView->sectionSize(0));
464  m_resizeWidgets << labelCheckBox;
465 
466 #ifdef Q_OS_UNIX
467  m_playButton->setFocusPolicy(Qt::NoFocus);
468  addButton->setFocusPolicy(Qt::NoFocus);
469  downloadButton->setFocusPolicy(Qt::NoFocus);
470  labelCheckBox->setFocusPolicy(Qt::NoFocus);
471 #endif
472 
473  QLabel *label1 = new QLabel(tr("Song"), this);
474  label1->setStyleSheet(TTK::UI::FontStyle01);
475  labelLayout->addWidget(label1, headerView->sectionSize(1));
476  m_resizeWidgets << label1;
477 
478  QLabel *label2 = new QLabel(tr("Artist"), this);
479  label2->setStyleSheet(TTK::UI::FontStyle01);
480  labelLayout->addWidget(label2, headerView->sectionSize(2));
481  m_resizeWidgets << label2;
482 
483  QLabel *label3 = new QLabel(tr("Album"), this);
484  label3->setStyleSheet(TTK::UI::FontStyle01);
485  labelLayout->addWidget(label3, headerView->sectionSize(3));
486  m_resizeWidgets << label3;
487 
488  QLabel *label4 = new QLabel(tr("Operator"), this);
489  label4->setStyleSheet(TTK::UI::FontStyle01);
490  labelLayout->addWidget(label4, headerView->sectionSize(4) + headerView->sectionSize(5) + headerView->sectionSize(6) * 3);
491  m_resizeWidgets << label3;
492 
493  labelWidget->setLayout(labelLayout);
494  wLayout->addWidget(labelWidget);
495 }
496 
498 {
499  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
500  if(!m_resizeWidgets.isEmpty())
501  {
502  m_resizeWidgets[1]->setFixedWidth(273 + (width - WINDOW_WIDTH_MIN) / 3.0);
503  m_resizeWidgets[2]->setFixedWidth(105 + (width - WINDOW_WIDTH_MIN) / 3.0);
504  m_resizeWidgets[3]->setFixedWidth(105 + (width - WINDOW_WIDTH_MIN) / 3.0);
505  }
506 
507  m_textLabel->setText(tr("&nbsp;find <font color=#158FE1> %1 </font> result").arg(TTK::Widget::elidedText(font(), name, Qt::ElideRight, 240 + width - WINDOW_WIDTH_MIN)));
508  m_textLabel->setToolTip(name);
509 }
static MusicRightAreaWidget * instance()
The class of the download batch widget.
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:112
virtual bool writeBuffer(const MusicSearchRecordList &items) overridefinal
The class of the search result data item.
virtual void searchActionClicked(QAction *action) overridefinal
The class of the download widget.
void initialize(MusicAbstractQueryRequest *request, int row)
void addSearchMusicToPlaylist(int row, bool play)
virtual void startToSearchByText(const QString &text) override
virtual void createResultItem(const MusicResultInfoItem &songItem) overridefinal
void startToSearchByText(const QString &name)
bool fromFile(const QString &name)
The class of the search item table widget.
The class of the music song property.
Definition: musicobject.h:223
static const QString CheckBoxStyle01
CheckBox.
void startToSearchByID(const QString &name)
MusicSongSearchTableWidget(QWidget *parent=nullptr)
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
virtual void startToSearchByText(const QString &text) overridefinal
void songBufferToPlaylist(const MusicResultDataItem &item)
static constexpr unsigned int Color02
Definition: musicuiobject.h:34
The class of the search history Config.
#define G_CONNECTION_PTR
static const QString FontStyle01
Font.
void setResizeLabelText(const QString &name)
virtual void startToSearchByID(const QString &value)
static void popup(const QString &text)
virtual bool readBuffer(MusicSearchRecordList &items) overridefinal
MusicAbstractQueryRequest * queryInput() const
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
#define MUSIC_PLAY_NOW
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
#define qAsConst
Definition: ttkqtglobal.h:53
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
const char * name
Definition: http_parser.c:458
The class of the song search online table widget.
static const QString PushButtonStyle03
void showArtistFound(const QString &text, const QString &id)
virtual void downloadQueryResult(int row) overridefinal
virtual void itemCellClicked(int row, int column) overridefinal
void startToSearchByID(const QString &text)
void initialize(MusicAbstractQueryRequest *request, const TTKIntList &items)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
static const QString BackgroundStyle09
virtual void itemCellEntered(int row, int column)
#define TTK_SLOT
Definition: ttkqtglobal.h:165
void showAlbumFound(const QString &text, const QString &id)
virtual void itemDoubleClicked(int row, int column) overridefinal
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:101
static const QString ColorStyle03
Definition: musicuiobject.h:43
static qint64 currentTimestamp()
Definition: ttktime.cpp:249
#define SEARCH_PATH_FULL
Definition: musicobject.h:138
virtual void removeItems() override
The class of the search result info item.
#define MUSIC_PLAY_LATER
The class of the searched record item.
virtual void removeItems() overridefinal
#define G_NETWORK_PTR
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:153
void restartToSearchQuery(const QString &name)
virtual void itemCellClicked(int row, int column) override
virtual void startToSearch(const QString &value)=0
The class of the abstract query download data from net.
const TTK::MusicSongInformationList & items() const
MusicSongSearchOnlineWidget(QWidget *parent=nullptr)
virtual void itemCellEntered(int row, int column) overridefinal
MusicSongSearchTableWidget * m_tableWidget
MusicAbstractQueryRequest * m_networkRequest
#define TTK_CHECKED_ROLE
The class of the music song information.
Definition: musicobject.h:281
#define TTK_BN_128
Definition: ttkglobal.h:348
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60