TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicbackgroundskindialog.cpp
Go to the documentation of this file.
2 #include "ui_musicbackgroundskindialog.h"
7 #include "musictopareawidget.h"
9 #include "musicfileutils.h"
10 #include "musicsettingmanager.h"
11 #include "musicextractwrapper.h"
12 
13 static constexpr int CURRENT_ITEMS_COUNT = 58;
14 
16  : MusicAbstractMoveDialog(parent),
17  m_ui(new Ui::MusicBackgroundSkinDialog),
18  m_stackThemeIndex(CURRENT_ITEMS_COUNT)
19 {
20  m_ui->setupUi(this);
21  setFixedSize(size());
22  setBackgroundLabel(m_ui->background);
23 
24  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
25  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
26  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
27  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
28  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
29 
30  m_ui->paletteButton->setStyleSheet(TTK::UI::PushButtonStyle04);
31  m_ui->customSkin->setStyleSheet(TTK::UI::PushButtonStyle04);
32  m_ui->stackedWidget->setLength(m_ui->stackedWidget->width(), MusicAnimationStackedWidget::Module::RightToLeft);
33 #ifdef Q_OS_UNIX
34  m_ui->paletteButton->setFocusPolicy(Qt::NoFocus);
35  m_ui->customSkin->setFocusPolicy(Qt::NoFocus);
36  m_ui->resetWindowButton->setFocusPolicy(Qt::NoFocus);
37  m_ui->skinTransparentLabelBox->setFocusPolicy(Qt::NoFocus);
38 #endif
39  connect(m_ui->skinAnimationSiwidget, SIGNAL(buttonClicked(int)), SLOT(backgroundListWidgetChanged(int)));
40 
44 
48 
51 
54 
57 
58  m_ui->resetWindowButton->setStyleSheet(TTK::UI::BtnResetWindow);
59  m_ui->skinTransparentButton->setStyleSheet(TTK::UI::ToolButtonStyle05);
60  m_ui->listTransparentButton->setStyleSheet(TTK::UI::ToolButtonStyle05);
61 
62  m_ui->skinTransparentButton->setEnabled(false);
63  m_ui->skinTransparentLabelBox->setStyleSheet(TTK::UI::CheckBoxStyle04);
64  m_ui->listTransparentLabel->setStyleSheet(TTK::UI::ColorStyle03);
65 
66  connect(m_ui->skinTransparentLabelBox, SIGNAL(clicked(bool)), SLOT(windowTransparentChanged(bool)));
67  connect(m_ui->skinTransparentButton, SIGNAL(valueChanged(int)), MusicTopAreaWidget::instance(), SLOT(backgroundTransparentChanged(int)));
68  connect(m_ui->skinTransparentButton, SIGNAL(sliderStateChanged(bool)), MusicTopAreaWidget::instance(), SLOT(backgroundAnimationChanged(bool)));
69  connect(m_ui->listTransparentButton, SIGNAL(valueChanged(int)), MusicTopAreaWidget::instance(), SLOT(playlistTransparent(int)));
70  connect(m_ui->paletteButton, SIGNAL(clicked()), SLOT(showPaletteDialog()));
71  connect(m_ui->customSkin, SIGNAL(clicked()) ,SLOT(showCustomSkinDialog()));
72  connect(m_ui->resetWindowButton, SIGNAL(clicked()), MusicApplicationModule::instance(), SLOT(resetWindowGeometry()));
73 
74  connect(m_cacheBackgroundList, SIGNAL(itemClicked(int,QString)), SLOT(classicalListWidgetItemClicked(int,QString)));
75  connect(m_stackBackgroundList, SIGNAL(itemClicked(int,QString)), SLOT(classicalListWidgetItemClicked(int,QString)));
76 }
77 
79 {
80  delete m_ui;
81  delete m_cacheBackgroundList;
82  delete m_stackBackgroundList;
83  delete m_dailyBackgroundList;
85 }
86 
88 {
89  QString path = USER_THEME_DIR_FULL + name + TKM_FILE;
91  G_BACKGROUND_PTR->setBackgroundUrl(path);
92 
94  return MusicExtractWrapper::outputSkin(&image, path) ? image.m_pix : QPixmap();
95 }
96 
97 bool MusicBackgroundSkinDialog::themeValidCheck(QString &name, QString &path)
98 {
99  if(!QFile::exists(path))
100  {
101  QString orPath = QString("%1%2%3").arg(THEME_DIR_FULL, name, TKM_FILE);
102  if(QFile::exists(orPath))
103  {
104  QFile::copy(orPath, QString("%1%2%3").arg(USER_THEME_DIR_FULL, name, TKM_FILE));
105  }
106  else
107  {
108  name = "theme-1";
109  orPath = QString("%1%2%3").arg(THEME_DIR_FULL, name, TKM_FILE);
110  QFile::copy(orPath, QString("%1%2%3").arg(USER_THEME_DIR_FULL, name, TKM_FILE));
111  }
112  return false;
113  }
114  return true;
115 }
116 
118 {
119  const int index = cpoyFileToLocal(path);
120  return (index != -1) ? QString("theme-%1").arg(index + 1) : QString();
121 }
122 
124 {
125  const QString &des = QString("%1%2%3").arg(USER_THEME_DIR_FULL, theme, TKM_FILE);
126  m_stackBackgroundList->addCellItem(theme, des, true);
128 }
129 
130 void MusicBackgroundSkinDialog::setCurrentBackgroundTheme(const QString &theme, int skin, int list)
131 {
134  //Set the the slider bar value as what the alpha is
135  m_ui->listTransparentButton->setValue(list);
136  setListTransToolText(list);
137 
139  m_ui->skinTransparentButton->setValue(state ? skin : 0);
140  m_ui->skinTransparentButton->setEnabled(state);
141  setSkinTransToolText(state ? skin : 0);
142  m_ui->skinTransparentLabelBox->setChecked(state);
143 }
144 
146 {
147  return m_ui->listTransparentButton->value();
148 }
149 
151 {
152  return m_ui->skinTransparentLabelBox->isChecked();
153 }
154 
156 {
157  m_ui->skinTransparentButton->setText(QString("%1%").arg(value));
158 }
159 
161 {
162  m_ui->listTransparentButton->setText(QString("%1%").arg(value));
163 }
164 
166 {
167  MusicBackgroundPaletteWidget widget(this);
168  connect(&widget, SIGNAL(currentColorToFileChanged(QString)), SLOT(showPaletteDialog(QString)));
169  connect(&widget, SIGNAL(currentColorToMemoryChanged(QString)), SLOT(currentColorChanged(QString)));
170  widget.exec();
171 }
172 
174 {
175  cpoyFileFromLocal(path);
177 }
178 
180 {
181  const QString &path = TTK::File::getOpenFileName(this, "Image Files (*.png *.bmp *.jpg);;TKM Files (*.tkm)");
182  if(path.isEmpty())
183  {
184  return;
185  }
186 
187  if(TTK_FILE_SUFFIX(QFileInfo(path)) == TKM_FILE_SUFFIX)
188  {
189  const int index = cpoyFileToLocalIndex();
190  if(index != -1)
191  {
192  m_stackThemeIndex = index;
193  const QString &des = QString("%1theme-%2%3").arg(USER_THEME_DIR_FULL).arg(index + 1).arg(TKM_FILE);
194  QFile::copy(path, des);
195  m_stackBackgroundList->addCellItem(QString("theme-%1").arg(index + 1), des, true);
196  }
197  }
198  else
199  {
200  cpoyFileFromLocal(path);
201  }
203 }
204 
206 {
207  QWidget *toolWidget = m_onlineBackgroundList->createFunctionsWidget(index != 3, this);
208  if(!toolWidget->isVisible())
209  {
210  toolWidget->show();
211  QRect rect = m_ui->stackedWidget->geometry();
212  m_ui->stackedWidget->setGeometry(QRect(rect.x(), rect.y() + toolWidget->height(), rect.width(), rect.height() - toolWidget->height()));
213  }
214 
215  if(m_ui->stackedWidget->currentIndex() == index)
216  {
217  return;
218  }
219  //
222  //
223  if(index == 2)
224  {
226  }
227  else if(index == 3)
228  {
230  }
231  //
232  m_ui->stackedWidget->setIndex(0, 0);
233  m_ui->stackedWidget->start(index);
234 }
235 
237 {
239  {
240  if(!m_stackBackgroundList->contains(name))
241  {
242  const QString &path = QString("%1%2%3").arg(USER_THEME_DIR_FULL, name, TKM_FILE);
243  QFile::copy(QString("%1%2%3").arg(THEME_DIR_FULL, name, TKM_FILE), path);
244  m_stackBackgroundList->addCellItem(name, path, true);
245  }
247  }
248  else
249  {
251  }
252 }
253 
255 {
256  switch(type)
257  {
260  default: break;
261  }
262 }
263 
265 {
266  if(path.contains(TTK_COLOR_FILE))
267  {
269  }
270  else
271  {
272  MusicTopAreaWidget::instance()->backgroundSkinChanged(QFileInfo(path).baseName());
273  }
274 
275  G_BACKGROUND_PTR->setBackgroundUrl(path);
276  G_BACKGROUND_PTR->backgroundUrlChanged();
277 }
278 
280 {
281  m_ui->skinTransparentButton->setEnabled(state);
283  if(!state)
284  {
285  m_ui->skinTransparentButton->setValue(0);
287  }
288 }
289 
291 {
293 
294  item->clearState();
295  item->setCurrentItemName(name);
296 
297  QString s(name);
298  QString path = USER_THEME_DIR_FULL + s + TKM_FILE;
300 
301  G_BACKGROUND_PTR->setBackgroundUrl(path);
302  G_BACKGROUND_PTR->backgroundUrlChanged();
303 }
304 
306 {
307  MusicBackgroundImage image;
308  item->outputRemoteSkin(image, name);
309  if(!image.isValid())
310  {
311  return;
312  }
313 
315  if(!m_stackBackgroundList->contains(image))
316  {
317  const int index = cpoyFileToLocalIndex();
318  const QString &theme = QString("theme-%1").arg(index + 1);
319  const QString &des = QString("%1%2%3").arg(USER_THEME_DIR_FULL, theme, TKM_FILE);
320  MusicExtractWrapper::inputSkin(&image, des);
321 
322  m_stackBackgroundList->addCellItem(theme, des, true);
324  }
325  else
326  {
328  if(it)
329  {
331  }
332  }
333 }
334 
336 {
339 }
340 
342 {
343  TTKIntList data;
344  findThemeListByPath(dir, data);
345  std::sort(data.begin(), data.end());
346 
347  for(const int index : qAsConst(data))
348  {
349  const QFileInfo fin(QString("%1theme-%2%3").arg(dir).arg(index).arg(TKM_FILE));
350  item->addCellItem(fin.baseName(), fin.filePath(), state);
351  }
352 }
353 
355 {
356  const int index = cpoyFileToLocal(path);
357  if(index != -1)
358  {
359  m_stackThemeIndex = index;
360  const QString &des = QString("%1theme-%2%3").arg(USER_THEME_DIR_FULL).arg(m_stackThemeIndex + 1).arg(TKM_FILE);
361  m_stackBackgroundList->addCellItem(QString("theme-%1").arg(m_stackThemeIndex + 1), des, true);
362  }
363 }
364 
366 {
367  data.clear();
368  const QStringList files(QDir(dir).entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name));
369 
370  for(const QString &path : qAsConst(files))
371  {
372  const QFileInfo fin(path);
373  if(TTK_FILE_SUFFIX(fin) != TKM_FILE_SUFFIX)
374  {
375  continue;
376  }
377 
378  const QStringList &list = fin.baseName().split(TTK_DEFAULT_STR);
379  if(list.count() < 2)
380  {
381  continue;
382  }
383 
384  const QString &fileName = list.back();
385  data << fileName.trimmed().toInt();
386  }
387 }
388 
390 {
391  TTKIntList data;
393  std::sort(data.begin(), data.end(), std::greater<int>());
394 
395  int index = CURRENT_ITEMS_COUNT;
396  if(!data.isEmpty())
397  {
398  index = data.front();
399  if(index < CURRENT_ITEMS_COUNT)
400  {
401  index = CURRENT_ITEMS_COUNT;
402  }
403  }
404 
405  return index;
406 }
407 
409 {
410  const int index = cpoyFileToLocalIndex();
411 
412  const QString &des = QString("%1theme-%2%3").arg(USER_THEME_DIR_FULL).arg(index + 1).arg(TKM_FILE);
413  MusicBackgroundImage image;
414  image.m_pix = QPixmap(path);
415  return MusicExtractWrapper::inputSkin(&image, des) ? index : -1;
416 }
void setBackgroundLabel(QLabel *label)
The class of the remote background widget.
MusicBackgroundDailyWidget * m_dailyBackgroundList
static const QString ToolButtonStyle05
static QString cpoyArtistFileToLocal(const QString &path)
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
#define G_BACKGROUND_PTR
static constexpr int CURRENT_ITEMS_COUNT
static QPixmap setBackgroundUrl(QString &name)
#define TKM_FILE_SUFFIX
Definition: musicobject.h:29
The class of the local background widget.
voidpf void uLong size
Definition: ioapi.h:136
The class of the daily background widget.
The class of the background list item.
MusicBackgroundListWidget * m_cacheBackgroundList
#define THEME_DIR_FULL
Definition: musicobject.h:142
TTK_MODULE_EXPORT QString getOpenFileName(QWidget *parent, const QString &filter="Image Files (*.png *.bmp *.jpg)")
void currentColorChanged(const QString &path)
void addCellItem(const QString &icon, bool state)
Ui::MusicBackgroundSkinDialog * m_ui
#define USER_THEME_DIR_FULL
Definition: musicobject.h:139
void listWidgetItemClicked(MusicBackgroundListWidget *item, const QString &name)
The class of the background list widget.
MusicBackgroundSkinDialog(QWidget *parent=nullptr)
static bool themeValidCheck(QString &name, QString &path)
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
#define qAsConst
Definition: ttkqtglobal.h:53
The class of the skin backgroud image.
const char * name
Definition: http_parser.c:458
void remoteListWidgetItemClicked(int type, const QString &name)
static const QString CheckBoxStyle04
#define TTK_COLOR_FILE
static const QString PushButtonStyle04
QWidget * createFunctionsWidget(bool revert, QWidget *object=nullptr)
static constexpr const char * BtnResetWindow
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data)=0
static int cpoyFileToLocal(const QString &path)
The class of the moving dialog base.
bool contains(const QString &name) const
MusicBackgroundOnlineWidget * m_onlineBackgroundList
#define TKM_FILE
Definition: musicobject.h:59
static const QString ColorStyle03
Definition: musicuiobject.h:43
int find(MusicBackgroundListItem *item) const
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
void classicalListWidgetItemClicked(int type, const QString &name)
void backgroundSkinChanged(const QString &fileName)
void updateArtistFileTheme(const QString &theme)
void cpoyFileFromLocal(const QString &path)
static void findThemeListByPath(const QString &dir, TTKIntList &data)
static MusicApplicationModule * instance()
static bool outputSkin(MusicBackgroundImage *image, const QString &input)
void setCurrentItemName(const QString &name)
static bool inputSkin(MusicBackgroundImage *image, const QString &output)
static const QString ToolButtonStyle04
The class of the background palette widget.
#define TTK_FILE_SUFFIX(fin)
Definition: ttkqtglobal.h:173
The class of the online background widget.
void setCurrentBackgroundTheme(const QString &theme, int skin, int list)
static MusicTopAreaWidget * instance()
state
Definition: http_parser.c:279
#define G_SETTING_PTR
MusicBackgroundListWidget * m_stackBackgroundList