TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicbackgroundremotewidget.cpp
Go to the documentation of this file.
6 #include "musicextractwrapper.h"
7 #include "musicwidgetheaders.h"
8 #include "musicwidgetutils.h"
9 
10 #include <QDir>
11 
13  : QWidget(parent),
14  m_currentIndex(-1),
15  m_downloadRequest(nullptr)
16 {
17  QHBoxLayout *hbox = new QHBoxLayout(this);
18  hbox->setContentsMargins(0, 0, 0, 0);
19  hbox->setSpacing(0);
20 
22  hbox->addWidget(m_backgroundList);
23  setLayout(hbox);
24 
26  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), SLOT(downLoadFinished(QString)));
27  connect(m_backgroundList, SIGNAL(itemClicked(int,QString)), parent, SLOT(remoteListWidgetItemClicked(int,QString)));
28 }
29 
31 {
32  abort();
33  delete m_backgroundList;
34  delete m_networkRequest;
35  delete m_downloadRequest;
36 }
37 
39 {
41 }
42 
44 {
45  if(m_groups.isEmpty())
46  {
47  return;
48  }
49 
51  outputRemoteSkin(image, bytes);
52  if(!image.isValid())
53  {
54  image.m_pix = QPixmap(":/image/lb_none_image");
55  }
56 
57  m_backgroundList->updateItem(image, bytes);
58 }
59 
60 void MusicBackgroundRemoteWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
61 {
62  m_groups = bytes;
63 }
64 
66 {
67  if(m_groups.isEmpty())
68  {
69  return;
70  }
71 
72  const QString &path = QString("%1%2").arg(CACHE_DIR_FULL, m_groups[m_currentIndex].m_group);
73  QDir().mkpath(path);
74 
76 
77  MusicDownloadQueueDataList datas;
78  for(const MusicSkinRemoteItem &item : qAsConst(m_groups[m_currentIndex].m_items))
79  {
80  m_backgroundList->addCellItem(":/image/lb_none_image", false);
82  data.m_url = item.m_url;
83  data.m_path = QString("%1/%2%3").arg(path).arg(item.m_index).arg(prefix);
84  datas << data;
85  }
86 
87  m_networkRequest->addQueue(datas);
89 }
90 
91 
92 
95 {
96  m_currentIndex = 0;
98 }
99 
101 {
102  if(!m_downloadRequest)
103  {
105  connect(m_downloadRequest, SIGNAL(downLoadDataChanged(MusicSkinRemoteGroupList)), SLOT(downLoadFinished(MusicSkinRemoteGroupList)));
107  }
108  else
109  {
111  }
112 }
113 
115 {
116  if(m_groups.isEmpty() || m_currentIndex < 0)
117  {
118  return;
119  }
120 
121  for(const MusicSkinRemoteItem &item : qAsConst(m_groups[m_currentIndex].m_items))
122  {
123  if(QFileInfo(data).baseName().toInt() == item.m_index)
124  {
125  image.m_item.m_name = item.m_name;
126  image.m_item.m_useCount = item.m_useCount;
127  image.m_pix = QPixmap(data);
128  break;
129  }
130  }
131 }
132 
133 void MusicBackgroundDailyWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
134 {
137 }
138 
139 
140 
142  : MusicBackgroundRemoteWidget(parent),
143  m_functionsWidget(nullptr)
144 {
146 }
147 
149 {
150  delete m_functionsWidget;
151 }
152 
154 {
155  if(m_typeBox->count() != 0)
156  {
157  m_typeBox->setCurrentIndex(0);
158  }
159 
160  if(!m_downloadRequest)
161  {
163  connect(m_downloadRequest, SIGNAL(downLoadDataChanged(MusicSkinRemoteGroupList)), SLOT(downLoadFinished(MusicSkinRemoteGroupList)));
165  }
166  else
167  {
169  }
170 }
171 
172 QWidget* MusicBackgroundOnlineWidget::createFunctionsWidget(bool revert, QWidget *object)
173 {
174  if(!m_functionsWidget)
175  {
176  m_functionsWidget = new QWidget(object);
177  m_functionsWidget->setGeometry(24, 70, 585, 25);
178  m_functionsWidget->hide();
179 
180  QHBoxLayout *hbox = new QHBoxLayout(m_functionsWidget);
181  hbox->setContentsMargins(9, 0, 0, 9);
182  hbox->addStretch(1);
183 
184  m_typeBox = new QComboBox(m_functionsWidget);
185  m_typeBox->setFixedSize(100, 20);
186  m_typeBox->addItem(tr("Select One"));
187  m_typeBox->hide();
189 
190  m_allButton = new QPushButton(tr("All"), m_functionsWidget);
191  m_allButton->setStyleSheet(TTK::UI::PushButtonStyle02 + QString("QPushButton{%1}").arg(TTK::UI::ColorStyle07));
192  m_allButton->setCursor(QCursor(Qt::PointingHandCursor));
193  m_allButton->setFixedSize(35, 20);
194 #ifdef Q_OS_UNIX
195  m_allButton->setFocusPolicy(Qt::NoFocus);
196 #endif
197  m_allButton->hide();
198 
199  m_functionsWidget->setLayout(hbox);
200  connect(m_typeBox, SIGNAL(currentIndexChanged(int)), SLOT(currentTypeChanged(int)));
201  }
202 
203  QHBoxLayout *layout = TTKObjectCast(QHBoxLayout*, m_functionsWidget->layout());
204  if(revert)
205  {
206  layout->removeWidget(m_typeBox);
207  layout->addWidget(m_allButton);
208  m_allButton->show();
209  m_typeBox->hide();
210  }
211  else
212  {
213  layout->removeWidget(m_allButton);
214  layout->addWidget(m_typeBox);
215  m_allButton->hide();
216  m_typeBox->show();
217  }
218 
219  return m_functionsWidget;
220 }
221 
223 {
224  if(m_groups.isEmpty() || m_currentIndex < 0)
225  {
226  return;
227  }
228 
229  const int index = QFileInfo(data).baseName().toInt();
230  MusicSkinRemoteItemList &items = m_groups[m_currentIndex].m_items;
231  if(index >= 0 || index < items.count())
232  {
233  MusicSkinRemoteItem &item = items[index];
234  image.m_item.m_name = item.m_name;
235  image.m_item.m_useCount = item.m_useCount;
237  }
238 }
239 
241 {
242  index -= 1; // remove first index because it is tips
243  if(index < 0 || index >= m_groups.count())
244  {
245  return;
246  }
247 
248  if(m_currentIndex != index)
249  {
251  }
252 
253  m_currentIndex = index;
255 }
256 
257 void MusicBackgroundOnlineWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
258 {
260  m_typeBox->blockSignals(true);
261  for(int i = 0; i < bytes.count(); ++i)
262  {
263  QString title(m_groups[i].m_group);
264  m_typeBox->addItem(title.remove(SKIN_THUNDER_DIR));
265  }
266  m_typeBox->setCurrentIndex(0);
267  m_typeBox->blockSignals(false);
268 }
The class of the remote background widget.
The class of the remote skin item.
#define CACHE_DIR_FULL
Definition: musicobject.h:130
MusicBackgroundDailyWidget(QWidget *parent=nullptr)
MusicDownloadQueueRequest * m_networkRequest
static bool outputThunderSkin(QPixmap &image, const QString &input)
The class of the download data from queue request.
void addCellItem(const QString &icon, bool state)
The class of the background list widget.
The class of the download bing daily skin background.
static const QString PushButtonStyle02
static constexpr const char * SKIN_THUNDER_DIR
#define qAsConst
Definition: ttkqtglobal.h:53
The class of the skin backgroud image.
void updateItem(const MusicBackgroundImage &image, const QString &path)
void addQueue(const MusicDownloadQueueDataList &datas)
virtual void downLoadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
The class of the download thunder skin background.
QWidget * createFunctionsWidget(bool revert, QWidget *object=nullptr)
MusicBackgroundRemoteWidget(QWidget *parent=nullptr)
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data)=0
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data) overridefinal
void downLoadFinished(const QString &bytes)
virtual void startToRequest() overridefinal
The class of the download queue data.
TTK_MODULE_EXPORT void generateComboBoxFormat(QComboBox *widget, const QString &style={})
static const QString ColorStyle07
Definition: musicuiobject.h:55
#define TKM_FILE
Definition: musicobject.h:59
void startToRequest(const QString &suffix)
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data) overridefinal
MusicAbstractDownloadSkinRequest * m_downloadRequest
MusicBackgroundOnlineWidget(QWidget *parent=nullptr)
QString m_path
download url/
MusicBackgroundListWidget * m_backgroundList
virtual void downLoadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60