TTKMusicPlayer  3.7.0.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 {
155  setCurrentValue(id);
156 
157  MusicResultDataItem item;
158  item.m_id = id;
160 }
161 
163 {
164  if(m_infoWidget)
165  {
167  }
168 
169  if(!m_resizeWidgets.isEmpty() && m_gridLayout)
170  {
171  for(const TTKResizeWidget &widget : qAsConst(m_resizeWidgets))
172  {
173  m_gridLayout->removeWidget(widget.m_label);
174  }
175 
176  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
177  for(int i = 0; i < m_resizeWidgets.count(); ++i)
178  {
179  m_gridLayout->addWidget(m_resizeWidgets[i].m_label, i / lineNumber, i % lineNumber, Qt::AlignCenter);
180  }
181  }
182 }
183 
185 {
186  if(!m_initialized)
187  {
188  delete m_statusLabel;
189  m_statusLabel = nullptr;
190 
191  m_container->removeWidget(m_mainWindow);
192  QScrollArea *scrollArea = new QScrollArea(this);
194  m_container->addWidget(scrollArea);
195 
196  m_initialized = true;
197  QVBoxLayout *mainLayout = TTKObjectCast(QVBoxLayout*, m_mainWindow->layout());
198  QWidget *containTopWidget = new QWidget(m_mainWindow);
199  QHBoxLayout *containTopLayout = new QHBoxLayout(containTopWidget);
200  containTopLayout->setContentsMargins(30, 0, 30, 0);
203  containTopLayout->addWidget(m_categoryButton);
204  containTopLayout->addStretch(1);
205 
206  const QStringList titles{tr("Recommend"), tr("Top"), tr("Hot"), tr("New")};
207  for(const QString &data : qAsConst(titles))
208  {
209  QLabel *l = new QLabel(data, containTopWidget);
210  l->setStyleSheet(QString("QLabel::hover{%1}").arg(TTK::UI::ColorStyle07));
211  QFrame *hline = new QFrame(containTopWidget);
212  hline->setFrameShape(QFrame::VLine);
213  hline->setStyleSheet(TTK::UI::ColorStyle12);
214  containTopLayout->addWidget(l);
215  containTopLayout->addWidget(hline);
216  }
217  containTopWidget->setLayout(containTopLayout);
218 
219  QFrame *line = new QFrame(m_mainWindow);
220  line->setFrameShape(QFrame::HLine);
221  line->setStyleSheet(TTK::UI::ColorStyle12);
222 
223  QWidget *containWidget = new QWidget(m_mainWindow);
224  m_gridLayout = new QGridLayout(containWidget);
225  m_gridLayout->setVerticalSpacing(35);
226  containWidget->setLayout(m_gridLayout);
227 
228  mainLayout->addWidget(containTopWidget);
229  mainLayout->addWidget(line);
230  mainLayout->addWidget(containWidget);
231 
233  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
234 
236  mainLayout->addStretch(1);
237  }
238 
240  {
241  m_categoryChanged = false;
243  }
244 
246  connect(label, SIGNAL(currentItemClicked(MusicResultDataItem)), SLOT(currentPlaylistClicked(MusicResultDataItem)));
247  label->setResultDataItem(item);
248 
249  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
250  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignCenter);
251 
252  m_resizeWidgets.push_back({label, label->font()});
253 }
254 
256 {
257  delete m_infoWidget;
259 
261  MusicResultDataItem info(item);
262  if(info.isEmpty())
263  {
264  d->startToQueryInfo(info);
265  }
266 
268  m_infoWidget->setResultDataItem(info, this);
269  m_container->addWidget(m_infoWidget);
270  m_container->setCurrentIndex(1);
271 }
272 
274 {
275  m_container->setCurrentIndex(0);
276 }
277 
279 {
280  if(m_categoryButton)
281  {
282  m_value.clear();
283  m_categoryChanged = true;
284  m_categoryButton->setText(category.m_value);
286 
287  while(!m_resizeWidgets.isEmpty())
288  {
289  QWidget *w = m_resizeWidgets.takeLast().m_label;
290  m_gridLayout->removeWidget(w);
291  delete w;
292  }
293 
295  }
296 }
297 
299 {
300  while(!m_resizeWidgets.isEmpty())
301  {
302  QWidget *w = m_resizeWidgets.takeLast().m_label;
303  m_gridLayout->removeWidget(w);
304  delete w;
305  }
306 
309 }
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:200
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:90
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:53
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 page(int index, int total)
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
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
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:69
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:60