TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwebmvradioquerywidget.cpp
Go to the documentation of this file.
6 #include "musiccoverrequest.h"
7 #include "musictinyuiobject.h"
8 
9 static constexpr int WIDTH_LABEL_SIZE = 150;
10 static constexpr int HEIGHT_LABEL_SIZE = 100;
11 static constexpr int LINE_SPACING_SIZE = 200;
12 
14  : QLabel(parent)
15 {
16  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
17 
18  m_playButton = new QPushButton(this);
19  m_playButton->setGeometry((WIDTH_LABEL_SIZE - 30) / 2, (HEIGHT_LABEL_SIZE - 30) / 2, 30, 30);
20  m_playButton->setCursor(Qt::PointingHandCursor);
21  m_playButton->setStyleSheet(TTK::UI::TinyBtnPlaylist);
22  connect(m_playButton, SIGNAL(clicked()), SLOT(currentItemClicked()));
23 
24 #ifdef Q_OS_UNIX
25  m_playButton->setFocusPolicy(Qt::NoFocus);
26 #endif
27 
28  m_iconLabel = new QLabel(this);
29  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
30 
31  m_nameLabel = new QLabel(this);
32  m_nameLabel->setAlignment(Qt::AlignCenter);
33  m_nameLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
35  m_nameLabel->setText(TTK_DEFAULT_STR);
36 }
37 
39 {
40  delete m_playButton;
41  delete m_iconLabel;
42  delete m_nameLabel;
43 }
44 
46 {
47  m_itemData = item;
48  m_nameLabel->setToolTip(item.m_name);
49  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
50 
52  {
53  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
54  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
55  d->startToRequest(item.m_coverUrl);
56  }
57 
58  m_playButton->hide();
59 }
60 
62 {
63  if(bytes.isEmpty())
64  {
65  TTK_ERROR_STREAM("Input byte data is empty");
66  return;
67  }
68 
69  MusicImageRenderer *render = new MusicImageRenderer(sender());
70  connect(render, SIGNAL(renderFinished(QPixmap)), SLOT(renderFinished(QPixmap)));
71  render->setInputData(bytes, m_iconLabel->size());
72  render->start();
73 }
74 
76 {
77  m_iconLabel->setPixmap(data);
78  m_playButton->raise();
79 }
80 
82 {
84 }
85 
87 {
88  QLabel::enterEvent(event);
89 
90  m_playButton->show();
91  m_nameLabel->hide();
92 }
93 
95 {
96  QLabel::leaveEvent(event);
97 
98  m_playButton->hide();
99  m_nameLabel->show();
100 }
101 
102 
103 
106 {
107  m_container->show();
108  layout()->removeWidget(m_mainWindow);
109  layout()->addWidget(m_container);
110  m_container->addWidget(m_mainWindow);
111 
112  m_initialized = false;
113  m_infoWidget = nullptr;
114  m_gridLayout = nullptr;
115  m_categoryButton = nullptr;
116 
118  connect(m_networkRequest, SIGNAL(createMVRadioItem(MusicResultDataItem)), SLOT(createMVRadioCategoryItem(MusicResultDataItem)));
119 }
120 
122 {
123  delete m_infoWidget;
124  delete m_gridLayout;
125  delete m_categoryButton;
126 }
127 
129 {
132 }
133 
135 {
136  if(m_infoWidget)
137  {
139  }
140 
141  if(!m_resizeWidgets.isEmpty() && m_gridLayout)
142  {
143  for(const TTKResizeWidget &widget : qAsConst(m_resizeWidgets))
144  {
145  m_gridLayout->removeWidget(widget.m_label);
146  }
147 
148  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
149  for(int i = 0; i < m_resizeWidgets.count(); ++i)
150  {
151  m_gridLayout->addWidget(m_resizeWidgets[i].m_label, i / lineNumber, i % lineNumber, Qt::AlignCenter);
152  }
153  }
154 }
155 
157 {
158  if(!m_initialized)
159  {
160  delete m_statusLabel;
161  m_statusLabel = nullptr;
162 
163  m_container->removeWidget(m_mainWindow);
164  QScrollArea *scrollArea = new QScrollArea(this);
166  m_container->addWidget(scrollArea);
167 
168  m_initialized = true;
169  QVBoxLayout *mainLayout = TTKObjectCast(QVBoxLayout*, m_mainWindow->layout());
170  QWidget *containTopWidget = new QWidget(m_mainWindow);
171  QHBoxLayout *containTopLayout = new QHBoxLayout(containTopWidget);
172  containTopLayout->setContentsMargins(30, 0, 30, 0);
175  containTopLayout->addWidget(m_categoryButton);
176  containTopLayout->addStretch(1);
177  containTopWidget->setLayout(containTopLayout);
178 
179  QFrame *line = new QFrame(m_mainWindow);
180  line->setFrameShape(QFrame::HLine);
181  line->setStyleSheet(TTK::UI::ColorStyle12);
182 
183  QWidget *containWidget = new QWidget(m_mainWindow);
184  m_gridLayout = new QGridLayout(containWidget);
185  m_gridLayout->setVerticalSpacing(35);
186  containWidget->setLayout(m_gridLayout);
187 
188  mainLayout->addWidget(containTopWidget);
189  mainLayout->addWidget(line);
190  mainLayout->addWidget(containWidget);
191  mainLayout->addStretch(1);
192  }
193 
195  connect(label, SIGNAL(currentItemClicked(MusicResultDataItem)), SLOT(currentRadioClicked(MusicResultDataItem)));
196  label->setResultDataItem(item);
197 
198  const int lineNumber = QUERY_WIDGET_WIDTH / LINE_SPACING_SIZE;
199  m_gridLayout->addWidget(label, m_resizeWidgets.count() / lineNumber, m_resizeWidgets.count() % lineNumber, Qt::AlignCenter);
200 
201  m_resizeWidgets.push_back({label, label->font()});
202 }
203 
205 {
206  delete m_infoWidget;
208  connect(m_infoWidget, SIGNAL(backToMainMenu()), SLOT(backToMainMenuClicked()));
210 
211  m_container->addWidget(m_infoWidget);
212  m_container->setCurrentIndex(1);
213 }
214 
216 {
217  m_container->setCurrentIndex(0);
218 }
219 
221 {
222  if(m_categoryButton)
223  {
224  m_value.clear();
225  m_categoryButton->setText(category.m_value);
227 
228  while(!m_resizeWidgets.isEmpty())
229  {
230  QWidget *w = m_resizeWidgets.takeLast().m_label;
231  m_gridLayout->removeWidget(w);
232  delete w;
233  }
234 
236  }
237 }
static const QString ColorStyle06
Definition: musicuiobject.h:52
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
static constexpr int LINE_SPACING_SIZE
The class of the search result data item.
static constexpr const char * TinyBtnPlaylist
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
void categoryChanged(const MusicResultsCategoryItem &category)
virtual void startToRequest(const QString &url)=0
MusicWebMVRadioQueryCategoryPopWidget * m_categoryButton
MusicWebMVRadioQueryItemWidget(QWidget *parent=nullptr)
static constexpr int HEIGHT_LABEL_SIZE
virtual void setCurrentValue(const QString &value)
void currentRadioClicked(const MusicResultDataItem &item)
static const QString FontStyle01
Font.
static const QString ColorStyle12
Definition: musicuiobject.h:70
virtual void setCurrentValue(const QString &value) overridefinal
The class of the music mv category pop widget.
#define qAsConst
Definition: ttkqtglobal.h:53
#define MUSIC_MOVIE_RADIO
virtual void resizeWidget() overridefinal
The class of the music mv info widget.
virtual void setCurrentValue(const QString &value) overridefinal
void setInputData(const QByteArray &data, const QSize &size)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
virtual void leaveEvent(QEvent *event) overridefinal
void downLoadFinished(const QByteArray &bytes)
static bool isCoverValid(const QString &url)
MusicWebMVRadioQueryWidget(QWidget *parent=nullptr)
The class of the image render thread.
The class of the item query widget base.
virtual void enterEvent(QtEnterEvent *event) overridefinal
static const QString FontStyle04
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
The class of the results category item.
void createMVRadioCategoryItem(const MusicResultDataItem &item)
The class of the mv radio category request.
void setCategory(const QString &server, QObject *obj)
MusicAbstractQueryRequest * m_networkRequest
#define G_DOWNLOAD_QUERY_PTR
MusicWebMVRadioInfoWidget * m_infoWidget
#define QUERY_WIDGET_WIDTH
static constexpr int WIDTH_LABEL_SIZE
The class of the cover data download request.
virtual void startToSearch(const QString &value)=0
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
void setResultDataItem(const MusicResultDataItem &item)
The class of the music mv query item widget.
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60
virtual void resizeWidget() overridefinal