TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicqueryitemwidget.cpp
Go to the documentation of this file.
1 #include "musicqueryitemwidget.h"
2 #include "musicwidgetutils.h"
3 #include "musicimagerenderer.h"
4 #include "musictinyuiobject.h"
5 #include "musicwidgetheaders.h"
6 
8  : QLabel(parent),
9  m_showTime(false),
10  m_showCount(true)
11 {
12  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
13 
14  m_listenButton = new QPushButton(this);
15  m_listenButton->setGeometry(0, 0, WIDTH_LABEL_SIZE, 20);
16  m_listenButton->setIcon(QIcon(":/tiny/btn_listen_hover"));
19 
20  m_playButton = new QPushButton(this);
21  m_playButton->setGeometry(110, 110, 30, 30);
22  m_playButton->setCursor(Qt::PointingHandCursor);
24  connect(m_playButton, SIGNAL(clicked()), SLOT(itemClicked()));
25 
26 #ifdef Q_OS_UNIX
27  m_listenButton->setFocusPolicy(Qt::NoFocus);
28  m_playButton->setFocusPolicy(Qt::NoFocus);
29 #endif
30 
31  m_iconLabel = new TTKClickedLabel(this);
32  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
33  connect(m_iconLabel, SIGNAL(clicked()), SLOT(itemClicked()));
34 
35  m_nameLabel = new QLabel(this);
36  m_nameLabel->setGeometry(0, 150, WIDTH_LABEL_SIZE, 25);
37  m_nameLabel->setText(TTK_DEFAULT_STR);
38 
39  m_valueLabel = new QLabel(this);
40  m_valueLabel->setGeometry(0, 175, WIDTH_LABEL_SIZE, 25);
41  m_valueLabel->setStyleSheet(TTK::UI::ColorStyle03);
42  m_valueLabel->setText("-");
43 }
44 
46 {
47  delete m_listenButton;
48  delete m_playButton;
49  delete m_iconLabel;
50  delete m_nameLabel;
51  delete m_valueLabel;
52 }
53 
55 {
56  m_itemData = item;
57  m_nameLabel->setToolTip(item.m_name);
58  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
59 
60  if(m_showTime)
61  {
62  m_valueLabel->setToolTip(item.m_time);
63  }
64  else
65  {
66  m_valueLabel->setToolTip("by " + item.m_nickName);
67  }
68  m_valueLabel->setText(TTK::Widget::elidedText(m_valueLabel->font(), m_valueLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
69 
70  if(!m_showCount)
71  {
72  m_listenButton->setVisible(false);
73  }
74  else
75  {
76  bool ok = false;
77  const int count = item.m_count.toInt(&ok);
78  if(ok)
79  {
80  if(count >= 10000)
81  {
82  m_listenButton->setText(tr("%1W").arg(count / 10000));
83  }
84  else
85  {
86  m_listenButton->setText(QString::number(count));
87  }
88  }
89  else
90  {
91  m_listenButton->setText(item.m_count);
92  }
93  }
94 
95  if(cover && TTK::isCoverValid(item.m_coverUrl))
96  {
97  connect(cover, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
98  cover->startToRequest(item.m_coverUrl);
99  }
100 }
101 
102 void MusicSquareQueryItemWidget::downloadFinished(const QByteArray &bytes)
103 {
104  if(bytes.isEmpty())
105  {
106  TTK_ERROR_STREAM("Input byte data is empty");
107  return;
108  }
109 
110  MusicImageRenderer *render = new MusicImageRenderer(sender());
111  connect(render, SIGNAL(renderFinished(QPixmap)), SLOT(renderFinished(QPixmap)));
112  render->setInputData(bytes, m_iconLabel->size());
113  render->start();
114 }
115 
117 {
118  m_iconLabel->setPixmap(data);
119  m_listenButton->raise();
120  m_playButton->raise();
121 }
122 
124 {
126 }
127 
128 
130  : QLabel(parent)
131 {
132  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
133 
134  m_playButton = new QPushButton(this);
135  m_playButton->setGeometry((WIDTH_LABEL_SIZE - 30) / 2, (HEIGHT_LABEL_SIZE - 30) / 2, 30, 30);
136  m_playButton->setCursor(Qt::PointingHandCursor);
137  m_playButton->setStyleSheet(TTK::UI::TinyBtnPlaylist);
138  connect(m_playButton, SIGNAL(clicked()), SLOT(itemClicked()));
139 
140 #ifdef Q_OS_UNIX
141  m_playButton->setFocusPolicy(Qt::NoFocus);
142 #endif
143 
144  m_iconLabel = new TTKClickedLabel(this);
145  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
146  connect(m_iconLabel, SIGNAL(clicked()), SLOT(itemClicked()));
147 
148  m_nameLabel = new QLabel(this);
149  m_nameLabel->setAlignment(Qt::AlignCenter);
150  m_nameLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
152  m_nameLabel->setText(TTK_DEFAULT_STR);
153 }
154 
156 {
157  delete m_playButton;
158  delete m_iconLabel;
159  delete m_nameLabel;
160 }
161 
163 {
164  m_itemData = item;
165  m_nameLabel->setToolTip(item.m_name);
166  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
167 
168  if(TTK::isCoverValid(item.m_coverUrl))
169  {
171  connect(req, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
172  req->startToRequest(item.m_coverUrl);
173  }
174 
175  m_playButton->hide();
176 }
177 
178 void MusicRectQueryItemWidget::downloadFinished(const QByteArray &bytes)
179 {
180  if(bytes.isEmpty())
181  {
182  TTK_ERROR_STREAM("Input byte data is empty");
183  return;
184  }
185 
186  MusicImageRenderer *render = new MusicImageRenderer(sender());
187  connect(render, SIGNAL(renderFinished(QPixmap)), SLOT(renderFinished(QPixmap)));
188  render->setInputData(bytes, m_iconLabel->size());
189  render->start();
190 }
191 
193 {
194  m_iconLabel->setPixmap(data);
195  m_playButton->raise();
196 }
197 
199 {
201 }
202 
204 {
205  QLabel::enterEvent(event);
206 
207  m_playButton->show();
208  m_nameLabel->hide();
209 }
210 
212 {
213  QLabel::leaveEvent(event);
214 
215  m_playButton->hide();
216  m_nameLabel->show();
217 }
218 
219 
221  : TTKClickedLabel(parent)
222 {
223  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
224 
225  m_iconLabel = new QLabel(this);
226  m_iconLabel->setGeometry(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE);
227 
228  m_nameLabel = new QLabel(this);
229  m_nameLabel->setGeometry(0, 65, WIDTH_LABEL_SIZE, 25);
230  m_nameLabel->setAlignment(Qt::AlignCenter);
231  m_nameLabel->setText(TTK_DEFAULT_STR);
232 
233  connect(this, SIGNAL(clicked()), SLOT(itemClicked()));
234 }
235 
237 {
238  delete m_iconLabel;
239  delete m_nameLabel;
240 }
241 
243 {
244  m_itemData = item;
245  m_nameLabel->setToolTip(item.m_name);
246  m_nameLabel->setText(TTK::Widget::elidedText(m_nameLabel->font(), m_nameLabel->toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
247 
248  if(TTK::isCoverValid(item.m_coverUrl))
249  {
251  connect(req, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
252  req->startToRequest(item.m_coverUrl);
253  }
254 }
255 
256 void MusicLabelQueryItemWidget::downloadFinished(const QByteArray &bytes)
257 {
258  if(bytes.isEmpty())
259  {
260  TTK_ERROR_STREAM("Input byte data is empty");
261  return;
262  }
263 
264  QPixmap pix;
265  pix.loadFromData(bytes);
266  if(!pix.isNull())
267  {
268  m_iconLabel->setPixmap(pix.copy(0, 0, WIDTH_LABEL_SIZE, WIDTH_LABEL_SIZE));
269  }
270 }
271 
273 {
275 }
276 
277 
279  : TTKClickedLabel(parent)
280 {
281  setAlignment(Qt::AlignCenter);
282  setStyleSheet(TTK::UI::ColorStyle02);
283  setFixedSize(WIDTH_LABEL_SIZE, HEIGHT_LABEL_SIZE);
284 
285  connect(this, SIGNAL(clicked()), SLOT(itemClicked()));
286 }
287 
289 {
290  m_itemData = item;
291  setToolTip(item.m_name);
292  setText(TTK::Widget::elidedText(font(), toolTip(), Qt::ElideRight, WIDTH_LABEL_SIZE));
293 }
294 
296 {
298 }
299 
300 
static const QString ColorStyle06
Definition: musicuiobject.h:52
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:178
The class of the search result data item.
static const QString BorderStyle01
border
static constexpr const char * TinyBtnPlaylist
MusicTextQueryItemWidget(QWidget *parent=nullptr)
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
void currentItemClicked(const MusicResultDataItem &item)
static bool isCoverValid(const QString &url) noexcept
MusicResultDataItem m_itemData
virtual void startToRequest(const QString &url)=0
static constexpr int WIDTH_LABEL_SIZE
static const QString PushButtonStyle01
PushButton.
void setResultDataItem(const MusicResultDataItem &item)
MusicResultDataItem m_itemData
void setResultDataItem(const MusicResultDataItem &item)
void currentItemClicked(const MusicResultDataItem &item)
The class of the label widget that can click.
MusicResultDataItem m_itemData
static const QString FontStyle01
Font.
void downloadFinished(const QByteArray &bytes)
static const QString BackgroundStyle04
Definition: musicuiobject.h:91
virtual void leaveEvent(QEvent *event) overridefinal
void downloadFinished(const QByteArray &bytes)
static constexpr int HEIGHT_LABEL_SIZE
MusicSquareQueryItemWidget(QWidget *parent=nullptr)
MusicRectQueryItemWidget(QWidget *parent=nullptr)
static const QString ColorStyle02
Definition: musicuiobject.h:40
The class of the cover source data download request.
static const QString FontStyle05
void renderFinished(const QPixmap &data)
void setInputData(const QByteArray &data, const QSize &size)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
void renderFinished(const QPixmap &data)
void downloadFinished(const QByteArray &bytes)
static constexpr int HEIGHT_LABEL_SIZE
static constexpr int WIDTH_LABEL_SIZE
static constexpr int HEIGHT_LABEL_SIZE
The class of the image render thread.
void setResultDataItem(const MusicResultDataItem &item, MusicCoverRequest *cover)
MusicResultDataItem m_itemData
static const QString ColorStyle03
Definition: musicuiobject.h:43
MusicLabelQueryItemWidget(QWidget *parent=nullptr)
void setResultDataItem(const MusicResultDataItem &item)
void currentItemClicked(const MusicResultDataItem &item)
The class of the cover data download request.
virtual void enterEvent(QtEnterEvent *event) overridefinal
static constexpr int WIDTH_LABEL_SIZE
static constexpr int WIDTH_LABEL_SIZE
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:76
static constexpr int HEIGHT_LABEL_SIZE
void currentItemClicked(const MusicResultDataItem &item)