TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicalbumquerywidget.cpp
Go to the documentation of this file.
3 #include "musiccoverrequest.h"
4 #include "musicratinglabel.h"
5 
6 #include <cmath>
8 
11 {
14  m_tableWidget->hide();
15 
16  m_networkRequest = G_DOWNLOAD_QUERY_PTR->makeSongRequest(this);
17  connect(m_networkRequest, SIGNAL(downloadDataChanged(QString)), SLOT(queryAllFinished()));
18 }
19 
20 void MusicAlbumQueryWidget::setCurrentValue(const QString &value)
21 {
25 }
26 
27 void MusicAlbumQueryWidget::setCurrentKey(const QString &id)
28 {
29  MusicAbstractQueryRequest *req = G_DOWNLOAD_QUERY_PTR->makeAlbumRequest(this);
32 
33  connect(req, SIGNAL(downloadDataChanged(QString)), SLOT(queryAlbumFinished()));
35 }
36 
38 {
40 
41  if(m_resizeWidgets.isEmpty())
42  {
43  return;
44  }
45 
46  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() - WINDOW_WIDTH_MIN + 180;
47 
48  Data *data = &m_resizeWidgets[1];
49  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width + 30));
50 
51  data = &m_resizeWidgets[2];
52  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
53 
54  data = &m_resizeWidgets[3];
55  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
56 
57  data = &m_resizeWidgets[4];
58  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
59 
60  data = &m_resizeWidgets[5];
61  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
62 }
63 
65 {
66  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
67  if(songInfos.isEmpty())
68  {
69  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_album_found"));
70  }
71  else
72  {
73  bool hasItem = false;
74  for(const TTK::MusicSongInformation &info : qAsConst(songInfos))
75  {
76  if(m_value.contains(info.m_songName))
77  {
78  hasItem = true;
79  setCurrentKey(info.m_albumId);
80  break;
81  }
82  }
83 
84  if(!hasItem)
85  {
86  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_album_found"));
87  }
88  }
89 }
90 
92 {
94  if(!req)
95  {
96  return;
97  }
98 
99  const TTK::MusicSongInformationList &songInfos = req->items();
100  if(songInfos.isEmpty())
101  {
102  m_statusLabel->setPixmap(QPixmap(":/image/lb_no_album_found"));
103  }
104  else
105  {
107  }
108 }
109 
111 {
112  m_currentPlaylistItem = item;
113 
114  createLabels();
115 
116  if(m_resizeWidgets.isEmpty())
117  {
118  return;
119  }
120 
121  if(TTK::isCoverValid(item.m_coverUrl))
122  {
123  MusicCoverRequest *req = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
124  connect(req, SIGNAL(downloadRawDataChanged(QByteArray)), SLOT(downloadFinished(QByteArray)));
125  req->startToRequest(item.m_coverUrl);
126  }
127 
128  QStringList list{item.m_count, item.m_category, item.m_description, item.m_time};
129  for(int i = 0; i < list.count(); ++i)
130  {
131  if(list[i].isEmpty())
132  {
133  list[i] = TTK_DEFAULT_STR;
134  }
135  }
136 
137  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() - WINDOW_WIDTH_MIN + 180;
138 
139  Data *data = &m_resizeWidgets[0];
140  data->m_label->setText(tr("<font color=#158FE1> Alubm > %1 </font>").arg(list[0]));
141 
142  data = &m_resizeWidgets[1];
143  data->m_label->setToolTip(list[0]);
144  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width + 30));
145 
146  data = &m_resizeWidgets[2];
147  data->m_label->setToolTip(tr("Singer: %1").arg(item.m_name));
148  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
149 
150  data = &m_resizeWidgets[3];
151  data->m_label->setToolTip(tr("Language: %1").arg(list[1]));
152  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
153 
154  data = &m_resizeWidgets[4];
155  data->m_label->setToolTip(tr("Company: %1").arg(list[2]));
156  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
157 
158  data = &m_resizeWidgets[5];
159  data->m_label->setToolTip(tr("Year: %1").arg(list[3]));
160  data->m_label->setText(TTK::Widget::elidedText(data->m_font, data->m_label->toolTip(), Qt::ElideRight, width));
161 }
162 
164 {
165  delete m_statusLabel;
166  m_statusLabel = nullptr;
167 
169  m_container->show();
170 
171  layout()->removeWidget(m_mainWidget);
172  QScrollArea *scrollArea = new QScrollArea(this);
174  layout()->addWidget(scrollArea);
175 
176  QWidget *function = new QWidget(m_mainWidget);
177  function->setStyleSheet(TTK::UI::CheckBoxStyle01 + TTK::UI::PushButtonStyle03);
178  QVBoxLayout *grid = new QVBoxLayout(function);
179 
180  QLabel *firstLabel = new QLabel(function);
181  grid->addWidget(firstLabel);
182  //
183  QWidget *topFuncWidget = new QWidget(function);
184  QHBoxLayout *topFuncLayout = new QHBoxLayout(topFuncWidget);
185 
186  m_iconLabel = new QLabel(topFuncWidget);
187  m_iconLabel->setPixmap(QPixmap(":/image/lb_warning").scaled(180, 180));
188  m_iconLabel->setFixedSize(210, 180);
189  //
190  QWidget *topLineWidget = new QWidget(topFuncWidget);
191  QVBoxLayout *topLineLayout = new QVBoxLayout(topLineWidget);
192  topLineLayout->setContentsMargins(10, 5, 5, 0);
193 
194  QLabel *albumLabel = new QLabel(topLineWidget);
195  QFont albumFont = albumLabel->font();
196  albumFont.setPixelSize(20);
197  albumLabel->setFont(albumFont);
198  albumLabel->setStyleSheet(TTK::UI::FontStyle01);
199  albumLabel->setText(TTK_DEFAULT_STR);
200 
201  QLabel *singerLabel = new QLabel(topLineWidget);
202  singerLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
203  singerLabel->setText(TTK_DEFAULT_STR);
204 
205  QLabel *languageLabel = new QLabel(topLineWidget);
206  languageLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
207  languageLabel->setText(TTK_DEFAULT_STR);
208 
209  QLabel *companyLabel = new QLabel(topLineWidget);
210  companyLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
211  companyLabel->setText(TTK_DEFAULT_STR);
212 
213  QLabel *yearLabel = new QLabel(topLineWidget);
214  yearLabel->setStyleSheet(TTK::UI::ColorStyle04 + TTK::UI::FontStyle03);
215  yearLabel->setText(TTK_DEFAULT_STR);
216 
217  topLineLayout->addWidget(albumLabel);
218  topLineLayout->addWidget(singerLabel);
219  topLineLayout->addWidget(languageLabel);
220  topLineLayout->addWidget(companyLabel);
221  topLineLayout->addWidget(yearLabel);
222  topLineWidget->setLayout(topLineLayout);
223 
224  QWidget *topButtonWidget = new QWidget(topFuncWidget);
225  QHBoxLayout *topButtonLayout = new QHBoxLayout(topButtonWidget);
226  topButtonLayout->setContentsMargins(0, 0, 0, 0);
227 
228  QPushButton *playAllButton = new QPushButton(tr("Play All"), topButtonWidget);
229  QPushButton *shareButton = new QPushButton(tr("Share"), topButtonWidget);
230 
231  playAllButton->setIcon(QIcon(":/contextMenu/btn_play_white"));
232  playAllButton->setIconSize(QSize(14, 14));
233  playAllButton->setCursor(QCursor(Qt::PointingHandCursor));
234  shareButton->setCursor(QCursor(Qt::PointingHandCursor));
235  playAllButton->setFixedSize(90, 30);
236  shareButton->setFixedSize(55, 30);
237 
238  topButtonLayout->addWidget(playAllButton);
239  topButtonLayout->addWidget(shareButton);
240  topButtonLayout->addStretch(1);
241  topButtonWidget->setLayout(topButtonLayout);
242  topLineLayout->addWidget(topButtonWidget);
243 
244  connect(playAllButton, SIGNAL(clicked()), SLOT(playAllButtonClicked()));
245  connect(shareButton, SIGNAL(clicked()), SLOT(shareButtonClicked()));
246  //
247  QWidget *topRightWidget = new QWidget(topFuncWidget);
248  QGridLayout *topRightLayout = new QGridLayout(topRightWidget);
249  topRightLayout->setContentsMargins(0, 0, 0, 0);
250  topRightLayout->setSpacing(0);
251 
252  QLabel *numberLabel = new QLabel(topRightWidget);
253  numberLabel->setAlignment(Qt::AlignCenter);
254  numberLabel->setStyleSheet(TTK::UI::FontStyle06 + TTK::UI::ColorStyle11);
255 
256  const int number = 7 + TTK::random(3);
257  numberLabel->setText(QString("%1.%2").arg(number).arg(TTK::random(10)));
258  topRightLayout->addWidget(numberLabel, 0, 0);
259  topRightLayout->addWidget(new MusicRatingLabel(std::ceil(number / 2.0), topRightWidget), 0, 1, 1, 6);
260 
261  QLabel *numberTextLabel = new QLabel(tr("Score:"), topRightWidget);
262  topRightLayout->addWidget(numberTextLabel, 1, 0);
263  topRightLayout->addWidget(new MusicRatingLabel(topRightWidget), 1, 1, 1, 6);
264 
265  QLabel *marginBottmLabel = new QLabel(topRightWidget);
266  marginBottmLabel->setFixedHeight(40);
267  topRightLayout->addWidget(marginBottmLabel, 2, 0);
268  topRightWidget->setLayout(topRightLayout);
269 
270  QRCodeQWidget *code = new QRCodeQWidget({}, QSize(90, 90), topRightWidget);
271  code->setMargin(2);
272  code->setIcon(":/image/lb_app_logo", 0.23);
273  topRightLayout->addWidget(code, 3, 2, 1, 6);
274 
275  topFuncLayout->addWidget(m_iconLabel);
276  topFuncLayout->addWidget(topLineWidget);
277  topFuncLayout->addWidget(topRightWidget);
278  topFuncWidget->setLayout(topFuncLayout);
279  grid->addWidget(topFuncWidget);
280  //
281  QWidget *functionWidget = new QWidget(this);
282  functionWidget->setStyleSheet(TTK::UI::PushButtonStyle03);
283  QHBoxLayout *hLayout = new QHBoxLayout(functionWidget);
284 
285  m_songButton = new QPushButton(functionWidget);
286  m_songButton->setText(tr("SongItems"));
287  m_songButton->setFixedSize(100, 25);
288  m_songButton->setCursor(QCursor(Qt::PointingHandCursor));
289  hLayout->addWidget(m_songButton);
290  hLayout->addStretch(1);
291  functionWidget->setLayout(hLayout);
292 
293  QButtonGroup *buttonGroup = new QButtonGroup(this);
294  buttonGroup->addButton(m_songButton, 0);
295  QtButtonGroupConnect(buttonGroup, m_container, setCurrentIndex, TTK_SLOT);
296 
297 #ifdef Q_OS_UNIX
298  playAllButton->setFocusPolicy(Qt::NoFocus);
299  shareButton->setFocusPolicy(Qt::NoFocus);
300  m_songButton->setFocusPolicy(Qt::NoFocus);
301 #endif
302  grid->addWidget(functionWidget);
303  grid->addWidget(m_container);
304  grid->addStretch(1);
305 
306  function->setLayout(grid);
307  m_mainWidget->layout()->addWidget(function);
308 
309  m_resizeWidgets.append({firstLabel, firstLabel->font()});
310  m_resizeWidgets.append({albumLabel, albumLabel->font()});
311  m_resizeWidgets.append({singerLabel, singerLabel->font()});
312  m_resizeWidgets.append({languageLabel, languageLabel->font()});
313  m_resizeWidgets.append({companyLabel, companyLabel->font()});
314  m_resizeWidgets.append({yearLabel, yearLabel->font()});
315 }
const TTK::MusicSongInformationList & items() const noexcept
void setQueryInput(MusicAbstractQueryRequest *query)
The class of the search result data item.
void setQueryMode(QueryMode mode) noexcept
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:276
static const QString FontStyle03
static bool isCoverValid(const QString &url) noexcept
virtual void resizeGeometry() overridefinal
virtual void startToRequest(const QString &url)=0
static const QString CheckBoxStyle01
CheckBox.
virtual void setCurrentKey(const QString &id) overridefinal
static const QString ColorStyle04
Definition: musicuiobject.h:46
void setIcon(const QString &path, float percent)
virtual void setCurrentValue(const QString &value)
static const QString FontStyle01
Font.
void setMargin(const int margin)
The class of the query item table widget.
void downloadFinished(const QByteArray &bytes)
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
Definition: ttktime.cpp:14
virtual void setCurrentValue(const QString &value) overridefinal
MusicAbstractQueryRequest * queryInput() const
#define qAsConst
Definition: ttkqtglobal.h:57
static const QString FontStyle06
static const QString PushButtonStyle03
The class of the qr code widget.
Definition: qrcodewidget.h:31
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
#define TTK_SLOT
Definition: ttkqtglobal.h:177
MusicAlbumQueryWidget(QWidget *parent=nullptr)
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:115
The class of the rating label.
The class of the item query widget base.
Definition: inftrees.h:24
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:172
MusicAbstractQueryRequest * m_networkRequest
void createAlbumItem(const MusicResultDataItem &item)
virtual void startToSearchByValue(const QString &value) overridefinal
static const QString ColorStyle11
Definition: musicuiobject.h:67
#define G_DOWNLOAD_QUERY_PTR
MusicItemQueryTableWidget * m_tableWidget
The class of the cover data download request.
virtual void startToSearch(const QString &value)=0
The class of the abstract query data from net.
virtual void resizeGeometry() overridefinal
MusicSongSharingWidget::Module m_shareType
The class of the music song information.
Definition: musicobject.h:300
#define G_SETTING_PTR