TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicdownloadbatchwidget.cpp
Go to the documentation of this file.
2 #include "ui_musicdownloadbatchwidget.h"
3 #include "musicmessagebox.h"
4 #include "musictoastlabel.h"
5 
7  : QWidget(parent),
8  m_networkRequest(nullptr)
9 {
10  m_songName = new QLabel(this);
11  m_singer = new QLabel(this);
12  m_information = new QLabel(this);
13  m_information->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
14  m_status = new QLabel(this);
15  m_status->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
16 
17  m_qulity = new QComboBox(this);
19 
20  m_songName->setGeometry(0, 0, 190, TTK_ITEM_SIZE_S);
21  m_singer->setGeometry(180, 0, 120, TTK_ITEM_SIZE_S);
22  m_qulity->setGeometry(300, 0, 80, TTK_ITEM_SIZE_S);
23  m_information->setGeometry(380, 0, 150, TTK_ITEM_SIZE_S);
24  m_status->setGeometry(530, 0, TTK_ITEM_SIZE_S, TTK_ITEM_SIZE_S);
26 
27  connect(m_qulity, SIGNAL(currentIndexChanged(int)), SLOT(currentQualityChanged(int)));
28 }
29 
31 {
32  delete m_songName;
33  delete m_singer;
34  delete m_information;
35  delete m_status;
36  delete m_qulity;
37 }
38 
40 {
41  m_songName->setToolTip(info.m_songName);
42  m_songName->setText(TTK::Widget::elidedText(m_songName->font(), m_songName->toolTip(), Qt::ElideRight, m_songName->width() - 10));
43 
44  m_singer->setToolTip(info.m_artistName);
45  m_singer->setText(TTK::Widget::elidedText(m_singer->font(), m_singer->toolTip(), Qt::ElideRight, m_singer->width() - 10));
46 
47  m_info = info;
48  m_networkRequest = request;
49  m_queryType = request->queryType();
50 
51  m_qulity->addItems({QObject::tr("SD"), QObject::tr("HQ"), QObject::tr("SQ"), QObject::tr("CD")});
52  m_qulity->setCurrentIndex(0);
53 }
54 
56 {
57  if(!G_NETWORK_PTR->isOnline() || m_qulity->currentIndex() < 0)
58  {
59  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
60  return;
61  }
62 
63  m_status->setPixmap(QPixmap(":/tiny/lb_question"));
65  {
67  }
69  {
71  }
72 }
73 
75 {
76  m_qulity->setCurrentIndex(index);
77 }
78 
80 {
81  const int bitrate = currentBitrate(index);
83  {
84  const QString &size = TTK::Number::sizeByteToLabel(m_info.m_duration, bitrate);
85  m_information->setText(QString("%1/%2KBPS/%3").arg(size).arg(bitrate).arg(QString(bitrate > TTK_BN_320 ? FLAC_FILE_SUFFIX : MP3_FILE_SUFFIX).toUpper()));
86  }
88  {
89  const QString &size = TTK::Number::sizeByteToLabel(m_info.m_duration, bitrate);
90  m_information->setText(QString("%1/%2KBPS/%3").arg(size).arg(bitrate).arg(QString(MP4_FILE_SUFFIX).toUpper()));
91  }
92 
93  m_status->setPixmap(QPixmap(":/tiny/lb_question"));
94 }
95 
97 {
98  m_status->setPixmap(QPixmap(":/tiny/lb_right"));
99 }
100 
102 {
103  int bitrate = -1;
105  {
106  switch(index)
107  {
108  case 0: bitrate = TTK_BN_128; break;
109  case 1: bitrate = TTK_BN_192; break;
110  case 2: bitrate = TTK_BN_320; break;
111  case 3: bitrate = TTK_BN_1000; break;
112  default: break;
113  }
114  }
116  {
117  switch(index)
118  {
119  case 0: bitrate = TTK_BN_250; break;
120  case 1: bitrate = TTK_BN_500; break;
121  case 2: bitrate = TTK_BN_750; break;
122  case 3: bitrate = TTK_BN_1000; break;
123  default: break;
124  }
125  }
126  return bitrate;
127 }
128 
130 {
131  const int bitrate = currentBitrate(m_qulity->currentIndex());
133 
135  {
136  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
137  }
138 }
139 
141 {
142  const int bitrate = currentBitrate(m_qulity->currentIndex());
144 
146  {
147  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
148  }
149 }
150 
151 
152 
154  : MusicAbstractTableWidget(parent),
155  m_index(-1)
156 {
157  setColumnCount(1);
158 
159  QHeaderView *headerView = horizontalHeader();
160  headerView->resizeSection(0, 555);
161 
162  setStyleSheet(styleSheet() + TTK::UI::TableWidgetStyle02);
163  verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle01);
164 
165  TTK::Widget::setTransparent(this, 255);
166 #if defined Q_OS_UNIX && !TTK_QT_VERSION_CHECK(5,7,0) //Fix linux selection-background-color stylesheet bug
167  TTK::Widget::setTransparent(this, QColor(220, 220, 220));
168 #endif
169 
170  TTK::initRandom();
171 
172  m_timer = new QTimer(this);
173  connect(m_timer, SIGNAL(timeout()), SLOT(timeout()));
174 }
175 
177 {
178  m_timer->stop();
179  delete m_timer;
180  removeItems();
181 }
182 
184 {
185  const int index = rowCount();
186  setRowCount(index + 1);
187  setRowHeight(index, TTK_ITEM_SIZE_S);
188 
189  QTableWidgetItem *it = new QTableWidgetItem;
190  setItem(index, 0, it);
191 
193  item->addCellItem(request, info);
194  setCellWidget(index, 0, item);
195  m_items << item;
196 }
197 
199 {
200  qDeleteAll(m_items);
201  m_items.clear();
202 
204  setColumnCount(1);
205 }
206 
208 {
210  {
211  item->setCurrentQuality(index);
212  }
213 }
214 
216 {
217  if(m_timer->isActive() || m_items.isEmpty())
218  {
219  return;
220  }
221 
222  m_index = 0;
223  generateTimer();
224  MusicToastLabel::popup(tr("Downloading now"));
225 }
226 
228 {
229  if(m_index >= m_items.count())
230  {
231  m_index = -1;
232  m_timer->stop();
233  MusicToastLabel::popup(tr("All download finished"));
234  return;
235  }
236 
237  generateTimer();
238  m_items[m_index++]->startToRequest();
239 }
240 
242 {
243  m_timer->start((5 + TTK::random(5)) * TTK_DN_S2MS); // (5-10)s
244 }
245 
246 
247 
249  : MusicAbstractMoveDialog(parent),
250  m_ui(new Ui::MusicDownloadBatchWidget)
251 {
252  m_ui->setupUi(this);
253  setFixedSize(size());
254  setBackgroundLabel(m_ui->background);
255 
256  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
257  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
258  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
259  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
260  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
261 
263  m_ui->qualityBox->addItems({QObject::tr("SD"), QObject::tr("HQ"), QObject::tr("SQ"), QObject::tr("CD")});
264  connect(m_ui->qualityBox, SIGNAL(currentIndexChanged(int)), m_ui->tableWidget, SLOT(currentQualityChanged(int)));
265 
266  m_ui->qualityBox->setCurrentIndex(0);
267 
268  m_ui->downloadButton->setStyleSheet(TTK::UI::PushButtonStyle05);
269 #ifdef Q_OS_UNIX
270  m_ui->downloadButton->setFocusPolicy(Qt::NoFocus);
271 #endif
272  connect(m_ui->downloadButton, SIGNAL(clicked()), m_ui->tableWidget, SLOT(startToRequest()));
273  connect(m_ui->downloadButton, SIGNAL(clicked(bool)), m_ui->downloadButton, SLOT(setEnabled(bool)));
274 }
275 
277 {
278  delete m_ui;
279 }
280 
282 {
283  TTK::MusicSongInformationList infos, songInfos(request->items());
284  for(int index : qAsConst(items))
285  {
286  if(index < 0 || index >= songInfos.count())
287  {
288  continue;
289  }
290 
291  infos << songInfos[index];
292  }
293 
294  for(const TTK::MusicSongInformation &info : qAsConst(infos))
295  {
296  m_ui->tableWidget->addCellItem(request, info);
297  }
298 
299  m_ui->songCountLabel->setText(tr("All Songs Count %1").arg(infos.count()));
300 }
301 
303 {
304  if(m_ui->tableWidget->isRunning())
305  {
307  message.setText(tr("Downloading now, are you sure to close?"));
308  if(!message.exec())
309  {
310  return;
311  }
312  }
313 
314  MusicAbstractMoveDialog::close();
315 }
const TTK::MusicSongInformationList & items() const noexcept
The class of the download batch widget.
static bool startToRequestMovie(const TTK::MusicSongInformation &info, int bitrate, QObject *parent)
static QString message(const TTK::Attribute attr)
void setText(const QString &text) const
TTK_MODULE_EXPORT void generateComboBoxStyle(QComboBox *widget, const QString &style={})
Ui::MusicDownloadBatchWidget * m_ui
The class of the table widget base.
voidpf void uLong size
Definition: ioapi.h:136
TTK_MODULE_EXPORT void initRandom()
Definition: ttktime.cpp:7
static bool startToRequestMusic(const TTK::MusicSongInformation &info, int bitrate, QObject *parent)
void addCellItem(MusicAbstractQueryRequest *request, const TTK::MusicSongInformation &info)
virtual void removeItems() overridefinal
#define TTK_ITEM_SIZE_S
Definition: ttkglobal.h:320
The class of the messagebox widget.
static const QString ItemView01
ItemView.
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
#define TTK_BN_1000
Definition: ttkglobal.h:434
void setBackgroundLabel(QLabel *label) noexcept
#define TTK_BN_250
Definition: ttkglobal.h:430
#define MP3_FILE_SUFFIX
Definition: musicobject.h:58
static void popup(const QString &text)
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
Definition: ttktime.cpp:14
#define TTK_BN_500
Definition: ttkglobal.h:432
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
#define MP4_FILE_SUFFIX
Definition: musicobject.h:61
#define qAsConst
Definition: ttkqtglobal.h:57
static const QString ScrollBarStyle01
ScrollBar.
MusicDownloadBatchWidget(QWidget *parent=nullptr)
TTK::MusicSongInformation m_info
The class of the download batch table item.
TTK_MODULE_EXPORT void setTransparent(QWidget *widget, int alpha)
void addCellItem(MusicAbstractQueryRequest *request, const TTK::MusicSongInformation &info)
static const QString TableWidgetStyle02
void initialize(MusicAbstractQueryRequest *request, const TTKIntList &items)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
#define TTK_BN_320
Definition: ttkglobal.h:431
MusicAbstractQueryRequest * m_networkRequest
The class of the moving dialog base.
MusicDownloadBatchTableItem(QWidget *parent=nullptr)
QList< MusicDownloadBatchTableItem * > m_items
#define TTK_DN_S2MS
Definition: ttkglobal.h:355
#define G_NETWORK_PTR
static const QString PushButtonStyle05
static const QString ToolButtonStyle04
MusicDownloadBatchTableWidget(QWidget *parent=nullptr)
MusicAbstractQueryRequest::QueryType m_queryType
The class of the abstract query data from net.
QueryType queryType() const noexcept
#define TTK_BN_192
Definition: ttkglobal.h:429
#define FLAC_FILE_SUFFIX
Definition: musicobject.h:60
The class of the music song information.
Definition: musicobject.h:300
#define TTK_BN_750
Definition: ttkglobal.h:433
#define TTK_BN_128
Definition: ttkglobal.h:428
static const QString ComboBoxStyle02