TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicemojilabelwidget.cpp
Go to the documentation of this file.
2 #include "musictinyuiobject.h"
3 #include "musicwidgetheaders.h"
4 #include "ttkclickedgroup.h"
5 #include "ttkclickedlabel.h"
6 
7 #include <QFile>
8 #include <QButtonGroup>
9 
11  : QLabel(parent),
12  m_currentPage(-1)
13 {
14  setFixedSize(260, 175);
15  setAttribute(Qt::WA_DeleteOnClose);
16  setStyleSheet("background:white");
17 
18  QVBoxLayout *layout = new QVBoxLayout(this);
19  layout->setSpacing(0);
20  QToolButton *closeButton = new QToolButton(this);
21  closeButton->setFixedSize(16, 16);
22  closeButton->setStyleSheet(TTK::UI::TinyBtnClose);
23  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
24  connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
25 
26  QWidget *labelWidget = new QWidget(this);
27  labelWidget->setFixedHeight(110);
28  //
29  QGridLayout *labelIconLayout = new QGridLayout(labelWidget);
30  labelIconLayout->setContentsMargins(0, 0, 0, 0);
31  labelIconLayout->setSpacing(3);
32 
33  TTKClickedGroup *clickedGroup = new TTKClickedGroup(this);
34  connect(clickedGroup, SIGNAL(clicked(int)), SLOT(labelClicked(int)));
35 
36  for(int i = 0; i < 3; ++i)
37  {
38  for(int j = 0; j < 7; ++j)
39  {
40  TTKClickedLabel *label = new TTKClickedLabel(labelWidget);
41  label->setAlignment(Qt::AlignCenter);
42  label->setStyleSheet(QString("QLabel{%1}QLabel:hover{%2}").arg(TTK::UI::BorderStyle03, TTK::UI::BorderStyle04));
43  label->setFixedSize(32, 32);
44  labelIconLayout->addWidget(label, i, j);
45 
46  m_labelItems << label;
47  clickedGroup->mapped(label);
48  }
49  }
50  labelWidget->setLayout(labelIconLayout);
51  //
52  QWidget *buttonWidget = new QWidget(this);
53  QHBoxLayout *buttonWidgetLayout = new QHBoxLayout(buttonWidget);
54  buttonWidgetLayout->setContentsMargins(0, 0, 5, 0);
55  buttonWidgetLayout->addStretch(1);
56 
57  QButtonGroup *buttonGroup = new QButtonGroup(buttonWidget);
58  QtButtonGroupConnect(buttonGroup, this, buttonClicked, TTK_SLOT);
59 
60  for(int i = 0; i < 5; ++i)
61  {
62  QToolButton *button = new QToolButton(buttonWidget);
63  button->setCursor(Qt::PointingHandCursor);
64  button->setText(QString::number(i + 1));
65  button->setFixedSize(15, 15);
66  buttonWidgetLayout->addWidget(button, 0 , Qt::AlignRight);
67  buttonWidget->setLayout(buttonWidgetLayout);
68  buttonGroup->addButton(button, i);
69  m_buttonItems << button;
70  }
71  buttonClicked(0);
72  //
73  layout->addWidget(closeButton, 0, Qt::AlignRight | Qt::AlignVCenter);
74  layout->addWidget(labelWidget);
75  layout->addWidget(buttonWidget);
76  setLayout(layout);
77 
78  QFile file(":/emoji/db");
79  if(file.open(QIODevice::ReadOnly))
80  {
81  m_datas = QString(file.readAll()).split("\n");
82  file.close();
83  }
84 }
85 
87 {
88  qDeleteAll(m_labelItems);
89  qDeleteAll(m_buttonItems);
90 }
91 
93 {
94  m_currentPage = index;
95  for(QToolButton *button : qAsConst(m_buttonItems))
96  {
97  button->setStyleSheet(TTK::UI::BackgroundStyle01 + TTK::UI::BorderStyle01);
98  }
99  m_buttonItems[index]->setStyleSheet(m_buttonItems[index]->styleSheet() + TTK::UI::BorderStyle03);
100 
101  for(int i = 0; i < 3; ++i)
102  {
103  for(int j = 0; j < 7; ++j)
104  {
105  const int in = i * 7 + j;
106  m_labelItems[in]->setPixmap(QPixmap(QString(":/emoji/%1").arg(21 * index + in + 1)));
107  }
108  }
109 }
110 
112 {
113  const int offset = index + m_currentPage * 21;
114  if(offset < 0 || offset >= m_datas.count())
115  {
116  return;
117  }
118 
119  Q_EMIT dataChanged(m_datas[offset]);
120 }
121 
123 {
124  QLabel::leaveEvent(event);
125  close();
126 }
QList< QToolButton * > m_buttonItems
static const QString BorderStyle01
border
The class of the label widget that can click.
MusicEMOJILabelWidget(QWidget *parent=nullptr)
static const QString BorderStyle04
void mapped(QWidget *widget)
voidpf uLong offset
Definition: ioapi.h:142
#define qAsConst
Definition: ttkqtglobal.h:53
void dataChanged(const QString &data)
static const QString BackgroundStyle01
Background.
Definition: musicuiobject.h:77
#define TTK_SLOT
Definition: ttkqtglobal.h:165
TTK_MODULE_EXPORT QStringList split(const QString &value, const QString &key=TTK_DEFAULT_STR)
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:101
QList< QLabel * > m_labelItems
static const QString BorderStyle03
static constexpr const char * TinyBtnClose
The class of the label widget click group mapper.
virtual void leaveEvent(QEvent *event) overridefinal