TTKMusicPlayer  4.3.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 "ttkclickedlabel.h"
6 
9 {
10  setIconSize(QSize(TTK_ITEM_SIZE_L, TTK_ITEM_SIZE_L));
11  setColumnCount(6);
12 
13  QHeaderView *headerView = horizontalHeader();
14  headerView->resizeSection(0, 10);
15  headerView->resizeSection(1, 40);
16  headerView->resizeSection(2, 315);
17  headerView->resizeSection(3, 90);
18  headerView->resizeSection(4, 105);
19  headerView->resizeSection(5, 110);
20 
21  verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle03);
22 
25 }
26 
28 {
29  delete m_networkRequest;
30 }
31 
33 {
35 }
36 
38 {
39  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
40  QHeaderView *headerView = horizontalHeader();
41  headerView->resizeSection(2, 315 + width - WINDOW_WIDTH_MIN);
42 
43  for(int i = 0; i < rowCount(); ++i)
44  {
45  QTableWidgetItem *it = item(i, 2);
46  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
47  }
48 }
49 
51 {
52  if(column == 2 || column == 3)
53  {
54  setCursor(QCursor(Qt::PointingHandCursor));
55  }
56  else
57  {
58  unsetCursor();
59  }
60 
62 }
63 
65 {
66  Q_UNUSED(row);
67  MusicResultDataItemList items(m_networkRequest->items());
68  if(row < 0 || row >= items.count())
69  {
70  return;
71  }
72 
73  switch(column)
74  {
75  case 2: Q_EMIT programItemClicked(items[row].m_id, QString("-1")); break;
76  case 3: Q_EMIT programItemClicked(QString("-1"), items[row].m_nickName); break;
77  default:break;
78  }
79 }
80 
82 {
83  const int index = rowCount();
84  setRowCount(index + 1);
85  setRowHeight(index, TTK_ITEM_SIZE_2XL);
86 
87  QHeaderView *headerView = horizontalHeader();
88  QTableWidgetItem *item = new QTableWidgetItem;
89  setItem(index, 0, item);
90 
91  item = new QTableWidgetItem;
92  item->setIcon(QPixmap(":/image/lb_default_art"));
93  setItem(index, 1, item);
94 
95  item = new QTableWidgetItem;
96  item->setToolTip(data.m_name);
97  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
98  item->setForeground(QColor(TTK::UI::Color02));
99  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
100  setItem(index, 2, item);
101 
102  item = new QTableWidgetItem(data.m_category);
103  item->setForeground(QColor(TTK::UI::Color02));
104  QtItemSetTextAlignment(item, Qt::AlignCenter);
105  setItem(index, 3, item);
106 
107  item = new QTableWidgetItem(tr("Played %1").arg(data.m_count));
108  item->setForeground(QColor(TTK::UI::Color02));
109  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
110  setItem(index, 4, item);
111 
112  item = new QTableWidgetItem(data.m_time);
113  item->setForeground(QColor(TTK::UI::Color02));
114  QtItemSetTextAlignment(item, Qt::AlignCenter);
115  setItem(index, 5, item);
116 
117  if(TTK::isCoverValid(data.m_coverUrl))
118  {
120  connect(req, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
121  req->setHeader("id", index);
122  req->startToRequest(data.m_coverUrl);
123  }
124 }
125 
127 {
128  if(bytes.isEmpty())
129  {
130  TTK_ERROR_STREAM("Input byte data is empty");
131  return;
132  }
133 
135  if(!d)
136  {
137  return;
138  }
139 
140  QTableWidgetItem *it = item(d->header("id").toInt(), 1);
141  if(it)
142  {
143  QPixmap pix;
144  pix.loadFromData(bytes);
145  it->setIcon(pix);
146  }
147 }
148 
149 
150 
152  : QWidget(parent),
153  m_type(type)
154 {
155  QVBoxLayout *layout = new QVBoxLayout(this);
156  layout->setContentsMargins(0, 0, 0, 0);
157  setLayout(layout);
158 
159  QWidget *top = new QWidget(this);
160  layout->addWidget(top);
161  QHBoxLayout *topLayout = new QHBoxLayout(top);
162  topLayout->setContentsMargins(10, 20, 10, 0);
163  top->setLayout(topLayout);
164 
165  QLabel *label = new QLabel(type == TTK::Program::Recommed ? tr("Recommend") : tr("Program"), this);
166  QFont font = label->font();
167  font.setPixelSize(20);
168  font.setBold(true);
169  label->setFont(font);
170  topLayout->addWidget(label);
171 
172  QPushButton *backButton = new QPushButton(tr("Back"), this);
173  backButton->setFixedSize(90, 30);
174  backButton->setStyleSheet(TTK::UI::PushButtonStyle03);
175  backButton->setCursor(QCursor(Qt::PointingHandCursor));
176  connect(backButton, SIGNAL(clicked()), parent, SLOT(backToMainMenu()));
177  topLayout->addWidget(backButton);
178  layout->addWidget(top);
179 
180 #ifdef Q_OS_UNIX
181  backButton->setFocusPolicy(Qt::NoFocus);
182 #endif
183 
184  QFrame *line = new QFrame(this);
185  line->setFrameShape(QFrame::HLine);
186  line->setStyleSheet(TTK::UI::ColorStyle11);
187  layout->addWidget(line);
188 
190  connect(m_tableWidget, SIGNAL(programItemClicked(QString,QString)), parent, SLOT(programItemClicked(QString,QString)));
191  layout->addWidget(m_tableWidget);
192 }
193 
195 {
196  delete m_tableWidget;
197 }
198 
200 {
202 }
203 
205 {
207 }
208 
209 
210 
212  : QStackedWidget(parent),
213  m_recommendWidget(nullptr),
214  m_programWidget(nullptr),
215  m_queryWidget(nullptr)
216 {
217  setObjectName(MusicWebDJRadioWidget::metaObject()->className());
218  setStyleSheet(QString("#%1{ %2 }").arg(objectName(), TTK::UI::BackgroundStyle10));
219 
221 }
222 
224 {
225  delete m_recommendWidget;
226  delete m_programWidget;
227  delete m_categoryWidget;
228  delete m_queryWidget;
229 }
230 
232 {
234 }
235 
237 {
238  if(m_categoryWidget)
239  {
241  }
242 
244  {
246  }
247 
248  if(m_programWidget)
249  {
251  }
252 
253  if(m_queryWidget)
254  {
256  }
257 }
258 
260 {
261  setCurrentIndex(0);
262 }
263 
265 {
266  delete m_recommendWidget;
269  addWidget(m_recommendWidget);
270  setCurrentWidget(m_recommendWidget);
271 }
272 
274 {
275  delete m_programWidget;
278  addWidget(m_programWidget);
279  setCurrentWidget(m_programWidget);
280 }
281 
282 void MusicWebDJRadioWidget::programItemClicked(const QString &rid, const QString &cid)
283 {
284  delete m_queryWidget;
286  connect(m_queryWidget, SIGNAL(backToMainMenu()), SLOT(backToMainMenu()));
287 
288  if(rid == "-1" && cid != "-1")
289  {
291  }
292  else
293  {
295  }
296 
297  addWidget(m_queryWidget);
298  setCurrentWidget(m_queryWidget);
299 }
300 
302 {
303  programItemClicked("-1", item.m_id);
304 }
305 
307 {
308  QWidget *w = new QWidget(this);
309  QVBoxLayout *layout = new QVBoxLayout(w);
310  layout->setSpacing(15);
311  layout->setContentsMargins(30, 30, 30, 0);
312  w->setLayout(layout);
313  //
314  QWidget *top = new QWidget(w);
315  layout->addWidget(top);
316  QHBoxLayout *topLayout = new QHBoxLayout(top);
317  topLayout->setSpacing(35);
318  topLayout->setContentsMargins(0, 0, 0, 0);
319  top->setLayout(topLayout);
320 
321  QWidget *leftTop = new QWidget(top);
322  QHBoxLayout *leftTopLayout = new QHBoxLayout(leftTop);
323  leftTopLayout->setSpacing(0);
324  leftTopLayout->setContentsMargins(0, 0, 0, 0);
325  TTKClickedLabel *recommendLabel = new TTKClickedLabel(tr("Recommend"), leftTop);
326  QFont recommendFont = recommendLabel->font();
327  recommendFont.setPixelSize(20);
328  recommendFont.setBold(true);
329  recommendLabel->setFont(recommendFont);
330  leftTopLayout->addWidget(recommendLabel);
331  leftTopLayout->addStretch(1);
332  connect(recommendLabel, SIGNAL(clicked()), SLOT(createRecommendWidget()));
333 
334  TTKClickedLabel *recommendMoreLabel = new TTKClickedLabel(tr("More >"), leftTop);
335  recommendMoreLabel->setStyleSheet(TTK::UI::ColorStyle04);
336  connect(recommendMoreLabel, SIGNAL(clicked()), SLOT(createRecommendWidget()));
337  leftTopLayout->addWidget(recommendMoreLabel);
338  topLayout->addWidget(leftTop);
339  //
340  QWidget *rightTop = new QWidget(top);
341  QHBoxLayout *rightTopLayout = new QHBoxLayout(rightTop);
342  rightTopLayout->setSpacing(0);
343  rightTopLayout->setContentsMargins(0, 0, 0, 0);
344  TTKClickedLabel *programLabel = new TTKClickedLabel(tr("Program"), rightTop);
345  QFont programFont = programLabel->font();
346  programFont.setPixelSize(20);
347  programFont.setBold(true);
348  programLabel->setFont(programFont);
349  rightTopLayout->addWidget(programLabel);
350  rightTopLayout->addStretch(1);
351  connect(programLabel, SIGNAL(clicked()), SLOT(createProgramWidget()));
352 
353  TTKClickedLabel *programMoreLabel = new TTKClickedLabel(tr("More >"), rightTop);
354  programMoreLabel->setStyleSheet(TTK::UI::ColorStyle04);
355  connect(programMoreLabel, SIGNAL(clicked()), SLOT(createProgramWidget()));
356  rightTopLayout->addWidget(programMoreLabel);
357  topLayout->addWidget(rightTop);
358  //
359  QFrame *line = new QFrame(w);
360  line->setFrameShape(QFrame::HLine);
361  line->setStyleSheet(TTK::UI::ColorStyle11);
362  layout->addWidget(line);
363  //
366  layout->addWidget(m_categoryWidget);
367 
368  addWidget(w);
369 }
The class of the dj radio music query widget.
void downloadFinished(const QByteArray &bytes)
MusicWebDJRadioProgramTableWidget(QWidget *parent=nullptr)
The class of the search result data item.
const QVariant header(const QString &key) const noexcept
static bool isCoverValid(const QString &url) noexcept
The class of the table widget base.
virtual void itemCellClicked(int row, int column) overridefinal
virtual void startToRequest(const QString &url)=0
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
void setHeader(const QString &key, const QVariant &value) noexcept
MusicWebDJRadioProgramWidget * m_programWidget
The class of the label widget that can click.
const MusicResultDataItemList & items() const noexcept
virtual void setCurrentKey(const QString &id) overridefinal
MusicWebDJRadioProgramTableWidget * m_tableWidget
#define TTK_ITEM_SIZE_2XL
Definition: ttkglobal.h:324
static const QString ScrollBarStyle03
virtual void resizeGeometry() overridefinal
virtual void setCurrentValue(const QString &value) overridefinal
The class of the cover source data download request.
virtual void itemCellEntered(int row, int column) overridefinal
static const QString PushButtonStyle03
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)
virtual void itemCellEntered(int row, int column)
The class of the music dj radio category widget.
MusicWebDJRadioWidget(QWidget *parent=nullptr)
The class of the music dj radio program request.
MusicDJRadioProgramRequest * m_networkRequest
static const QString BackgroundStyle10
virtual void resizeGeometry() overridefinal
The class of the music dj radio program table widget.
void startToRequest(TTK::Program type)
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:172
static const QString ColorStyle11
Definition: musicuiobject.h:67
#define TTK_ITEM_SIZE_L
Definition: ttkglobal.h:322
void currentItemClicked(const MusicResultDataItem &item)
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:76
void createProgramItem(const MusicResultDataItem &item)
void programItemClicked(const QString &rid, const QString &cid)
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:82