TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicbackgroundmanager.cpp
Go to the documentation of this file.
2 #include "musicsong.h"
3 
5  : m_currentIndex(0)
6 {
7 
8 }
9 
11 {
14 }
15 
17 {
18  return m_currentArtistName;
19 }
20 
22 {
24 }
25 
27 {
29 }
30 
32 {
33  if(m_images.isEmpty())
34  {
35  return {};
36  }
37 
39 }
40 
42 {
43  if(m_images.isEmpty())
44  {
45  return {};
46  }
47 
48  const int index = m_currentIndex - 1;
49  return (-1 < index && index < m_images.count()) ? m_images[index] : QString();
50 }
51 
53 {
54  m_images.clear();
55  m_currentIndex = 0;
56 
57  const QString &filter = BACKGROUND_DIR_FULL + m_currentArtistName + "-%1" + SKN_FILE;
58  for(int i = 0; i < MAX_IMAGE_COUNT; ++i)
59  {
60  QFile file(filter.arg(i));
61  if(file.exists() && file.open(QIODevice::ReadOnly))
62  {
63  if(file.size() > 0)
64  {
65  m_images << file.fileName();
66  }
67  file.close();
68  }
69  }
70 
71  Q_EMIT artistChanged();
72 }
73 
75 {
76  return m_images;
77 }
78 
79 void MusicBackgroundManager::setArtistImageList(const QStringList &list) noexcept
80 {
81  m_images = list;
82 }
83 
85 {
86  m_currentIndex = index;
87  Q_EMIT selectIndexChanged();
88 }
89 
91 {
92  m_observer << object;
93  connect(this, SIGNAL(backgroundChanged()), object, SLOT(backgroundChanged()));
94 }
95 
97 {
98  m_observer.removeOne(object);
99  disconnect(this, SIGNAL(backgroundChanged()), object, SLOT(backgroundChanged()));
100 }
101 
102 void MusicBackgroundManager::setBackgroundUrl(const QString &path) noexcept
103 {
104  m_background = path;
105  Q_EMIT backgroundChanged();
106 }
107 
109 {
110  return m_background;
111 }
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:121
void removeObserver(QObject *object)
QString artistImagePath() noexcept
void setSelectArtistIndex(int index) noexcept
void setBackgroundUrl(const QString &path) noexcept
QStringList artistImageList() const noexcept
QString backgroundUrl() const noexcept
const char * name
Definition: http_parser.c:458
void addObserver(QObject *object)
#define MAX_IMAGE_COUNT
void setArtistImageList(const QStringList &list) noexcept
#define BACKGROUND_DIR_FULL
Definition: musicobject.h:143
QString artistName() const noexcept
#define const
Definition: zconf.h:233
#define SKN_FILE
Definition: musicobject.h:69
QString artistImageDefaultPath() const noexcept
void setArtistName(const QString &name)