TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musiclrcfloatphotowidget.cpp
Go to the documentation of this file.
5 #include "musicwidgetheaders.h"
6 #include "musicimageutils.h"
7 
8 #include <qmath.h>
9 #include <QTimer>
10 
12  : TTKClickedLabel(parent),
13  m_index(index)
14 {
15  setFixedSize(120, 65);
16 
17  m_checkBox = new QCheckBox(this);
18  m_checkBox->setGeometry(100, 45, 16, 16);
20 #ifdef Q_OS_UNIX
21  m_checkBox->setFocusPolicy(Qt::NoFocus);
22 #endif
23  connect(this, SIGNAL(clicked()), SLOT(sendUserSelectArt()));
24  connect(m_checkBox, SIGNAL(clicked()), SLOT(sendUserBoxClicked()));
25 }
26 
28 {
29  delete m_checkBox;
30 }
31 
32 void MusicLrcFloatPhotoItem::setPhoto(const QString &path)
33 {
34  m_pixPath = path;
35 
36  QPixmap pix;
37  if(!m_pixPath.isEmpty())
38  {
39  pix.load(m_pixPath);
40  pix = TTK::Image::roundedPixmap(pix, size(), 5, 5);
41  }
42  setPixmap(pix);
43 }
44 
46 {
47  m_checkBox->setChecked(checked);
48 }
49 
51 {
52  return m_checkBox->isChecked();
53 }
54 
56 {
57  m_checkBox->setVisible(v);
58 }
59 
61 {
62  Q_EMIT boxClicked(m_index);
63 }
64 
66 {
67  const QPixmap &pixmap = QtLablePixmap(this);
68  if(!pixmap.isNull())
69  {
70  Q_EMIT itemClicked(m_index);
71  }
72 }
73 
75 {
76  TTKClickedLabel::enterEvent(event);
77  const QPixmap &pixmap = QtLablePixmap(this);
78  if(!pixmap.isNull())
79  {
80  setCursor(Qt::PointingHandCursor);
81  }
82  else
83  {
84  unsetCursor();
85  }
86 }
87 
88 
89 
91  : MusicAbstractFloatWidget(parent),
92  m_currentIndex(0)
93 {
94  QVBoxLayout *layout = new QVBoxLayout(this);
95  layout->setContentsMargins(0, 0, 0, 0);
96  layout->setSpacing(0);
97  setLayout(layout);
98 
99  m_artistLabel = new QLabel(this);
100  m_artistLabel->setAlignment(Qt::AlignCenter);
102  layout->addWidget(m_artistLabel);
103 
104  QWidget *areaWidget = new QWidget(this);
105  areaWidget->setObjectName("AreaWidget");
106  areaWidget->setStyleSheet(QString("#AreaWidget{%1}").arg(TTK::UI::BackgroundStyle07));
107 
108  QHBoxLayout *areaLayout = new QHBoxLayout(areaWidget);
109  areaLayout->setContentsMargins(9, 18, 9, 9);
110  areaWidget->setLayout(areaLayout);
111  layout->addWidget(areaWidget);
112 
113  m_previous = new QPushButton(this);
114  m_previous->setCursor(QCursor(Qt::PointingHandCursor));
116  m_previous->setFixedSize(20, 52);
117  areaLayout->addWidget(m_previous);
118 
119  for(int i = 0; i < MIN_ITEM_COUNT; ++i)
120  {
121  MusicLrcFloatPhotoItem *item = new MusicLrcFloatPhotoItem(i, this);
122  areaLayout->addWidget(item);
123  m_planes << item;
124 
125  connect(item, SIGNAL(boxClicked(int)), SLOT(userSelectCheckBoxChecked(int)));
126  connect(item, SIGNAL(itemClicked(int)), SLOT(sendUserSelectArtBackground(int)));
127  }
128 
129  m_next = new QPushButton(this);
130  m_next->setCursor(QCursor(Qt::PointingHandCursor));
131  m_next->setStyleSheet(TTK::UI::InteriorFloatPhotoNext);
132  m_next->setFixedSize(20, 52);
133  areaLayout->addWidget(m_next);
134 
135  QWidget *functionWidget = new QWidget(this);
136  functionWidget->setObjectName("FunctionWidget");
137  functionWidget->setStyleSheet(QString("#FunctionWidget{%1}").arg(TTK::UI::BackgroundStyle07));
138 
139  QHBoxLayout *functionLayout = new QHBoxLayout(functionWidget);
140  functionLayout->setContentsMargins(18, 9, 18, 9);
141  functionLayout->setSpacing(15);
142  functionWidget->setLayout(functionLayout);
143  layout->addWidget(functionWidget);
144 
145  m_checkBox = new QCheckBox(tr("All"), functionWidget);
146  m_checkBox->setCursor(QCursor(Qt::PointingHandCursor));
147  m_checkBox->setStyleSheet(TTK::UI::CheckBoxStyle05);
148  m_checkBox->setFixedSize(50, 20);
149  m_checkBox->setChecked(true);
150  functionLayout->addWidget(m_checkBox);
151  functionLayout->addStretch(1);
152 
153  QPushButton *manageButton = new QPushButton(tr("Manage"), functionWidget);
154  manageButton->setCursor(QCursor(Qt::PointingHandCursor));
155  manageButton->setStyleSheet(TTK::UI::InteriorFloatSetting + TTK::UI::PushButtonStyle06);
156  manageButton->setFixedSize(55, 25);
157  functionLayout->addWidget(manageButton);
158 
159  QPushButton *confirmButton = new QPushButton(tr("OK"), functionWidget);
160  confirmButton->setCursor(QCursor(Qt::PointingHandCursor));
161  confirmButton->setStyleSheet(TTK::UI::InteriorFloatSetting + TTK::UI::PushButtonStyle06);
162  confirmButton->setFixedSize(55, 25);
163  functionLayout->addWidget(confirmButton);
164 
165  QPushButton *cancelButton = new QPushButton(tr("Cancel"), functionWidget);
166  cancelButton->setCursor(QCursor(Qt::PointingHandCursor));
167  cancelButton->setStyleSheet(TTK::UI::InteriorFloatSetting + TTK::UI::PushButtonStyle06);
168  cancelButton->setFixedSize(55, 25);
169  functionLayout->addWidget(cancelButton);
170 
171 #ifdef Q_OS_UNIX
172  m_previous->setFocusPolicy(Qt::NoFocus);
173  m_next->setFocusPolicy(Qt::NoFocus);
174  m_checkBox->setFocusPolicy(Qt::NoFocus);
175  manageButton->setFocusPolicy(Qt::NoFocus);
176  confirmButton->setFocusPolicy(Qt::NoFocus);
177  cancelButton->setFocusPolicy(Qt::NoFocus);
178 #endif
179 
180  connect(m_previous, SIGNAL(clicked()), SLOT(photoPrevious()));
181  connect(m_next, SIGNAL(clicked()), SLOT(photoNext()));
182  connect(m_checkBox, SIGNAL(clicked(bool)), SLOT(selectAllStateChanged(bool)));
183  connect(manageButton, SIGNAL(clicked()), SLOT(manageButtonClicked()));
184  connect(confirmButton, SIGNAL(clicked()), SLOT(confirmButtonClicked()));
185  connect(cancelButton, SIGNAL(clicked()), SLOT(close()));
186  connect(G_BACKGROUND_PTR, SIGNAL(artistChanged()), SLOT(artistNameChanged()));
187 }
188 
190 {
191  qDeleteAll(m_planes);
192  delete m_previous;
193  delete m_next;
194  delete m_checkBox;
195 }
196 
197 void MusicLrcFloatPhotoWidget::resizeGeometry(int width, int height)
198 {
199  m_rectEnter = QRect(0, 525 + height, 680 + width, 185);
200  m_rectLeave = QRect(0, 325 + height, 680 + width, 185);
201 
202  setGeometry(m_rectLeave);
203 }
204 
206 {
207  QWidget::show();
208  animationLeave();
209  showArtistPhoto();
210 }
211 
213 {
214  animationEnter();
215  TTK_SIGNLE_SHOT(m_animation->duration(), this, parentClose, TTK_SLOT);
216 }
217 
219 {
220  close();
221 
222  MusicLrcPhotoManagerWidget widget(this);
223  widget.exec();
224 }
225 
227 {
228  QStringList list;
229  for(int i : qAsConst(m_selectNum))
230  {
231  list << m_photos[i];
232  }
233 
234  G_BACKGROUND_PTR->setArtistPhotoList(list);
235  close();
236 }
237 
239 {
240  m_previous->setEnabled(m_currentIndex != 0);
241  int page = ceil(m_photos.count() * 1.0 / MIN_ITEM_COUNT) - 1;
242  if(page < 0)
243  {
244  page = 0;
245  }
246 
247  m_next->setEnabled(m_currentIndex != page);
248 
249  const int indexCheck = m_currentIndex * MIN_ITEM_COUNT;
250  for(int i = 0; i < m_planes.count(); ++i)
251  {
252  m_planes[i]->setPhoto((indexCheck + i) < m_photos.count() ? m_photos[indexCheck + i] : QString());
253  //check show radio button
254  m_planes[i]->setBoxChecked(m_selectNum.contains(indexCheck + i));
255  m_planes[i]->setBoxVisible((indexCheck + i) < m_photos.count());
256  }
257 }
258 
260 {
261  if(--m_currentIndex < 0)
262  {
263  m_currentIndex = 0;
264  }
265  showArtistPhoto();
266 }
267 
269 {
270  if(isVisible())
271  {
272  close();
273  }
274 
275  m_currentIndex = 0;
276  m_selectNum.clear();
277  m_checkBox->setChecked(true);
278  m_photos = G_BACKGROUND_PTR->artistPhotoList();
279 
280  for(int i = 0; i < m_photos.count(); ++i)
281  {
282  m_selectNum << i;
283  }
284 
285  const QString &name = G_BACKGROUND_PTR->artistName();
286  m_artistLabel->setText(name);
287  m_artistLabel->setFixedSize(TTK::Widget::fontTextWidth(m_artistLabel->font(), name) + 50, 35);
288 }
289 
291 {
292  int page = ceil(m_photos.count() * 1.0 / MIN_ITEM_COUNT) - 1;
293  if(page < 0)
294  {
295  page = 0;
296  }
297 
298  if(++m_currentIndex > page)
299  {
300  m_currentIndex = page;
301  }
302  showArtistPhoto();
303 }
304 
306 {
307  G_BACKGROUND_PTR->setSelectArtistIndex(m_currentIndex * MIN_ITEM_COUNT + index);
308 }
309 
311 {
312  bool status = true;
313  if(-1 < index && index < m_planes.count())
314  {
315  status = m_planes[index]->boxChecked();
316  }
317 
318  index = m_currentIndex * MIN_ITEM_COUNT + index;
319  if(status)
320  {
321  m_selectNum << index;
322  }
323  else
324  {
325  m_selectNum.remove(index);
326  }
327 
328  m_checkBox->setChecked(false);
329 }
330 
332 {
333  if(state)
334  {
335  for(int i = 0; i < m_photos.count(); ++i)
336  {
337  m_selectNum << i;
338  }
339  showArtistPhoto();
340  }
341  else
342  {
344  {
345  item->setBoxChecked(false);
346  }
347  m_selectNum.clear();
348  }
349 }
#define QtEnterEvent
Event enter.
Definition: ttkqtcompat.h:160
MusicLrcFloatPhotoItem(int index, QWidget *parent=nullptr)
The class of the lrc art photo upload.
#define G_BACKGROUND_PTR
static const QString CheckBoxStyle05
voidpf void uLong size
Definition: ioapi.h:136
static constexpr const char * InteriorFloatSetting
void resizeGeometry(int width, int height)
The class of the label widget that can click.
The class of the lrc photo float pixmap item.
TTK_MODULE_EXPORT QPixmap roundedPixmap(const QPixmap &input, int ratioX, int ratioY)
static constexpr const char * InteriorFloatPhotoItem
#define qAsConst
Definition: ttkqtglobal.h:53
The class of the float widget base.
const char * name
Definition: http_parser.c:458
static const QString PushButtonStyle06
void boxClicked(int index)
void itemClicked(int index)
QList< MusicLrcFloatPhotoItem * > m_planes
QPropertyAnimation * m_animation
#define TTK_SIGNLE_SHOT(...)
Definition: ttkqtglobal.h:177
MusicLrcFloatPhotoWidget(QWidget *parent=nullptr)
static constexpr const char * InteriorFloatPhotoNext
void setPhoto(const QString &path)
static constexpr const char * InteriorFloatPhotoPrevious
#define TTK_SLOT
Definition: ttkqtglobal.h:165
TTK_MODULE_EXPORT int fontTextWidth(const QFont &font, const QString &text)
static const QString BackgroundStyle07
Definition: musicuiobject.h:99
static const QString BorderStyle07
#define MIN_ITEM_COUNT
virtual void enterEvent(QtEnterEvent *event) overridefinal
static const QString BackgroundStyle06
Definition: musicuiobject.h:96
static const QString ColorStyle13
Definition: musicuiobject.h:73
state
Definition: http_parser.c:279
#define QtLablePixmap(p)
Lable pixmap.
Definition: ttkqtcompat.h:122