TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicplaylistquerywidget.cpp
Go to the documentation of this file.
2 #include "musiccoverrequest.h"
6 #include "musictinyuiobject.h"
8 #include "musicpagequerywidget.h"
9 
10 #include <QGridLayout>
11 
12 static constexpr int WIDTH_LABEL_SIZE = 150;
13 static constexpr int HEIGHT_LABEL_SIZE = 200;
14 static constexpr int LINE_SPACING_SIZE = 200;
15 
17  : QLabel(parent)
18 {
19  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
20 
21  m_topListenButton = new QPushButton(this);
22  m_topListenButton->setGeometry(0, 0, WIDTH_LABEL_SIZE, 20);
23  m_topListenButton->setIcon(QIcon(":/tiny/btn_listen_hover"));
26 
27  m_playButton = new QPushButton(this);
28  m_playButton->setGeometry(110, 110, 30, 30);
29  m_playButton->setCursor(Qt::PointingHandCursor);
30  m_playButton->setStyleSheet(TTK::UI::TinyBtnPlaylist);
31  connect(m_playButton, SIGNAL(clicked()), SLOT(currentItemClicked()));
32 
33 #ifdef Q_OS_UNIX
34  m_topListenButton->setFocusPolicy(Qt::NoFocus);
35  m_playButton->setFocusPolicy(Qt::NoFocus);
36 #endif
37 
38  m_iconLabel = new QLabel(this);
39  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
40 
41  m_nameLabel = new QLabel(this);
42  m_nameLabel->setGeometry(0, 150, WIDTH_LABEL_SIZE, 25);
43  m_nameLabel->setText(TTK_DEFAULT_STR);
44 
45  m_creatorLabel = new QLabel(this);
46  m_creatorLabel->setGeometry(0, 175, WIDTH_LABEL_SIZE, 25);
47  m_creatorLabel->setText("by anonymous");
48 }
49 
51 {
52  delete m_topListenButton;
53  delete m_playButton;
54  delete m_iconLabel;
55  delete m_nameLabel;
56  delete m_creatorLabel;
57 }
58 
60 {
61  m_itemData = item;
62  m_nameLabel->setToolTip(item.m_name);
63  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
64  m_creatorLabel->setToolTip("by " + item.m_nickName);
65  m_creatorLabel->setText(TTK::Widget::elidedText(m_creatorLabel->font(), m_creatorLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
66 
67  bool ok = false;
68  const int count = item.m_count.toInt(&ok);
69  if(ok)
70  {
71  if(count >= 10000)
72  {
73  m_topListenButton->setText(tr("%1W").arg(count / 10000));
74  }
75  else
76  {
77  m_topListenButton->setText(QString::number(count));
78  }
79  }
80  else
81  {
82  m_topListenButton->setText(item.m_count);
83  }
84 
86  {
87  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
88  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
89  d->startToRequest(item.m_coverUrl);
90  }
91 }
92 
94 {
95  if(bytes.isEmpty())
96  {
97  TTK_ERROR_STREAM("Input byte data is empty");
98  return;
99  }
100 
101  MusicImageRenderer *render = new MusicImageRenderer(sender());
102  connect(render, SIGNAL(renderFinished(QPixmap)), SLOT(renderFinished(QPixmap)));
103  render->setInputData(bytes, m_iconLabel->size());
104  render->start();
105 }
106 
108 {
109  m_iconLabel->setPixmap(data);
110  m_topListenButton->raise();
111  m_playButton->raise();
112 }
113 
115 {
117 }
118 
119 
120 
123  m_initialized(false),
124  m_categoryChanged(false),
125  m_gridLayout(nullptr),
126  m_pageQueryWidget(nullptr),
127  m_infoWidget(nullptr),
128  m_categoryButton(nullptr)
129 {
130  m_container->show();
131  layout()->removeWidget(m_mainWindow);
132  layout()->addWidget(m_container);
133  m_container->addWidget(m_mainWindow);
134 
135  m_networkRequest = G_DOWNLOAD_QUERY_PTR->makePlaylistRequest(this);
137 }
138 
140 {
141  delete m_infoWidget;
142  delete m_gridLayout;
143  delete m_categoryButton;
144  delete m_pageQueryWidget;
145 }
146 
148 {
151 }
152 
154 {
157 }
158 
160 {
161  setCurrentValue(id);
162 
163  MusicResultDataItem item;
164  item.m_id = id;
166 }
167 
169 {
170  if(m_infoWidget)
171  {
173  }
174 
175  if(!m_resizeWidgets.isEmpty() && m_gridLayout)
176  {
177  for(const TTKResizeWidget &widget : qAsConst(m_resizeWidgets))
178  {
179  m_gridLayout->removeWidget(widget.m_label);
180  }
181 
182  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
183  for(int i = 0; i < m_resizeWidgets.count(); ++i)
184  {
185  m_gridLayout->addWidget(m_resizeWidgets[i].m_label, i / lineNumber, i % lineNumber, Qt::AlignCenter);
186  }
187  }
188 }
189 
191 {
192  if(!m_initialized)
193  {
194  delete m_statusLabel;
195  m_statusLabel = nullptr;
196 
197  m_container->removeWidget(m_mainWindow);
198  QScrollArea *scrollArea = new QScrollArea(this);
200  m_container->addWidget(scrollArea);
201 
202  m_initialized = true;
203  QVBoxLayout *mainLayout = TTKObjectCast(QVBoxLayout*, m_mainWindow->layout());
204  QWidget *containTopWidget = new QWidget(m_mainWindow);
205  QHBoxLayout *containTopLayout = new QHBoxLayout(containTopWidget);
206  containTopLayout->setContentsMargins(30, 0, 30, 0);
209  containTopLayout->addWidget(m_categoryButton);
210  containTopLayout->addStretch(1);
211 
212  const QStringList titles{tr("Recommend"), tr("Top"), tr("Hot"), tr("New")};
213  for(const QString &data : qAsConst(titles))
214  {
215  QLabel *l = new QLabel(data, containTopWidget);
216  l->setStyleSheet(QString("QLabel::hover{ %1 }").arg(TTK::UI::ColorStyle07));
217  QFrame *hline = new QFrame(containTopWidget);
218  hline->setFrameShape(QFrame::VLine);
219  hline->setStyleSheet(TTK::UI::ColorStyle12);
220  containTopLayout->addWidget(l);
221  containTopLayout->addWidget(hline);
222  }
223  containTopWidget->setLayout(containTopLayout);
224 
225  QFrame *line = new QFrame(m_mainWindow);
226  line->setFrameShape(QFrame::HLine);
227  line->setStyleSheet(TTK::UI::ColorStyle12);
228 
229  QWidget *containWidget = new QWidget(m_mainWindow);
230  m_gridLayout = new QGridLayout(containWidget);
231  m_gridLayout->setVerticalSpacing(35);
232  containWidget->setLayout(m_gridLayout);
233 
234  mainLayout->addWidget(containTopWidget);
235  mainLayout->addWidget(line);
236  mainLayout->addWidget(containWidget);
237 
239  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
240 
242  mainLayout->addStretch(1);
243  }
244 
246  {
247  m_categoryChanged = false;
249  }
250 
252  connect(label, SIGNAL(currentItemClicked(MusicResultDataItem)), SLOT(currentPlaylistClicked(MusicResultDataItem)));
253  label->setResultDataItem(item);
254 
255  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
256  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignCenter);
257 
258  m_resizeWidgets.push_back({label, label->font()});
259 }
260 
262 {
263  delete m_infoWidget;
265 
267  MusicResultDataItem info(item);
268  if(info.isEmpty())
269  {
270  d->startToQueryInfo(info);
271  }
272 
274  m_infoWidget->setResultDataItem(info, this);
275  m_container->addWidget(m_infoWidget);
276  m_container->setCurrentIndex(1);
277 }
278 
280 {
281  m_container->setCurrentIndex(0);
282 }
283 
285 {
286  if(m_categoryButton)
287  {
288  m_value.clear();
289  m_categoryChanged = true;
290  m_categoryButton->setText(category.m_value);
292 
293  while(!m_resizeWidgets.isEmpty())
294  {
295  QWidget *w = m_resizeWidgets.takeLast().m_label;
296  m_gridLayout->removeWidget(w);
297  delete w;
298  }
299 
301  }
302 }
303 
305 {
306  while(!m_resizeWidgets.isEmpty())
307  {
308  QWidget *w = m_resizeWidgets.takeLast().m_label;
309  m_gridLayout->removeWidget(w);
310  delete w;
311  }
312 
315 }
static const QString ColorStyle06
Definition: musicuiobject.h:52
The class of the search result data item.
static const QString BorderStyle01
border
static constexpr const char * TinyBtnPlaylist
static constexpr int WIDTH_LABEL_SIZE
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:203
The class of the playlist music item widget.
int pageTotalSize() const noexcept
virtual void startToRequest(const QString &url)=0
virtual void setCurrentID(const QString &id) overridefinal
The class of the playlist music found category pop widget.
void setResultDataItem(const MusicResultDataItem &item)
void currentPlaylistClicked(const MusicResultDataItem &item)
virtual void setCurrentValue(const QString &value)
The class of the query playlist download data from net.
virtual void startToQueryInfo(MusicResultDataItem &item)=0
static const QString BackgroundStyle04
Definition: musicuiobject.h:91
MusicPlaylistQueryItemWidget(QWidget *parent=nullptr)
static const QString ColorStyle12
Definition: musicuiobject.h:70
virtual void startToSearchByID(const QString &value)
MusicPlaylistQueryWidget(QWidget *parent=nullptr)
#define qAsConst
Definition: ttkqtglobal.h:51
void setInputData(const QByteArray &data, const QSize &size)
void setCategory(const QString &server, QObject *obj)
The class of the page query widget.
static constexpr int LINE_SPACING_SIZE
virtual void startToPage(int offset)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
void setCurrentCategory(const MusicResultsCategoryItem &category)
void page(int index, int total)
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
void createPlaylistItem(const MusicResultDataItem &item)
MusicPlaylistFoundCategoryPopWidget * m_categoryButton
static bool isCoverValid(const QString &url)
The class of the image render thread.
The class of the item query widget base.
static const QString ColorStyle07
Definition: musicuiobject.h:55
The class of the results category item.
QWidget * createPageWidget(QWidget *parent, int total)
virtual void resizeWidget() overridefinal
void categoryChanged(const MusicResultsCategoryItem &category)
void setResultDataItem(const MusicResultDataItem &item, QObject *obj)
virtual void setCurrentValue(const QString &value) overridefinal
MusicAbstractQueryRequest * m_networkRequest
void renderFinished(const QPixmap &data)
MusicPlaylistQueryInfoWidget * m_infoWidget
#define G_DOWNLOAD_QUERY_PTR
#define QUERY_WIDGET_WIDTH
The class of the cover data download request.
void setQueryInput(MusicAbstractQueryRequest *query)
virtual void resizeWidget() overridefinal
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:70
static constexpr int HEIGHT_LABEL_SIZE
MusicPageQueryWidget * m_pageQueryWidget
The class of the playlist music query info widget.
void downLoadFinished(const QByteArray &bytes)
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:76