TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwebdjradiowidget.cpp
Go to the documentation of this file.
5 #include "musiccoverrequest.h"
6 #include "musicwidgetheaders.h"
7 
10 {
11  setIconSize(QSize(TTK_ITEM_SIZE_L, TTK_ITEM_SIZE_L));
12  setColumnCount(6);
13 
14  QHeaderView *headerView = horizontalHeader();
15  headerView->resizeSection(0, 10);
16  headerView->resizeSection(1, 40);
17  headerView->resizeSection(2, 315);
18  headerView->resizeSection(3, 90);
19  headerView->resizeSection(4, 105);
20  headerView->resizeSection(5, 110);
21 
22  verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle03);
23 
26 }
27 
29 {
30  delete m_networkRequest;
31 }
32 
34 {
36 }
37 
39 {
40  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
41  QHeaderView *headerView = horizontalHeader();
42  headerView->resizeSection(2, 315 + width - WINDOW_WIDTH_MIN);
43 
44  for(int i = 0; i < rowCount(); ++i)
45  {
46  QTableWidgetItem *it = item(i, 2);
47  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
48  }
49 }
50 
52 {
53  if(column == 2 || column == 3)
54  {
55  setCursor(QCursor(Qt::PointingHandCursor));
56  }
57  else
58  {
59  unsetCursor();
60  }
61 
63 }
64 
66 {
67  Q_UNUSED(row);
68  MusicResultDataItemList items(m_networkRequest->items());
69  if(row < 0 || row >= items.count())
70  {
71  return;
72  }
73 
74  switch(column)
75  {
76  case 2: Q_EMIT programItemClicked(items[row].m_id, QString("-1")); break;
77  case 3: Q_EMIT programItemClicked(QString("-1"), items[row].m_nickName); break;
78  default:break;
79  }
80 }
81 
83 {
84  const int index = rowCount();
85  setRowCount(index + 1);
86  setRowHeight(index, TTK_ITEM_SIZE_2XL);
87 
88  QHeaderView *headerView = horizontalHeader();
89  QTableWidgetItem *item = new QTableWidgetItem;
90  setItem(index, 0, item);
91 
92  item = new QTableWidgetItem;
93  item->setIcon(QPixmap(":/image/lb_default_art"));
94  setItem(index, 1, item);
95 
96  item = new QTableWidgetItem;
97  item->setToolTip(data.m_name);
98  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
99  item->setForeground(QColor(TTK::UI::Color02));
100  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
101  setItem(index, 2, item);
102 
103  item = new QTableWidgetItem(data.m_category);
104  item->setForeground(QColor(TTK::UI::Color02));
105  QtItemSetTextAlignment(item, Qt::AlignCenter);
106  setItem(index, 3, item);
107 
108  item = new QTableWidgetItem(tr("Played %1").arg(data.m_count));
109  item->setForeground(QColor(TTK::UI::Color02));
110  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
111  setItem(index, 4, item);
112 
113  item = new QTableWidgetItem(data.m_updateTime);
114  item->setForeground(QColor(TTK::UI::Color02));
115  QtItemSetTextAlignment(item, Qt::AlignCenter);
116  setItem(index, 5, item);
117 
118  if(TTK::isCoverValid(data.m_coverUrl))
119  {
120  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
121  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
122  d->setHeader("id", index);
123  d->startToRequest(data.m_coverUrl);
124  }
125 }
126 
128 {
129  if(bytes.isEmpty())
130  {
131  TTK_ERROR_STREAM("Input byte data is empty");
132  return;
133  }
134 
136  if(!d)
137  {
138  return;
139  }
140 
141  QTableWidgetItem *it = item(d->header("id").toInt(), 1);
142  if(it)
143  {
144  QPixmap pix;
145  pix.loadFromData(bytes);
146  it->setIcon(pix);
147  }
148 }
149 
150 
151 
153  : QWidget(parent),
154  m_type(type)
155 {
156  QVBoxLayout *layout = new QVBoxLayout(this);
157  layout->setContentsMargins(0, 0, 0, 0);
158  setLayout(layout);
159 
160  QWidget *top = new QWidget(this);
161  layout->addWidget(top);
162  QHBoxLayout *topLayout = new QHBoxLayout(top);
163  topLayout->setContentsMargins(10, 20, 10, 0);
164  top->setLayout(topLayout);
165 
166  QLabel *label = new QLabel(type == TTK::Program::Recommed ? tr("Recommend") : tr("Program"), this);
167  QFont font = label->font();
168  font.setPixelSize(20);
169  font.setBold(true);
170  label->setFont(font);
171  topLayout->addWidget(label);
172 
173  QPushButton *backButton = new QPushButton(tr("Back"), this);
174  backButton->setFixedSize(90, 30);
175  backButton->setStyleSheet(TTK::UI::PushButtonStyle03);
176  backButton->setCursor(QCursor(Qt::PointingHandCursor));
177  connect(backButton, SIGNAL(clicked()), parent, SLOT(backToMainMenu()));
178  topLayout->addWidget(backButton);
179  layout->addWidget(top);
180 
181 #ifdef Q_OS_UNIX
182  backButton->setFocusPolicy(Qt::NoFocus);
183 #endif
184 
185  QFrame *line = new QFrame(this);
186  line->setFrameShape(QFrame::HLine);
187  line->setStyleSheet(TTK::UI::ColorStyle11);
188  layout->addWidget(line);
189 
191  connect(m_tableWidget, SIGNAL(programItemClicked(QString,QString)), parent, SLOT(programItemClicked(QString,QString)));
192  layout->addWidget(m_tableWidget);
193 }
194 
196 {
197  delete m_tableWidget;
198 }
199 
201 {
203 }
204 
206 {
208 }
209 
210 
211 
213  : QStackedWidget(parent),
214  m_recommendWidget(nullptr),
215  m_programWidget(nullptr),
216  m_queryWidget(nullptr)
217 {
218  setObjectName(className());
219  setStyleSheet(QString("#%1{%2}").arg(className(), TTK::UI::BackgroundStyle10));
220 
221  initFirstWidget();
222 }
223 
225 {
226  delete m_recommendWidget;
227  delete m_programWidget;
228  delete m_categoryWidget;
229  delete m_queryWidget;
230 }
231 
233 {
235 }
236 
238 {
239  if(m_categoryWidget)
240  {
242  }
243 
245  {
247  }
248 
249  if(m_programWidget)
250  {
252  }
253 
254  if(m_queryWidget)
255  {
257  }
258 }
259 
261 {
262  setCurrentIndex(0);
263 }
264 
266 {
267  delete m_recommendWidget;
270  addWidget(m_recommendWidget);
271  setCurrentWidget(m_recommendWidget);
272 }
273 
275 {
276  delete m_programWidget;
279  addWidget(m_programWidget);
280  setCurrentWidget(m_programWidget);
281 }
282 
283 void MusicWebDJRadioWidget::programItemClicked(const QString &rid, const QString &cid)
284 {
285  delete m_queryWidget;
287  connect(m_queryWidget, SIGNAL(backToMainMenu()), SLOT(backToMainMenu()));
288 
289  if(rid == "-1" && cid != "-1")
290  {
292  }
293  else
294  {
296  }
297 
298  addWidget(m_queryWidget);
299  setCurrentWidget(m_queryWidget);
300 }
301 
303 {
304  programItemClicked("-1", item.m_id);
305 }
306 
308 {
309  QWidget *w = new QWidget(this);
310  QVBoxLayout *layout = new QVBoxLayout(w);
311  layout->setSpacing(15);
312  layout->setContentsMargins(30, 30, 30, 0);
313  w->setLayout(layout);
314  //
315  QWidget *top = new QWidget(w);
316  layout->addWidget(top);
317  QHBoxLayout *topLayout = new QHBoxLayout(top);
318  topLayout->setSpacing(35);
319  topLayout->setContentsMargins(0, 0, 0, 0);
320  top->setLayout(topLayout);
321 
322  QWidget *leftTop = new QWidget(top);
323  QHBoxLayout *leftTopLayout = new QHBoxLayout(leftTop);
324  leftTopLayout->setSpacing(0);
325  leftTopLayout->setContentsMargins(0, 0, 0, 0);
326  TTKClickedLabel *recommendLabel = new TTKClickedLabel(tr("Recommend"), leftTop);
327  QFont recommendFont = recommendLabel->font();
328  recommendFont.setPixelSize(20);
329  recommendFont.setBold(true);
330  recommendLabel->setFont(recommendFont);
331  leftTopLayout->addWidget(recommendLabel);
332  leftTopLayout->addStretch(1);
333  connect(recommendLabel, SIGNAL(clicked()), SLOT(createRecommendWidget()));
334 
335  TTKClickedLabel *recommendMoreLabel = new TTKClickedLabel(tr("More >"), leftTop);
336  recommendMoreLabel->setStyleSheet(TTK::UI::ColorStyle04);
337  connect(recommendMoreLabel, SIGNAL(clicked()), SLOT(createRecommendWidget()));
338  leftTopLayout->addWidget(recommendMoreLabel);
339  topLayout->addWidget(leftTop);
340  //
341  QWidget *rightTop = new QWidget(top);
342  QHBoxLayout *rightTopLayout = new QHBoxLayout(rightTop);
343  rightTopLayout->setSpacing(0);
344  rightTopLayout->setContentsMargins(0, 0, 0, 0);
345  TTKClickedLabel *programLabel = new TTKClickedLabel(tr("Program"), rightTop);
346  QFont programFont = programLabel->font();
347  programFont.setPixelSize(20);
348  programFont.setBold(true);
349  programLabel->setFont(programFont);
350  rightTopLayout->addWidget(programLabel);
351  rightTopLayout->addStretch(1);
352  connect(programLabel, SIGNAL(clicked()), SLOT(createProgramWidget()));
353 
354  TTKClickedLabel *programMoreLabel = new TTKClickedLabel(tr("More >"), rightTop);
355  programMoreLabel->setStyleSheet(TTK::UI::ColorStyle04);
356  connect(programMoreLabel, SIGNAL(clicked()), SLOT(createProgramWidget()));
357  rightTopLayout->addWidget(programMoreLabel);
358  topLayout->addWidget(rightTop);
359  //
360  QFrame *line = new QFrame(w);
361  line->setFrameShape(QFrame::HLine);
362  line->setStyleSheet(TTK::UI::ColorStyle11);
363  layout->addWidget(line);
364  //
367  layout->addWidget(m_categoryWidget);
368 
369  addWidget(w);
370 }
The class of the dj radio music query widget.
MusicWebDJRadioProgramTableWidget(QWidget *parent=nullptr)
The class of the search result data item.
void currentCategoryClicked(const MusicResultDataItem &item)
The class of the table widget base.
virtual void itemCellClicked(int row, int column) overridefinal
virtual void startToRequest(const QString &url)=0
void downLoadFinished(const QByteArray &bytes)
MusicWebDJRadioCategoryWidget * m_categoryWidget
void programItemClicked(const QString &rid, const QString &cid)
static const QString ColorStyle04
Definition: musicuiobject.h:46
#define QtItemSetTextAlignment(p, a)
Item text alignment.
Definition: ttkqtcompat.h:45
static constexpr unsigned int Color02
Definition: musicuiobject.h:34
MusicWebDJRadioProgramWidget * m_programWidget
The class of the label widget that can click.
MusicWebDJRadioProgramTableWidget * m_tableWidget
#define TTK_ITEM_SIZE_2XL
Definition: ttkglobal.h:245
static const QString ScrollBarStyle03
virtual void setCurrentValue(const QString &value) overridefinal
virtual void itemCellEntered(int row, int column) overridefinal
static const QString PushButtonStyle03
virtual void resizeWidget() overridefinal
const QVariant header(const QString &key) const
The class of the music dj radio program widget.
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
const MusicResultDataItemList & items() const
virtual void itemCellEntered(int row, int column)
The class of the music dj radio category widget.
MusicWebDJRadioWidget(QWidget *parent=nullptr)
virtual void setCurrentID(const QString &id) overridefinal
The class of the music dj radio program request.
static bool isCoverValid(const QString &url)
MusicDJRadioProgramRequest * m_networkRequest
static const QString BackgroundStyle10
virtual void resizeWidget() overridefinal
void setHeader(const QString &key, const QVariant &value)
The class of the music dj radio program table widget.
void startToRequest(TTK::Program type)
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:153
static const QString ColorStyle11
Definition: musicuiobject.h:67
#define G_DOWNLOAD_QUERY_PTR
#define TTK_ITEM_SIZE_L
Definition: ttkglobal.h:243
MusicWebDJRadioProgramWidget * m_recommendWidget
The class of the cover data download request.
MusicWebDJRadioQueryWidget * m_queryWidget
MusicWebDJRadioProgramWidget(TTK::Program type, QWidget *parent=nullptr)
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
void createProgramItem(const MusicResultDataItem &item)
void programItemClicked(const QString &rid, const QString &cid)
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60