TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicfileinformationwidget.cpp
Go to the documentation of this file.
2 #include "ui_musicfileinformationwidget.h"
3 #include "musicnumberutils.h"
4 #include "musicsongmeta.h"
5 #include "musictoastlabel.h"
6 #include "musicfileutils.h"
7 #include "musicmessagebox.h"
8 #include "musicsong.h"
9 
11  : MusicAbstractMoveDialog(parent),
12  m_ui(new Ui::MusicFileInformationWidget),
13  m_deleteImage(false)
14 {
15  m_ui->setupUi(this);
16  setFixedSize(size());
17  setBackgroundLabel(m_ui->background);
18 
19  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
20  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
21  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
22  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
23  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
24 
25  setStyleSheet(TTK::UI::LineEditStyle01);
26  setEditLineEnabled(false);
27 
28  const QPixmap pix(":/image/lb_default_art");
29  m_ui->pixmapLabel->setPixmap(pix.scaled(m_ui->pixmapLabel->size()));
30  m_ui->mainViewWidget->setStyleSheet(TTK::UI::TabWidgetStyle01);
31  m_ui->descriptionPlainEdit->setReadOnly(true);
32  m_ui->descriptionPlainEdit->verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle03);
33 
34  m_ui->editButton->setStyleSheet(TTK::UI::PushButtonStyle04);
35  m_ui->deletePixButton->setStyleSheet(TTK::UI::PushButtonStyle04);
36  m_ui->savePixButton->setStyleSheet(TTK::UI::PushButtonStyle04);
37  m_ui->saveButton->setStyleSheet(TTK::UI::PushButtonStyle04);
38  m_ui->viewButton->setStyleSheet(TTK::UI::PushButtonStyle04);
39  m_ui->openPixButton->setStyleSheet(TTK::UI::PushButtonStyle04);
40 
41 #ifdef Q_OS_UNIX
42  m_ui->editButton->setFocusPolicy(Qt::NoFocus);
43  m_ui->deletePixButton->setFocusPolicy(Qt::NoFocus);
44  m_ui->savePixButton->setFocusPolicy(Qt::NoFocus);
45  m_ui->saveButton->setFocusPolicy(Qt::NoFocus);
46  m_ui->openPixButton->setFocusPolicy(Qt::NoFocus);
47  m_ui->viewButton->setFocusPolicy(Qt::NoFocus);
48 #endif
49 
50  connect(m_ui->editButton, SIGNAL(clicked()), SLOT(editTag()));
51  connect(m_ui->deletePixButton, SIGNAL(clicked()), SLOT(deleteAlbumImage()));
52  connect(m_ui->savePixButton, SIGNAL(clicked()), SLOT(saveAlbumImage()));
53  connect(m_ui->saveButton, SIGNAL(clicked()), SLOT(saveTag()));
54  connect(m_ui->viewButton, SIGNAL(clicked()), SLOT(openFileDir()));
55  connect(m_ui->openPixButton, SIGNAL(clicked()), SLOT(openImageFileDir()));
56 }
57 
59 {
60  delete m_ui;
61 }
62 
64 {
66  {
67  MusicToastLabel::popup(tr("The file has been moved or does not exist"));
68  }
69 }
70 
71 static void rendererPixmap(Ui::MusicFileInformationWidget *ui, const QPixmap &pixmap)
72 {
73  if(pixmap.isNull())
74  {
75  ui->pixmapWidthLabel->setText(TTK_DEFAULT_STR);
76  ui->pixmapHeightLabel->setText(TTK_DEFAULT_STR);
77  }
78  else
79  {
80  ui->pixmapWidthLabel->setText(QString("%1px").arg(pixmap.width()));
81  ui->pixmapHeightLabel->setText(QString("%1px").arg(pixmap.height()));
82  ui->pixmapLabel->setPixmap(pixmap.scaled(ui->pixmapLabel->size()));
83  }
84 }
85 
87 {
89  if(m_imagePath.isEmpty())
90  {
91  return;
92  }
93 
94  QPixmap pix;
95  pix.load(m_imagePath);
96  rendererPixmap(m_ui, pix);
97 }
98 
100 {
101  m_deleteImage = true;
102  rendererPixmap(m_ui, QPixmap(":/image/lb_default_art"));
103 }
104 
106 {
107  QPixmap pix;
108  MusicSongMeta meta;
109  if(meta.read(m_path))
110  {
111  pix = meta.cover();
112  }
113 
114  if(!pix.isNull())
115  {
116  const QString &path = TTK::File::getSaveFileName(this);
117  if(!path.isEmpty())
118  {
119  pix.save(path);
120  }
121  }
122 }
123 
125 {
126  setEditLineEnabled(!m_ui->fileAlbumEdit->isEnabled());
127 }
128 
130 {
131  MusicMessageBox message;
132  message.setText(tr("Are you sure to save?"));
133  if(!message.exec())
134  {
135  return;
136  }
137 
138  MusicSongMeta meta;
139  if(!meta.read(m_path))
140  {
141  return;
142  }
143 
144  QString value = m_ui->fileAlbumEdit->text().trimmed();
145  if(value != TTK_DEFAULT_STR)
146  {
147  meta.setAlbum(value);
148  }
149 
150  value = m_ui->fileArtistEdit->text().trimmed();
151  if(value != TTK_DEFAULT_STR)
152  {
153  meta.setArtist(value);
154  }
155 
156  value = m_ui->fileGenreEdit->text().trimmed();
157  if(value != TTK_DEFAULT_STR)
158  {
159  meta.setGenre(value);
160  }
161 
162  value = m_ui->fileTitleEdit->text().trimmed();
163  if(value != TTK_DEFAULT_STR)
164  {
165  meta.setTitle(value);
166  }
167 
168  value = m_ui->fileYearEdit->text().trimmed();
169  if(value != TTK_DEFAULT_STR)
170  {
171  meta.setYear(value);
172  }
173 
174  if(m_deleteImage)
175  {
176  meta.setCover(QPixmap());
177  }
178  else if(!m_imagePath.isEmpty())
179  {
180  meta.setCover(QPixmap(m_imagePath));
181  }
182 
183  meta.save();
184  MusicToastLabel::popup(tr("Save successfully"));
185 }
186 
188 {
189  if(name.contains(CACHE_DIR_FULL)) //cache song should not allow open url
190  {
191  m_ui->viewButton->setEnabled(false);
192  }
193 
194  MusicSongMeta meta;
195  const bool state = meta.read(m_path = name);
196  const QFileInfo fin(meta.fileRelatedPath());
197 
198  QString check;
199  m_ui->filePathEdit->setText((check = fin.filePath()).isEmpty() ? TTK_DEFAULT_STR : check);
200  m_ui->fileFormatEdit->setText((check = TTK_FILE_SUFFIX(fin)).isEmpty() ? TTK_DEFAULT_STR : check);
201  m_ui->fileSizeEdit->setText((check = TTK::Number::sizeByteToLabel(fin.size())).isEmpty() ? TTK_DEFAULT_STR : check);
202 
203  m_ui->fileAlbumEdit->setText(state ? ((check = meta.album()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
204  m_ui->fileArtistEdit->setText(state ? ((check = meta.artist()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
205  m_ui->fileGenreEdit->setText(state ? ((check = meta.genre()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
206  m_ui->fileTitleEdit->setText(state ? ((check = meta.title()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
207  m_ui->fileYearEdit->setText(state ? ((check = meta.year()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
208  m_ui->fileTimeEdit->setText(state ? ((check = meta.duration()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
209 
210  const int rating = meta.rating().toInt();
211  if(rating == 0) m_ui->ratingLabel->setValue(0);
212  else if(rating < 64) m_ui->ratingLabel->setValue(1);
213  else if(rating < 128) m_ui->ratingLabel->setValue(2);
214  else if(rating < 196) m_ui->ratingLabel->setValue(3);
215  else if(rating < 255) m_ui->ratingLabel->setValue(4);
216  else m_ui->ratingLabel->setValue(5);
217 
218  m_ui->bitrateEdit->setText(state ? ((check = (meta.bitrate())).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
219  m_ui->channelEdit->setText(state ? ((check = meta.channel()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
220  m_ui->sampleRateEdit->setText(state ? ((check = meta.sampleRate()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
221  m_ui->trackNumEdit->setText(state ? ((check = meta.trackNum()).isEmpty() ? TTK_DEFAULT_STR : check) : TTK_DEFAULT_STR);
222 
223  QColor color;
224  QString bitrate;
225  TTK::Number::bitrateToQuality(TTK::Number::bitrateToLevel(m_ui->bitrateEdit->text()), bitrate, color);
226  m_ui->qualityEdit->setText(bitrate);
227 
228  m_ui->descriptionPlainEdit->setPlainText(meta.description());
229 
230  rendererPixmap(m_ui, meta.cover());
231 }
232 
234 {
235  m_ui->fileAlbumEdit->setEnabled(enabled);
236  m_ui->fileArtistEdit->setEnabled(enabled);
237  m_ui->fileGenreEdit->setEnabled(enabled);
238  m_ui->fileTitleEdit->setEnabled(enabled);
239  m_ui->fileYearEdit->setEnabled(enabled);
240 
241  m_ui->openPixButton->setEnabled(enabled);
242  m_ui->deletePixButton->setEnabled(enabled);
243  m_ui->saveButton->setEnabled(enabled);
244 }
void setBackgroundLabel(QLabel *label)
MusicFileInformationWidget(QWidget *parent=nullptr)
bool read(const QString &url)
QString genre() noexcept
QString sampleRate() noexcept
QString title() noexcept
#define CACHE_DIR_FULL
Definition: musicobject.h:130
void setGenre(const QString &genre) noexcept
void setText(const QString &text) const
QString artist() noexcept
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
TTK_MODULE_EXPORT QString trackRelatedPath(const QString &path)
Definition: musicsong.cpp:100
static void rendererPixmap(Ui::MusicFileInformationWidget *ui, const QPixmap &pixmap)
voidpf void uLong size
Definition: ioapi.h:136
TTK_MODULE_EXPORT QString getOpenFileName(QWidget *parent, const QString &filter="Image Files (*.png *.bmp *.jpg)")
The class of the messagebox widget.
void initialize(const QString &name)
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
QString bitrate() noexcept
static void popup(const QString &text)
void setYear(const QString &year) noexcept
TTK_MODULE_EXPORT QString getSaveFileName(QWidget *parent, const QString &filter="Image Files (*.png *.bmp *.jpg)")
static const QString ScrollBarStyle03
void setTitle(const QString &title) noexcept
Ui::MusicFileInformationWidget * m_ui
const char * name
Definition: http_parser.c:458
QString album() noexcept
TTK_MODULE_EXPORT TTK::QueryQuality bitrateToLevel(int bitrate)
The class of the file information widget.
QString description() noexcept
static const QString PushButtonStyle04
TTK_MODULE_EXPORT bool openUrl(const QString &path, bool local=true)
The class of the moving dialog base.
QPixmap cover() noexcept
QString duration() noexcept
static const QString LineEditStyle01
LineEdit.
QString trackNum() noexcept
static const QString TabWidgetStyle01
TabWidget.
static const QString ToolButtonStyle04
#define TTK_FILE_SUFFIX(fin)
Definition: ttkqtglobal.h:173
The class of the music song meta.
Definition: musicsongmeta.h:30
QString channel() noexcept
void setAlbum(const QString &album) noexcept
QString fileRelatedPath() noexcept
QString year() noexcept
void setArtist(const QString &artist) noexcept
QString rating() noexcept
void setCover(const QPixmap &cover) noexcept
state
Definition: http_parser.c:279
TTK_MODULE_EXPORT void bitrateToQuality(TTK::QueryQuality level, QString &bitrate, QColor &color)