TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicplaylistcategorywidget.cpp
Go to the documentation of this file.
4 #include "musicrightareawidget.h"
5 #include "musicwidgetutils.h"
6 #include "musicwidgetheaders.h"
7 #include "ttkclickedgroup.h"
8 #include "ttkclickedlabel.h"
9 
11 {
12  enum
13  {
14  New,
16  };
17 
18  struct Property
19  {
20  int m_index;
21  int m_type;
22  };
23 
24  CategoryProperty(const QString &tag, const QList<Property> &property)
25  : m_tag(tag),
26  m_property(property)
27  {
28 
29  }
30 
31  QString m_tag;
33  QList<Property> m_property;
34 };
36 
37 
38 static constexpr int ITEM_MAX_COLUMN = 6;
39 static constexpr int ITEM_LABEL_HEIGHT = 20;
40 static constexpr int LINE_SPACING_SIZE = 75;
41 
43 
44 class CategoryMultiItem : public QWidget
45 {
46 public:
47  CategoryMultiItem(const QString &text, const QString &icon, QWidget *parent = nullptr)
48  : QWidget(parent)
49  {
50  QHBoxLayout *layout = new QHBoxLayout(this);
51  layout->setSpacing(0);
52  layout->setContentsMargins(0, 0, 0, 0);
53  setLayout(layout);
54 
55  m_item = new CategorySingleItem(text, this);
56  layout->addWidget(m_item);
57 
58  QLabel *ico = new QLabel(this);
59  ico->setPixmap(QPixmap(icon));
60  layout->addWidget(ico);
61  }
62 
64 };
65 
66 
68  : QWidget(parent)
69 {
70  QHBoxLayout *layout = new QHBoxLayout(this);
71  layout->setContentsMargins(20, 0, 20, 0);
72 
73  QWidget *leftLabel = new QWidget(this);
74  QVBoxLayout *leftLabelLayout = new QVBoxLayout(leftLabel);
75  leftLabelLayout->addStretch();
76  leftLabel->setFixedWidth(100);
77  leftLabel->setLayout(leftLabelLayout);
78  layout->addWidget(leftLabel);
79 
80  QLabel *iconLabel = new QLabel(leftLabel);
81  iconLabel->setFixedSize(38, 38);
82  iconLabel->setPixmap(QPixmap(":/playlist/" + category->m_tag));
83  leftLabelLayout->addWidget(iconLabel, 0, Qt::AlignCenter);
84 
85  QLabel *textLabel = new QLabel(category->m_category.m_category, leftLabel);
86  textLabel->setStyleSheet(TTK::UI::ColorStyle03 + TTK::UI::FontStyle03);
87  leftLabelLayout->addWidget(textLabel, 0, Qt::AlignCenter);
88  leftLabelLayout->addStretch();
89 
90  QWidget *item = new QWidget(this);
91  m_gridLayout = new QGridLayout(item);
92  m_gridLayout->setContentsMargins(0, 10, 0, 10);
93 
94  TTKClickedGroup *clickedGroup = new TTKClickedGroup(this);
95  connect(clickedGroup, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
96 
97  const MusicResultsCategoryItemList &items = category->m_category.m_items;
98 
99  for(int i = 0; i < items.count(); ++i)
100  {
101  QWidget *label = nullptr;
102 
103  for(const CategoryProperty::Property &property : qAsConst(category->m_property))
104  {
105  if(property.m_index != i)
106  {
107  continue;
108  }
109 
110  const QString &icon = property.m_type == CategoryProperty::New ? "lb_new" : "lb_hot";
111  label = new CategoryMultiItem(items[i].m_value, ":/playlist/" + icon, item);
112  clickedGroup->mapped(TTKStaticCast(CategoryMultiItem*, label)->m_item);
113  }
114 
115  if(!label)
116  {
117  label = new CategorySingleItem(items[i].m_value, item);
118  clickedGroup->mapped(label);
119  }
120 
121  label->setProperty("key", items[i].m_key);
122  label->setProperty("value", items[i].m_value);
123  label->setStyleSheet(QString("QLabel::hover{ %1 }").arg(TTK::UI::ColorStyle07));
124  label->setFixedSize(LINE_SPACING_SIZE, ITEM_LABEL_HEIGHT);
125 
126  m_items << label;
127  m_gridLayout->addWidget(label, i / ITEM_MAX_COLUMN, i % ITEM_MAX_COLUMN, Qt::AlignLeft);
128  }
129 
130  item->setLayout(m_gridLayout);
131  layout->addWidget(item);
132 }
133 
135 {
136  qDeleteAll(m_items);
137  delete m_gridLayout;
138 }
139 
141 {
142  for(QWidget *item : qAsConst(m_items))
143  {
144  m_gridLayout->removeWidget(item);
145  }
146 
147  const int lineNumber = (G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width() - LEFT_SIDE_WIDTH_MIN - 350) / LINE_SPACING_SIZE;
148  for(int i = 0; i < m_items.count(); ++i)
149  {
150  m_gridLayout->addWidget(m_items[i], i / lineNumber, i % lineNumber, Qt::AlignLeft);
151  }
152 }
153 
155 {
156  if(index < 0 || index >= m_items.count())
157  {
158  return;
159  }
160 
161  const QString &key = m_items[index]->property("key").toString();
162  const QString &value = m_items[index]->property("value").toString();
164 }
165 
166 void MusicPlaylistCategoryItem::resizeEvent(QResizeEvent *event)
167 {
168  QWidget::resizeEvent(event);
169  resizeWindow();
170 }
171 
172 
174  : QFrame(parent)
175 {
176  initialize();
177 }
178 
180 {
181  qDeleteAll(m_items);
182 }
183 
185 {
187  {
188  item->resizeWindow();
189  }
190 }
191 
193 {
194  QVBoxLayout *layout = new QVBoxLayout(this);
195  layout->setSpacing(0);
196  layout->setContentsMargins(0, 0, 0, 0);
197  setLayout(layout);
198 
199  setStyleSheet(TTK::UI::BackgroundStyle10);
200 
201  QWidget *containWidget = new QWidget(this);
202  QVBoxLayout *containLayout = new QVBoxLayout(containWidget);
203  containWidget->setLayout(containLayout);
204 
205  QScrollArea *scrollArea = new QScrollArea(this);
206  TTK::Widget::generateVScrollAreaStyle(scrollArea, containWidget);
207  layout->addWidget(scrollArea);
208 
209  CategoryPropertyList items;
210  QString server = QUERY_WY_INTERFACE;
211 
213  {
215  {
216  server = QUERY_WY_INTERFACE;
217  items.append({"h", {{0, CategoryProperty::Hot}, {3, CategoryProperty::New}, {4, CategoryProperty::New}}});
219  items.append({"a", {{2, CategoryProperty::New}, {7, CategoryProperty::New}, {8, CategoryProperty::New}}});
220  items.append({"g", {{1, CategoryProperty::Hot}, {3, CategoryProperty::New}, {9, CategoryProperty::New}}});
221  items.append({"i", {{0, CategoryProperty::New}, {1, CategoryProperty::Hot}, {8, CategoryProperty::New}, {15, CategoryProperty::New}}});
222  break;
223  }
225  {
226  server = QUERY_KW_INTERFACE;
227  items.append({"i", {{0, CategoryProperty::Hot}, {3, CategoryProperty::New}, {8, CategoryProperty::New}, {13, CategoryProperty::New}}});
228  items.append({"g", {{1, CategoryProperty::Hot}, {7, CategoryProperty::New}}});
229  items.append({"a", {{0, CategoryProperty::New}, {1, CategoryProperty::Hot}, {8, CategoryProperty::New}, {15, CategoryProperty::New}}});
230  items.append({"d", {{2, CategoryProperty::Hot}}});
231  items.append({"b", {{2, CategoryProperty::New}, {7, CategoryProperty::New}, {15, CategoryProperty::Hot}, {16, CategoryProperty::New}}});
232  items.append({"h", {{0, CategoryProperty::Hot}, {5, CategoryProperty::New}}});
233  break;
234  }
236  {
237  server = QUERY_KG_INTERFACE;
239  items.append({"i", {{3, CategoryProperty::New}, {5, CategoryProperty::New}, {11, CategoryProperty::Hot}, {13, CategoryProperty::New}}});
240  items.append({"h", {{0, CategoryProperty::Hot}, {6, CategoryProperty::New}}});
241  items.append({"b", {{0, CategoryProperty::Hot}, {4, CategoryProperty::New}, {10, CategoryProperty::New}, {16, CategoryProperty::New}}});
242  items.append({"g", {{1, CategoryProperty::Hot}, {3, CategoryProperty::New}, {12, CategoryProperty::New}}});
243  items.append({"d", {{0, CategoryProperty::Hot}}});
244  items.append({"c", {{2, CategoryProperty::New}, {5, CategoryProperty::New}, {9, CategoryProperty::Hot}}});
245  break;
246  }
247  default: break;
248  }
249 
250  MusicResultsCategoryList categorys;
251  MusicCategoryConfigManager manager(server);
253  manager.readBuffer(categorys);
254 
255  if(items.count() != categorys.count() - 1)
256  {
257  TTK_ERROR_STREAM("Playlist tags is not the same from category");
258  return;
259  }
260 
261  for(int i = 0; i < categorys.count() - 1; ++i)
262  {
263  items[i].m_category = categorys[i + 1];
264 
265  MusicPlaylistCategoryItem *item = new MusicPlaylistCategoryItem(&items[i], this);
266  containLayout->addWidget(item);
267  m_items << item;
268 
269  QFrame *line = new QFrame(this);
270  line->setFrameShape(QFrame::HLine);
271  line->setStyleSheet(TTK::UI::ColorStyle12);
272  containLayout->addWidget(line);
273  }
274 }
static MusicRightAreaWidget * instance()
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
TTK_DECLARE_LIST(CategoryProperty)
MusicPlaylistCategoryWidget(QWidget *parent=nullptr)
static const QString FontStyle03
static constexpr int ITEM_MAX_COLUMN
static constexpr const char * QUERY_KG_INTERFACE
static constexpr wchar_t key[]
TTKClickedLabel CategorySingleItem
The class of the label widget that can click.
virtual bool readBuffer(MusicResultsCategoryList &items) overridefinal
static constexpr int ITEM_LABEL_HEIGHT
static const QString ColorStyle12
Definition: musicuiobject.h:70
void mapped(QWidget *widget)
The class of the results category core.
#define qAsConst
Definition: ttkqtglobal.h:51
static constexpr int LINE_SPACING_SIZE
static constexpr const char * QUERY_WY_INTERFACE
QList< MusicPlaylistCategoryItem * > m_items
MusicPlaylistCategoryItem(CategoryProperty *category, QWidget *parent=nullptr)
The class of the playlist music category item.
The class of the category config manager.
static constexpr const char * QUERY_KW_INTERFACE
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
virtual void resizeWidget() overridefinal
MusicResultsCategory m_category
static const QString BackgroundStyle10
static const QString ColorStyle07
Definition: musicuiobject.h:55
CategoryMultiItem(const QString &text, const QString &icon, QWidget *parent=nullptr)
static const QString ColorStyle03
Definition: musicuiobject.h:43
virtual void resizeEvent(QResizeEvent *event) overridefinal
void showPlaylistCategoryFound(const QString &id, const QString &value)
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:70
MusicResultsCategoryItemList m_items
The class of the label widget click group mapper.
CategoryProperty(const QString &tag, const QList< Property > &property)
#define G_SETTING_PTR
#define LEFT_SIDE_WIDTH_MIN
Definition: musicobject.h:157