TTKMusicPlayer  3.7.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 
5  : QWidget(parent),
6  m_networkRequest(nullptr)
7 {
8  m_songName = new QLabel(this);
9  m_singer = new QLabel(this);
10  m_information = new QLabel(this);
11  m_information->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
12  m_status = new QLabel(this);
13  m_status->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
14 
15  m_qulity = new QComboBox(this);
17 
18  m_songName->setGeometry(0, 0, 190, TTK_ITEM_SIZE_S);
19  m_singer->setGeometry(180, 0, 120, TTK_ITEM_SIZE_S);
20  m_qulity->setGeometry(300, 0, 80, TTK_ITEM_SIZE_S);
21  m_information->setGeometry(380, 0, 150, TTK_ITEM_SIZE_S);
22  m_status->setGeometry(530, 0, TTK_ITEM_SIZE_S, TTK_ITEM_SIZE_S);
24 
25  connect(m_qulity, SIGNAL(currentIndexChanged(int)), SLOT(currentQualityChanged(int)));
26 }
27 
29 {
30  delete m_songName;
31  delete m_singer;
32  delete m_information;
33  delete m_status;
34  delete m_qulity;
35 }
36 
38 {
39  m_songName->setToolTip(info.m_songName);
40  m_songName->setText(TTK::Widget::elidedText(m_songName->font(), m_songName->toolTip(), Qt::ElideRight, m_songName->width() - 10));
41 
42  m_singer->setToolTip(info.m_artistName);
43  m_singer->setText(TTK::Widget::elidedText(m_singer->font(), m_singer->toolTip(), Qt::ElideRight, m_singer->width() - 10));
44 
45  m_songInfo = info;
46  m_networkRequest = request;
47  m_queryType = request->queryType();
48 
49  m_qulity->addItems({QObject::tr("SD"), QObject::tr("HQ"), QObject::tr("SQ"), QObject::tr("CD")});
50  m_qulity->setCurrentIndex(0);
51 }
52 
54 {
55  if(!G_NETWORK_PTR->isOnline() || m_qulity->currentIndex() < 0)
56  {
57  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
58  return;
59  }
60 
61  m_status->setPixmap(QPixmap(":/tiny/lb_question"));
63  {
65  }
67  {
69  }
70 }
71 
73 {
74  m_qulity->setCurrentIndex(index);
75 }
76 
78 {
79  const int bitrate = currentBitrate(index);
81  {
82  const QString &size = TTK::Number::sizeByteToLabel(m_songInfo.m_duration, bitrate);
83  m_information->setText(QString("%1/%2KBPS/%3").arg(size).arg(bitrate).arg(QString(bitrate > TTK_BN_320 ? FLAC_FILE_SUFFIX : MP3_FILE_SUFFIX).toUpper()));
84  }
86  {
87  const QString &size = TTK::Number::sizeByteToLabel(m_songInfo.m_duration, bitrate);
88  m_information->setText(QString("%1/%2KBPS/%3").arg(size).arg(bitrate).arg(QString(MP4_FILE_SUFFIX).toUpper()));
89  }
90 
91  m_status->setPixmap(QPixmap(":/tiny/lb_question"));
92 }
93 
95 {
96  m_status->setPixmap(QPixmap(":/tiny/lb_right"));
97 }
98 
100 {
101  int bitrate = -1;
103  {
104  switch(index)
105  {
106  case 0: bitrate = TTK_BN_128; break;
107  case 1: bitrate = TTK_BN_192; break;
108  case 2: bitrate = TTK_BN_320; break;
109  case 3: bitrate = TTK_BN_1000; break;
110  default: break;
111  }
112  }
114  {
115  switch(index)
116  {
117  case 0: bitrate = TTK_BN_250; break;
118  case 1: bitrate = TTK_BN_500; break;
119  case 2: bitrate = TTK_BN_750; break;
120  case 3: bitrate = TTK_BN_1000; break;
121  default: break;
122  }
123  }
124  return bitrate;
125 }
126 
128 {
129  const int bitrate = currentBitrate(m_qulity->currentIndex());
131 
133  {
134  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
135  }
136 }
137 
139 {
140  const int bitrate = currentBitrate(m_qulity->currentIndex());
142 
144  {
145  m_status->setPixmap(QPixmap(":/tiny/lb_error"));
146  }
147 }
148 
149 
150 
152  : MusicAbstractTableWidget(parent)
153 {
154  setColumnCount(1);
155 
156  QHeaderView *headerView = horizontalHeader();
157  headerView->resizeSection(0, 555);
158 
159  setStyleSheet(styleSheet() + TTK::UI::TableWidgetStyle02);
160  verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle01);
161 
162  TTK::Widget::setTransparent(this, 255);
163 #if defined Q_OS_UNIX && !TTK_QT_VERSION_CHECK(5,7,0) //Fix linux selection-background-color stylesheet bug
164  TTK::Widget::setTransparent(this, QColor(220, 220, 220));
165 #endif
166 }
167 
169 {
170  removeItems();
171 }
172 
174 {
175  const int index = rowCount();
176  setRowCount(index + 1);
177  setRowHeight(index, TTK_ITEM_SIZE_S);
178 
179  QTableWidgetItem *it = new QTableWidgetItem;
180  setItem(index, 0, it);
181 
183  item->addCellItem(request, info);
184  setCellWidget(index, 0, item);
185  m_items << item;
186 }
187 
189 {
190  qDeleteAll(m_items);
191  m_items.clear();
192 
194  setColumnCount(1);
195 }
196 
198 {
200  {
201  item->setCurrentQuality(index);
202  }
203 }
204 
206 {
208  {
209  item->startToRequest();
210  }
211 }
212 
213 
214 
216  : MusicAbstractMoveDialog(parent),
217  m_ui(new Ui::MusicDownloadBatchWidget)
218 {
219  m_ui->setupUi(this);
220  setFixedSize(size());
221  setBackgroundLabel(m_ui->background);
222 
223  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
224  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
225  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
226  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
227  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
228 
230  m_ui->qualityBox->addItems({QObject::tr("SD"), QObject::tr("HQ"), QObject::tr("SQ"), QObject::tr("CD")});
231  connect(m_ui->qualityBox, SIGNAL(currentIndexChanged(int)), m_ui->tableWidget, SLOT(currentQualityChanged(int)));
232 
233  m_ui->qualityBox->setCurrentIndex(0);
234 
235  m_ui->downloadButton->setStyleSheet(TTK::UI::PushButtonStyle05);
236 #ifdef Q_OS_UNIX
237  m_ui->downloadButton->setFocusPolicy(Qt::NoFocus);
238 #endif
239 
240  connect(m_ui->downloadButton, SIGNAL(clicked()), m_ui->tableWidget, SLOT(startToRequest()));
241 }
242 
244 {
245  delete m_ui;
246 }
247 
249 {
250  TTK::MusicSongInformationList infos, songInfos(request->items());
251  for(int index : qAsConst(items))
252  {
253  if(index < 0 || index >= songInfos.count())
254  {
255  continue;
256  }
257 
258  infos << songInfos[index];
259  }
260 
261  for(const TTK::MusicSongInformation &info : qAsConst(infos))
262  {
263  m_ui->tableWidget->addCellItem(request, info);
264  }
265  m_ui->songCountLabel->setText(tr("All Songs Count %1").arg(infos.count()));
266 }
The class of the download batch widget.
void setBackgroundLabel(QLabel *label)
static bool startToRequestMovie(const TTK::MusicSongInformation &info, int bitrate, QObject *parent)
Ui::MusicDownloadBatchWidget * m_ui
The class of the table widget base.
voidpf void uLong size
Definition: ioapi.h:136
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:241
static const QString ItemView01
ItemView.
TTK_MODULE_EXPORT QString sizeByteToLabel(qint64 size)
#define TTK_BN_1000
Definition: ttkglobal.h:354
#define TTK_BN_250
Definition: ttkglobal.h:350
#define MP3_FILE_SUFFIX
Definition: musicobject.h:50
#define TTK_BN_500
Definition: ttkglobal.h:352
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
#define MP4_FILE_SUFFIX
Definition: musicobject.h:53
#define qAsConst
Definition: ttkqtglobal.h:53
static const QString ScrollBarStyle01
ScrollBar.
MusicDownloadBatchWidget(QWidget *parent=nullptr)
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:351
MusicAbstractQueryRequest * m_networkRequest
The class of the moving dialog base.
MusicDownloadBatchTableItem(QWidget *parent=nullptr)
QList< MusicDownloadBatchTableItem * > m_items
TTK_MODULE_EXPORT void generateComboBoxFormat(QComboBox *widget, const QString &style={})
#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 download data from net.
#define TTK_BN_192
Definition: ttkglobal.h:349
TTK::MusicSongInformation m_songInfo
const TTK::MusicSongInformationList & items() const
#define FLAC_FILE_SUFFIX
Definition: musicobject.h:52
The class of the music song information.
Definition: musicobject.h:281
#define TTK_BN_750
Definition: ttkglobal.h:353
#define TTK_BN_128
Definition: ttkglobal.h:348
static const QString ComboBoxStyle02