TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musiclrcphotomanagerwidget.cpp
Go to the documentation of this file.
2 #include "ui_musiclrcphotomanagerwidget.h"
4 #include "musictoastlabel.h"
5 #include "musicfileutils.h"
6 #include "ttktime.h"
7 
9  : QLabel(parent),
10  m_isSelected(false)
11 {
12  setFixedSize(137, 100);
13  setCursor(Qt::PointingHandCursor);
14 }
15 
16 void MusicLrcPhotoItem::updatePixmap(const QString &path)
17 {
18  m_path = path;
19  setPixmap(QPixmap(path).scaled(size()));
20 }
21 
23 {
24  m_isSelected = v;
25 }
26 
27 void MusicLrcPhotoItem::mousePressEvent(QMouseEvent *event)
28 {
29  Q_UNUSED(event);
31  update();
32 }
33 
34 void MusicLrcPhotoItem::paintEvent(QPaintEvent *event)
35 {
36  QLabel::paintEvent(event);
37  if(m_isSelected)
38  {
39  QPainter painter(this);
40  painter.fillRect(rect(), QColor(0, 0, 0, 155));
41  painter.drawPixmap(width() - 16 - 4, height() - 16 - 4, 16, 16, QPixmap(":/lrc/lb_photo_checked"));
42  }
43 }
44 
45 
47  : QWidget(parent)
48 {
49  m_gridLayout = new QGridLayout(this);
50  m_gridLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
51  m_gridLayout->setContentsMargins(7, 0, 7, 0);
52  setLayout(m_gridLayout);
53 
54  initialize();
55 }
56 
58 {
59  qDeleteAll(m_items);
60  delete m_gridLayout;
61 }
62 
63 void MusicLrcPhotoWidget::addCellItem(const QString &path)
64 {
65  MusicLrcPhotoItem *item = new MusicLrcPhotoItem(this);
66  item->updatePixmap(path);
67 
68  m_gridLayout->addWidget(item, m_items.count() / MIN_ITEM_COUNT, m_items.count() % MIN_ITEM_COUNT, Qt::AlignLeft | Qt::AlignTop);
69  m_items << item;
70 }
71 
73 {
74  if(m_items.count() >= MAX_IMAGE_COUNT)
75  {
76  MusicToastLabel::popup(tr("Exceeded the maximum number limit"));
77  return;
78  }
79 
80  const QStringList &files = TTK::File::getOpenFileNames(this);
81  if(files.isEmpty())
82  {
83  return;
84  }
85 
86  int offset = MAX_IMAGE_COUNT - m_items.count();
87  if(files.count() < offset)
88  {
89  offset = files.count();
90  }
91 
92  for(int i = 0; i < offset; ++i)
93  {
94  const QString &name = G_BACKGROUND_PTR->artistName();
95  const QString &path = BACKGROUND_DIR_FULL + name + QString::number(m_items.count()) + SKN_FILE;
96  QFile::copy(files[i], path);
97 
98  addCellItem(path);
99  }
100 
101  G_BACKGROUND_PTR->updateArtistPhotoList();
102 }
103 
105 {
106  if(!isValid())
107  {
108  MusicToastLabel::popup(tr("Please select one item first"));
109  return;
110  }
111 
112  for(int i = 0; i < m_items.count(); ++i)
113  {
114  MusicLrcPhotoItem *item = m_items[i];
115  if(item->isSelected())
116  {
117  QFile::remove(item->path());
118  m_gridLayout->removeWidget(item);
119  m_items.takeAt(i--)->deleteLater();
120  }
121  }
122 
123  for(int i = 0; i < m_items.count(); ++i)
124  {
125  MusicLrcPhotoItem *item = m_items[i];
126  const QString &before = item->path();
127  const QString &after = item->pathRef().replace(before.length() - 4 - 1, 1, QString::number(i));
128  QFile::rename(before, after);
129  m_gridLayout->addWidget(item, i / MIN_ITEM_COUNT, i % MIN_ITEM_COUNT, Qt::AlignLeft | Qt::AlignTop);
130  }
131 
132  G_BACKGROUND_PTR->updateArtistPhotoList();
133  MusicToastLabel::popup(tr("Delete current file success"));
134 }
135 
137 {
138  if(!isValid())
139  {
140  MusicToastLabel::popup(tr("Please select one item first"));
141  return;
142  }
143 
144  const QString &path = TTK::File::getExistingDirectory(this);
145  if(path.isEmpty())
146  {
147  return;
148  }
149 
150  const QString &dir = path + "/images/";
151  QDir().mkpath(dir);
152 
153  for(MusicLrcPhotoItem *item : qAsConst(m_items))
154  {
155  if(item->isSelected())
156  {
157  QFile::copy(item->path(), dir + QString::number(TTKDateTime::currentTimestamp()) + JPG_FILE);
159  }
160  }
161 
162  MusicToastLabel::popup(tr("Export current file success"));
163 }
164 
166 {
167  const QDir dir(BACKGROUND_DIR_FULL);
168  const QString &name = G_BACKGROUND_PTR->artistName();
169 
170  for(const QFileInfo &fin : dir.entryInfoList())
171  {
172  const QString &v = fin.fileName();
173  if(v.length() > name.length() && v.startsWith(name) && v[name.length() + 1] == '.')
174  {
175  addCellItem(dir.filePath(v));
176  }
177  }
178 }
179 
181 {
182  for(MusicLrcPhotoItem *item : qAsConst(m_items))
183  {
184  if(item->isSelected())
185  {
186  return true;
187  }
188  }
189  return false;
190 }
191 
192 
194  : MusicAbstractMoveDialog(parent),
195  m_ui(new Ui::MusicLrcPhotoManagerWidget)
196 {
197  m_ui->setupUi(this);
198  setFixedSize(size());
199  setBackgroundLabel(m_ui->background);
200 
201  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
202  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
203  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
204  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
205  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
206 
207  m_ui->addButton->setStyleSheet(TTK::UI::PushButtonStyle04);
208  m_ui->deleteButton->setStyleSheet(TTK::UI::PushButtonStyle04);
209  m_ui->exportButton->setStyleSheet(TTK::UI::PushButtonStyle04);
210  m_ui->okButton->setStyleSheet(TTK::UI::PushButtonStyle04);
211 #ifdef Q_OS_UNIX
212  m_ui->addButton->setFocusPolicy(Qt::NoFocus);
213  m_ui->deleteButton->setFocusPolicy(Qt::NoFocus);
214  m_ui->exportButton->setFocusPolicy(Qt::NoFocus);
215  m_ui->okButton->setFocusPolicy(Qt::NoFocus);
216 #endif
217  m_ui->artTextLabel->setText(G_BACKGROUND_PTR->artistName());
218  m_ui->artTextLabel->setStyleSheet(TTK::UI::ColorStyle07);
219 
222 
223  connect(m_ui->addButton, SIGNAL(clicked()), m_photoWidget, SLOT(addButtonClicked()));
224  connect(m_ui->deleteButton, SIGNAL(clicked()), m_photoWidget, SLOT(deleteButtonClicked()));
225  connect(m_ui->exportButton, SIGNAL(clicked()), m_photoWidget, SLOT(exportButtonClicked()));
226  connect(m_ui->okButton, SIGNAL(clicked()), SLOT(close()));
227 }
228 
230 {
231  delete m_ui;
232  delete m_photoWidget;
233 }
TTK_MODULE_EXPORT QString getExistingDirectory(QWidget *parent)
void setBackgroundLabel(QLabel *label)
The class of the lrc photo widget.
The class of the lrc art photo upload.
#define G_BACKGROUND_PTR
void addCellItem(const QString &path)
voidpf void uLong size
Definition: ioapi.h:136
The class of the lrc photo pixmap item.
void updatePixmap(const QString &path)
virtual void paintEvent(QPaintEvent *event) overridefinal
static void popup(const QString &text)
voidpf uLong offset
Definition: ioapi.h:142
QList< MusicLrcPhotoItem * > m_items
#define qAsConst
Definition: ttkqtglobal.h:53
const char * name
Definition: http_parser.c:458
#define MAX_IMAGE_COUNT
TTK_MODULE_EXPORT void sleep(int ms)
static const QString PushButtonStyle04
MusicLrcPhotoItem(QWidget *parent=nullptr)
#define BACKGROUND_DIR_FULL
Definition: musicobject.h:129
The class of the moving dialog base.
static const QString ColorStyle07
Definition: musicuiobject.h:55
static qint64 currentTimestamp()
Definition: ttktime.cpp:249
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
Ui::MusicLrcPhotoManagerWidget * m_ui
MusicLrcPhotoWidget(QWidget *parent=nullptr)
#define MIN_ITEM_COUNT
virtual void mousePressEvent(QMouseEvent *event) overridefinal
static const QString ToolButtonStyle04
TTK_MODULE_EXPORT QStringList getOpenFileNames(QWidget *parent, const QString &filter="Image Files (*.png *.bmp *.jpg)")
MusicLrcPhotoManagerWidget(QWidget *parent=nullptr)
#define SKN_FILE
Definition: musicobject.h:61
#define JPG_FILE
Definition: musicobject.h:62
#define TTK_DN_MS
Definition: ttkglobal.h:270