TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicartistquerywidget.cpp
Go to the documentation of this file.
3 #include "musicqueryitemwidget.h"
4 #include "musicrightareawidget.h"
5 #include "musicpagequerywidget.h"
6 #include "musicratinglabel.h"
7 
8 #include <cmath>
10 
13  m_initialized(false),
14  m_pageQueryWidget(nullptr)
15 {
16  delete m_statusLabel;
17  m_statusLabel = nullptr;
18 
19  QWidget *function = new QWidget(m_mainWidget);
20  m_gridLayout = new QGridLayout(function);
21  m_gridLayout->setContentsMargins(0, 0, 0, 0);
22  function->setLayout(m_gridLayout);
23  m_mainWidget->layout()->addWidget(function);
24  m_container->show();
25 
27 
28  m_networkRequest = G_DOWNLOAD_QUERY_PTR->makeArtistMovieRequest(this);
29  connect(m_networkRequest, SIGNAL(createMovieItem(MusicResultDataItem)), SLOT(createArtistMvsItem(MusicResultDataItem)));
30 }
31 
33 {
34  delete m_gridLayout;
35 }
36 
38 {
41 }
42 
44 {
45  setCurrentValue(id);
46 }
47 
49 {
50  if(m_resizeWidgets.isEmpty())
51  {
52  return;
53  }
54 
55  for(const Data &data : qAsConst(m_resizeWidgets))
56  {
57  m_gridLayout->removeWidget(data.m_label);
58  }
59 
61  const int lineNumber = (QUERY_WIDGET_WIDTH - lineSize / 2) / lineSize;
62  for(int i = 0; i < m_resizeWidgets.count(); ++i)
63  {
64  m_gridLayout->addWidget(m_resizeWidgets[i].m_label, i / lineNumber, i % lineNumber, Qt::AlignLeft);
65  }
66 }
67 
69 {
70  if(!m_initialized)
71  {
72  m_initialized = true;
74  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
75 
77  }
78 
81  label->setShowCount(false);
82  label->setValueLabel(false);
83  label->setResultDataItem(item, G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this));
84 
86  const int lineNumber = (QUERY_WIDGET_WIDTH - lineSize / 2) / lineSize;
87  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignLeft);
88  m_resizeWidgets.append({label, label->font()});
89 }
90 
92 {
94 }
95 
97 {
101 }
102 
103 
104 
107  m_initialized(false),
108  m_pageQueryWidget(nullptr)
109 {
110  delete m_statusLabel;
111  m_statusLabel = nullptr;
112 
113  QWidget *function = new QWidget(m_mainWidget);
114  m_gridLayout = new QGridLayout(function);
115  m_gridLayout->setContentsMargins(0, 0, 0, 0);
116  function->setLayout(m_gridLayout);
117  m_mainWidget->layout()->addWidget(function);
118  m_container->show();
119 
121 
122  m_networkRequest = G_DOWNLOAD_QUERY_PTR->makeArtistAlbumRequest(this);
123  connect(m_networkRequest, SIGNAL(createAlbumItem(MusicResultDataItem)), SLOT(createArtistAlbumsItem(MusicResultDataItem)));
124 }
125 
127 {
128  delete m_gridLayout;
129 }
130 
132 {
135 }
136 
138 {
139  setCurrentValue(id);
140 }
141 
143 {
144  if(m_resizeWidgets.isEmpty())
145  {
146  return;
147  }
148 
149  for(const Data &data : qAsConst(m_resizeWidgets))
150  {
151  m_gridLayout->removeWidget(data.m_label);
152  }
153 
155  const int lineNumber = (QUERY_WIDGET_WIDTH - lineSize / 2) / lineSize;
156  for(int i = 0; i < m_resizeWidgets.count(); ++i)
157  {
158  m_gridLayout->addWidget(m_resizeWidgets[i].m_label, i / lineNumber, i % lineNumber, Qt::AlignLeft);
159  }
160 }
161 
163 {
164  if(!m_initialized)
165  {
166  m_initialized = true;
168  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
169 
171  }
172 
175  label->setShowTime(true);
176  label->setShowCount(false);
177  label->setResultDataItem(item, G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this));
178 
180  const int lineNumber = (QUERY_WIDGET_WIDTH - lineSize / 2) / lineSize;
181  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignLeft);
182  m_resizeWidgets.append({label, label->font()});
183 }
184 
186 {
188 }
189 
191 {
195 }
196 
197 
198 
201  m_artistAlbums(nullptr),
202  m_artistMvs(nullptr)
203 {
205  m_tableWidget->hide();
206 
208 
209  m_networkRequest = G_DOWNLOAD_QUERY_PTR->makeSongRequest(this);
210  connect(m_networkRequest, SIGNAL(downloadDataChanged(QString)), SLOT(queryAllFinished()));
211 }
212 
214 {
215  delete m_artistAlbums;
216  delete m_artistMvs;
217 }
218 
219 void MusicArtistQueryWidget::setCurrentValue(const QString &value)
220 {
224 }
225 
227 {
229  MusicAbstractQueryRequest *req = G_DOWNLOAD_QUERY_PTR->makeArtistRequest(this);
232 
233  connect(req, SIGNAL(downloadDataChanged(QString)), SLOT(queryArtistFinished()));
235 }
236 
238 {
240 
241  if(m_artistAlbums)
242  {
244  }
245 
246  if(m_artistMvs)
247  {
249  }
250 
251  if(m_resizeWidgets.isEmpty())
252  {
253  return;
254  }
255 
256  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() - WINDOW_WIDTH_MIN + 180;
257 
258  Data *data = &m_resizeWidgets[1];
259  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
260 
261  data = &m_resizeWidgets[2];
262  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width - 20));
263 
264  data = &m_resizeWidgets[3];
265  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
266 }
267 
269 {
270  if(m_tableWidget)
271  {
272  m_tableWidget->hide();
273  }
274 
275  if(m_infoLabel)
276  {
277  m_infoLabel->hide();
278  }
279 
280  delete m_artistAlbums;
281  m_artistAlbums = nullptr;
282 
283  delete m_artistMvs;
284  m_artistMvs = nullptr;
285 
286  if(index == 0 && m_tableWidget)
287  {
288  m_tableWidget->show();
289  }
290  else if(index == 1 && m_infoLabel)
291  {
292  m_infoLabel->show();
293  }
294  else if(index == 2)
295  {
297  m_container->addWidget(m_artistAlbums);
299  }
300  else if(index == 3)
301  {
303  m_container->addWidget(m_artistMvs);
305  }
306 
307  m_container->setCurrentIndex(index > 2 ? 2 : index);
308 }
309 
311 {
312  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
313  if(songInfos.isEmpty())
314  {
315  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_artist_found"));
316  }
317  else
318  {
319  bool hasItem = false;
320  for(const TTK::MusicSongInformation &info : qAsConst(songInfos))
321  {
322  if(m_value.contains(info.m_artistName))
323  {
324  hasItem = true;
325  setCurrentKey(info.m_artistId);
326  break;
327  }
328  }
329 
330  if(!hasItem)
331  {
332  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_artist_found"));
333  }
334  }
335 }
336 
338 {
340  if(!req)
341  {
342  return;
343  }
344 
345  const TTK::MusicSongInformationList &songInfos = req->items();
346  if(songInfos.isEmpty())
347  {
348  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_artist_found"));
349  }
350  else
351  {
353  }
354 }
355 
357 {
358  m_currentPlaylistItem = item;
359 
360  createLabels();
361 
362  if(m_resizeWidgets.isEmpty())
363  {
364  return;
365  }
366 
367  if(TTK::isCoverValid(item.m_coverUrl))
368  {
369  MusicCoverRequest *req = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
370  connect(req, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
371  req->startToRequest(item.m_coverUrl);
372  }
373 
374  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() - WINDOW_WIDTH_MIN + 180;
375 
376  Data *data = &m_resizeWidgets[0];
377  data->m_label->setText(tr("<font color=#158FE1> Artist > %1 </font>").arg(item.m_name));
378 
379  data = &m_resizeWidgets[1];
380  data->m_label->setToolTip(item.m_name);
381  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
382 
383  data = &m_resizeWidgets[2];
384  data->m_label->setToolTip(tr("NickName: %1").arg(item.m_nickName));
385  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width - 20));
386 
387  data = &m_resizeWidgets[3];
388  data->m_label->setToolTip(tr("Birth: %1").arg(item.m_time));
389  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
390 
391  m_infoLabel->setText(item.m_description);
392 }
393 
395 {
396  delete m_statusLabel;
397  m_statusLabel = nullptr;
398 
401  m_container->show();
402 
403  layout()->removeWidget(m_mainWidget);
404  QScrollArea *scrollArea = new QScrollArea(this);
406  layout()->addWidget(scrollArea);
407 
408  QWidget *function = new QWidget(m_mainWidget);
409  function->setStyleSheet(TTK::UI::CheckBoxStyle01 + TTK::UI::PushButtonStyle03);
410  QVBoxLayout *grid = new QVBoxLayout(function);
411 
412  QLabel *firstLabel = new QLabel(function);
413  grid->addWidget(firstLabel);
414  //
415  QWidget *topFuncWidget = new QWidget(function);
416  QHBoxLayout *topFuncLayout = new QHBoxLayout(topFuncWidget);
417 
418  m_iconLabel = new QLabel(topFuncWidget);
419  m_iconLabel->setPixmap(QPixmap(":/image/lb_warning").scaled(180, 180));
420  m_iconLabel->setFixedSize(210, 180);
421  //
422  QWidget *topLineWidget = new QWidget(topFuncWidget);
423  QVBoxLayout *topLineLayout = new QVBoxLayout(topLineWidget);
424  topLineLayout->setContentsMargins(10, 5, 5, 0);
425 
426  QLabel *artistLabel = new QLabel(topLineWidget);
427  QFont artistFont = artistLabel->font();
428  artistFont.setPixelSize(20);
429  artistLabel->setFont(artistFont);
430  artistLabel->setStyleSheet(TTK::UI::FontStyle01);
431  artistLabel->setText(TTK_DEFAULT_STR);
432 
433  QLabel *nickNameLabel = new QLabel(topLineWidget);
434  nickNameLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
435  nickNameLabel->setText(TTK_DEFAULT_STR);
436 
437  QLabel *birthLabel = new QLabel(topLineWidget);
438  birthLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
439  birthLabel->setText(TTK_DEFAULT_STR);
440 
441  topLineLayout->addWidget(artistLabel);
442  topLineLayout->addWidget(nickNameLabel);
443  topLineLayout->addWidget(birthLabel);
444  topLineWidget->setLayout(topLineLayout);
445 
446  QWidget *topButtonWidget = new QWidget(topFuncWidget);
447  topButtonWidget->setStyleSheet(TTK::UI::PushButtonStyle03);
448  QHBoxLayout *topButtonLayout = new QHBoxLayout(topButtonWidget);
449  topButtonLayout->setContentsMargins(0, 0, 0, 0);
450 
451  QPushButton *playAllButton = new QPushButton(tr("Play All"), topButtonWidget);
452  QPushButton *shareButton = new QPushButton(tr("Share"), topButtonWidget);
453 
454  playAllButton->setIcon(QIcon(":/contextMenu/btn_play_white"));
455  playAllButton->setIconSize(QSize(14, 14));
456  playAllButton->setCursor(QCursor(Qt::PointingHandCursor));
457  shareButton->setCursor(QCursor(Qt::PointingHandCursor));
458  playAllButton->setFixedSize(90, 30);
459  shareButton->setFixedSize(55, 30);
460 
461  topButtonLayout->addWidget(playAllButton);
462  topButtonLayout->addWidget(shareButton);
463  topButtonLayout->addStretch(1);
464  topButtonWidget->setLayout(topButtonLayout);
465  topLineLayout->addWidget(topButtonWidget);
466 
467  connect(playAllButton, SIGNAL(clicked()), SLOT(playAllButtonClicked()));
468  connect(shareButton, SIGNAL(clicked()), SLOT(shareButtonClicked()));
469  //
470  QWidget *topRightWidget = new QWidget(topFuncWidget);
471  QGridLayout *topRightLayout = new QGridLayout(topRightWidget);
472  topRightLayout->setContentsMargins(0, 0, 0, 0);
473  topRightLayout->setSpacing(0);
474 
475  QLabel *numberLabel = new QLabel(topRightWidget);
476  numberLabel->setAlignment(Qt::AlignCenter);
477  numberLabel->setStyleSheet(TTK::UI::FontStyle06 + TTK::UI::ColorStyle11);
478 
479  const int number = 7 + TTK::random(3);
480  numberLabel->setText(QString("%1.%2").arg(number).arg(TTK::random(10)));
481  topRightLayout->addWidget(numberLabel, 0, 0);
482  topRightLayout->addWidget(new MusicRatingLabel(std::ceil(number / 2.0), topRightWidget), 0, 1, 1, 6);
483 
484  QLabel *numberTextLabel = new QLabel(tr("Score:"), topRightWidget);
485  topRightLayout->addWidget(numberTextLabel, 1, 0);
486  topRightLayout->addWidget(new MusicRatingLabel(topRightWidget), 1, 1, 1, 6);
487 
488  QLabel *marginBottmLabel = new QLabel(topRightWidget);
489  marginBottmLabel->setFixedHeight(40);
490  topRightLayout->addWidget(marginBottmLabel, 2, 0);
491  topRightWidget->setLayout(topRightLayout);
492 
493  QRCodeQWidget *code = new QRCodeQWidget({}, QSize(90, 90), topRightWidget);
494  code->setMargin(2);
495  code->setIcon(":/image/lb_app_logo", 0.23);
496  topRightLayout->addWidget(code, 3, 2, 1, 6);
497 
498  topFuncLayout->addWidget(m_iconLabel);
499  topFuncLayout->addWidget(topLineWidget);
500  topFuncLayout->addWidget(topRightWidget);
501  topFuncWidget->setLayout(topFuncLayout);
502  grid->addWidget(topFuncWidget);
503  //
504  QWidget *functionWidget = new QWidget(this);
505  functionWidget->setStyleSheet(TTK::UI::PushButtonStyle03);
506  QHBoxLayout *hLayout = new QHBoxLayout(functionWidget);
507 
508  m_songButton = new QPushButton(functionWidget);
509  m_songButton->setText(tr("SongItems"));
510  m_songButton->setFixedSize(100, 25);
511  m_songButton->setCursor(QCursor(Qt::PointingHandCursor));
512  hLayout->addWidget(m_songButton);
513 
514  QPushButton *infoButton = new QPushButton(functionWidget);
515  infoButton->setText(tr("Info"));
516  infoButton->setFixedSize(100, 25);
517  infoButton->setCursor(QCursor(Qt::PointingHandCursor));
518  hLayout->addWidget(infoButton);
519 
520  QPushButton *albumsButton = new QPushButton(functionWidget);
521  albumsButton->setText(tr("Albums"));
522  albumsButton->setFixedSize(100, 25);
523  albumsButton->setCursor(QCursor(Qt::PointingHandCursor));
524  hLayout->addWidget(albumsButton);
525 
526  QPushButton *mvsButton = new QPushButton(functionWidget);
527  mvsButton->setText(tr("Movies"));
528  mvsButton->setFixedSize(100, 25);
529  mvsButton->setCursor(QCursor(Qt::PointingHandCursor));
530 
531  hLayout->addWidget(mvsButton);
532  hLayout->addStretch(1);
533  functionWidget->setLayout(hLayout);
534 
535  QButtonGroup *buttonGroup = new QButtonGroup(this);
536  buttonGroup->addButton(m_songButton, 0);
537  buttonGroup->addButton(infoButton, 1);
538  buttonGroup->addButton(albumsButton, 2);
539  buttonGroup->addButton(mvsButton, 3);
540  QtButtonGroupConnect(buttonGroup, this, setCurrentIndex, TTK_SLOT);
541 
542 #ifdef Q_OS_UNIX
543  playAllButton->setFocusPolicy(Qt::NoFocus);
544  shareButton->setFocusPolicy(Qt::NoFocus);
545  m_songButton->setFocusPolicy(Qt::NoFocus);
546  infoButton->setFocusPolicy(Qt::NoFocus);
547  albumsButton->setFocusPolicy(Qt::NoFocus);
548  mvsButton->setFocusPolicy(Qt::NoFocus);
549 #endif
550  grid->addWidget(functionWidget);
551  grid->addWidget(m_container);
552  grid->addStretch(1);
553 
554  function->setLayout(grid);
555  m_mainWidget->layout()->addWidget(function);
556 
557  m_resizeWidgets.append({firstLabel, firstLabel->font()});
558  m_resizeWidgets.append({artistLabel, artistLabel->font()});
559  m_resizeWidgets.append({nickNameLabel, nickNameLabel->font()});
560  m_resizeWidgets.append({birthLabel, birthLabel->font()});
561 }
static MusicRightAreaWidget * instance()
const TTK::MusicSongInformationList & items() const noexcept
void setQueryInput(MusicAbstractQueryRequest *query)
virtual void setCurrentKey(const QString &id) overridefinal
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
The class of the search result data item.
virtual void setCurrentValue(const QString &value) overridefinal
The class of the artist albums query widget.
void setValueLabel(bool v) noexcept
MusicArtistAlbumsQueryWidget * m_artistAlbums
void setQueryMode(QueryMode mode) noexcept
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
static const QString FontStyle03
MusicPageQueryWidget * m_pageQueryWidget
MusicArtistQueryWidget(QWidget *parent=nullptr)
static bool isCoverValid(const QString &url) noexcept
int pageTotalSize() const noexcept
MusicPageQueryWidget * m_pageQueryWidget
virtual void startToRequest(const QString &url)=0
The class of the artist mvs query widget.
static const QString CheckBoxStyle01
CheckBox.
MusicArtistMvsQueryWidget(QWidget *parent=nullptr)
static const QString ColorStyle04
Definition: musicuiobject.h:46
static constexpr int LINE_SPACING_SIZE
void setIcon(const QString &path, float percent)
void createArtistAlbumsItem(const MusicResultDataItem &item)
virtual void setCurrentValue(const QString &value)
static const QString FontStyle01
Font.
void setMargin(const int margin)
The class of the query item table widget.
void downloadFinished(const QByteArray &bytes)
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
Definition: ttktime.cpp:14
MusicAbstractQueryRequest * queryInput() const
void createArtistItem(const MusicResultDataItem &item)
#define qAsConst
Definition: ttkqtglobal.h:57
static const QString FontStyle06
void setShowTime(bool v) noexcept
virtual void setCurrentValue(const QString &value) overridefinal
static const QString PushButtonStyle03
The class of the qr code widget.
Definition: qrcodewidget.h:31
virtual void setCurrentKey(const QString &id) overridefinal
The class of the page query widget.
virtual void setCurrentKey(const QString &id) overridefinal
virtual void startToPage(int offset)
MusicArtistMvsQueryWidget * m_artistMvs
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
void page(int index, int total)
#define TTK_SLOT
Definition: ttkqtglobal.h:177
virtual void resizeGeometry() overridefinal
void showAlbumFound(const QString &text, const QString &id)
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
virtual void resizeGeometry() overridefinal
virtual void resizeGeometry() overridefinal
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:115
The class of the rating label.
The class of the item query widget base.
void setResultDataItem(const MusicResultDataItem &item, MusicCoverRequest *cover)
Definition: inftrees.h:24
void setShowCount(bool v) noexcept
QWidget * createPageWidget(QWidget *parent, int total)
MusicArtistAlbumsQueryWidget(QWidget *parent=nullptr)
void createArtistMvsItem(const MusicResultDataItem &item)
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:172
MusicAbstractQueryRequest * m_networkRequest
virtual void startToSearchByValue(const QString &value) overridefinal
static const QString ColorStyle11
Definition: musicuiobject.h:67
virtual void setCurrentValue(const QString &value) overridefinal
#define G_DOWNLOAD_QUERY_PTR
MusicItemQueryTableWidget * m_tableWidget
#define QUERY_WIDGET_WIDTH
The class of the cover data download request.
virtual void startToSearch(const QString &value)=0
The class of the abstract query data from net.
virtual void resizeGeometry() overridefinal
MusicSongSharingWidget::Module m_shareType
void currentItemClicked(const MusicResultDataItem &item)
void currentItemClicked(const MusicResultDataItem &item)
The class of the music song information.
Definition: musicobject.h:300
void showMovieSearchedFound(const QString &name, const QString &id)
#define G_SETTING_PTR
The class of the square query item widget.