TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwebdjradiocategorywidget.cpp
Go to the documentation of this file.
4 #include "musiccoverrequest.h"
5 #include "musicwidgetheaders.h"
6 
7 static constexpr int WIDTH_LABEL_SIZE = 60;
8 static constexpr int HEIGHT_LABEL_SIZE = 105;
9 static constexpr int LINE_SPACING_SIZE = 105;
10 
12  : TTKClickedLabel(parent)
13 {
14  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
15 
16  m_iconLabel = new QLabel(this);
17  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
18 
19  m_nameLabel = new QLabel(this);
20  m_nameLabel->setGeometry(0, 65, WIDTH_LABEL_SIZE, 25);
21  m_nameLabel->setAlignment(Qt::AlignCenter);
22  m_nameLabel->setText(TTK_DEFAULT_STR);
23 
24  connect(this, SIGNAL(clicked()), SLOT(currentItemClicked()));
25 }
26 
28 {
29  delete m_iconLabel;
30  delete m_nameLabel;
31 }
32 
34 {
35  m_itemData = item;
36  m_nameLabel->setToolTip(item.m_name);
37  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
38 
40  {
41  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
42  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
43  d->startToRequest(item.m_coverUrl);
44  }
45 }
46 
48 {
49  if(bytes.isEmpty())
50  {
51  TTK_ERROR_STREAM("Input byte data is empty");
52  return;
53  }
54 
55  QPixmap pix;
56  pix.loadFromData(bytes);
57  if(!pix.isNull())
58  {
59  m_iconLabel->setPixmap(pix.copy(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE));
60  }
61 }
62 
64 {
66 }
67 
68 
69 
71  : QWidget(parent)
72 {
73  QHBoxLayout *layout = new QHBoxLayout(this);
74  layout->setSpacing(0);
75  layout->setContentsMargins(0, 0, 0, 0);
76  setLayout(layout);
77 
78  QWidget *mainWindow = new QWidget(this);
79 
80  QScrollArea *scrollArea = new QScrollArea(this);
81  TTK::Widget::generateVScrollAreaFormat(scrollArea, mainWindow);
82  layout->addWidget(scrollArea);
83 
84  m_gridLayout = new QGridLayout(mainWindow);
85  m_gridLayout->setVerticalSpacing(35);
86  mainWindow->setLayout(m_gridLayout);
87 
89  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), SLOT(createCategoryItems()));
90 }
91 
93 {
94  delete m_gridLayout;
95  delete m_networkRequest;
96 }
97 
99 {
101 }
102 
104 {
105  if(!m_resizeWidgets.isEmpty())
106  {
107  for(QWidget *widget : qAsConst(m_resizeWidgets))
108  {
109  m_gridLayout->removeWidget(widget);
110  }
111 
112  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
113  for(int i = 0; i < m_resizeWidgets.count(); ++i)
114  {
115  m_gridLayout->addWidget(m_resizeWidgets[i], i / lineNumber, i % lineNumber, Qt::AlignCenter);
116  }
117  }
118 }
119 
121 {
122  for(const MusicResultDataItem &item : m_networkRequest->items())
123  {
125  connect(label, SIGNAL(currentItemClicked(MusicResultDataItem)), SIGNAL(currentCategoryClicked(MusicResultDataItem)));
126  label->setResultDataItem(item);
127 
128  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
129  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignCenter);
130  m_resizeWidgets << label;
131  }
132 }
static constexpr int LINE_SPACING_SIZE
The class of the search result data item.
static constexpr int HEIGHT_LABEL_SIZE
The class of the music dj radio category item widget.
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
void downLoadFinished(const QByteArray &bytes)
virtual void startToRequest(const QString &url)=0
static constexpr int WIDTH_LABEL_SIZE
MusicDJRadioCategoryRequest * m_networkRequest
The class of the label widget that can click.
MusicWebDJRadioCategoryItemWidget(QWidget *parent=nullptr)
#define qAsConst
Definition: ttkqtglobal.h:53
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
const MusicResultDataItemList & items() const
void currentCategoryClicked(const MusicResultDataItem &item)
static bool isCoverValid(const QString &url)
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
MusicWebDJRadioCategoryWidget(QWidget *parent=nullptr)
#define G_DOWNLOAD_QUERY_PTR
#define QUERY_WIDGET_WIDTH
The class of the cover data download request.
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
void setResultDataItem(const MusicResultDataItem &item)
The class of the music dj radio category request.