TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicitemquerytablewidget.cpp
Go to the documentation of this file.
4 #include "musictoastlabel.h"
5 #include "musicrightareawidget.h"
6 
8  : MusicQueryTableWidget(parent)
9 {
10  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
11  setColumnCount(8);
12 
13  QHeaderView *headerView = horizontalHeader();
14  headerView->resizeSection(0, 30);
15  headerView->resizeSection(1, 342);
16  headerView->resizeSection(2, 110);
17  headerView->resizeSection(3, 47);
18  headerView->resizeSection(4, 26);
19  headerView->resizeSection(5, 26);
20  headerView->resizeSection(6, 26);
21  headerView->resizeSection(7, 26);
22 }
23 
25 {
26  removeItems();
27 }
28 
30 {
31  if(!G_NETWORK_PTR->isOnline())
32  {
33  removeItems();
34  return;
35  }
36 
38 }
39 
41 {
42  if(!isValid(row))
43  {
44  return;
45  }
46 
47  MusicDownloadWidget *widget = new MusicDownloadWidget(this);
48  widget->initialize(m_networkRequest, row);
49  widget->show();
50 }
51 
53 {
54  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
55  QHeaderView *headerView = horizontalHeader();
56  headerView->resizeSection(1, 342 + (width - WINDOW_WIDTH_MIN) / 2.0);
57  headerView->resizeSection(2, 110 + (width - WINDOW_WIDTH_MIN) / 2.0);
58 
59  for(int i = 0; i < rowCount(); ++i)
60  {
61  QTableWidgetItem *it = item(i, 1);
62  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
63 
64  it = item(i, 2);
65  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
66  }
67 }
68 
70 {
71  if(column <= 0 || row < 0 || row >= rowCount() - 1)
72  {
73  return;
74  }
75 
76  addSearchMusicToPlaylist(row, true);
77 }
78 
80 {
81  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
82  const TTKIntList &rows = checkedItemRows();
83  if(rows.isEmpty())
84  {
85  MusicToastLabel::popup(tr("Please select one item first"));
86  return;
87  }
88 
89  for(int i = 0; i < rows.count(); ++i)
90  {
91  const int row = rows[i];
92  if(row >= songInfos.count())
93  {
94  continue;
95  }
96 
97  downloadDataFrom(&songInfos[row], play && (i == 0 /* first item row */));
98  }
99 }
100 
102 {
103  const TTKIntList &rows = checkedItemRows();
104  if(rows.isEmpty())
105  {
106  MusicToastLabel::popup(tr("Please select one item first"));
107  return;
108  }
109 
111  widget.initialize(m_networkRequest, rows);
112  widget.exec();
113 }
114 
116 {
117  const int row = currentRow();
118  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
119  if(!isValid(row) || row >= songInfos.count())
120  {
121  return;
122  }
123 
124  const TTK::MusicSongInformation &info = songInfos[row];
125  switch(action->data().toInt())
126  {
127  case 0: addSearchMusicToPlaylist(row, true); break;
128  case 1: addSearchMusicToPlaylist(row, false); break;
129  case 2: downloadQueryResult(row); break;
133  case 6: MusicRightAreaWidget::instance()->showSongSearchedFound(item(row, 1)->toolTip()); break;
134  default: break;
135  }
136 }
137 
138 void MusicItemQueryTableWidget::resizeEvent(QResizeEvent *event)
139 {
141  resizeGeometry();
142 }
143 
144 void MusicItemQueryTableWidget::contextMenuEvent(QContextMenuEvent *event)
145 {
146  MusicQueryTableWidget::contextMenuEvent(event);
147 
148  QMenu menu;
149  menu.setStyleSheet(TTK::UI::MenuStyle02);
150 
151  const int row = currentRow();
152  const TTK::MusicSongInformationList &songInfos = m_networkRequest->items();
153  if(!isValid(row) || row >= songInfos.count())
154  {
155  return;
156  }
157 
158  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"))->setData(0);
159  menu.addAction(tr("Add to list"))->setData(1);
160  menu.addAction(tr("Download More..."))->setData(2);
161  menu.addSeparator();
162 
163  const TTK::MusicSongInformation &info = songInfos[row];
164  menu.addAction(tr("Search '%1'").arg(info.m_artistName))->setData(3);
165  menu.addAction(tr("Search '%1'").arg(info.m_songName))->setData(4);
166  menu.addAction(tr("Search '%1'").arg(info.m_albumName))->setData(5);
167  menu.addAction(tr("Search '%1 - %2'").arg(info.m_artistName, info.m_songName))->setData(6);
168  connect(&menu, SIGNAL(triggered(QAction*)), SLOT(menuActionChanged(QAction*)));
169  menu.exec(QCursor::pos());
170 }
171 
173 {
175 
176  if(column == 5 || column == 6 || column == 7)
177  {
178  setCursor(QCursor(Qt::PointingHandCursor));
179  }
180  else
181  {
182  unsetCursor();
183  }
184 }
185 
187 {
189 
190  switch(column)
191  {
192  case 5: addSearchMusicToPlaylist(row, true); break;
193  case 6: addSearchMusicToPlaylist(row, false); break;
194  case 7: downloadQueryResult(row); break;
195  default: break;
196  }
197 }
198 
200 {
202  setColumnCount(8);
203 }
204 
206 {
207  const int count = rowCount();
208  setRowCount(count + 1);
209 
210  QHeaderView *headerView = horizontalHeader();
211  QTableWidgetItem *item = new QTableWidgetItem;
212  item->setData(TTK_CHECKED_ROLE, Qt::Unchecked);
213  setItem(count, 0, item);
214 
215  item = new QTableWidgetItem;
216  item->setToolTip(TTK::generateSongName(result.m_songName, result.m_artistName));
217  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
218  item->setForeground(QColor(TTK::UI::Color02));
219  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
220  setItem(count, 1, item);
221 
222  item = new QTableWidgetItem;
223  item->setToolTip(result.m_albumName);
224  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
225  item->setForeground(QColor(TTK::UI::Color02));
226  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
227  setItem(count, 2, item);
228 
229  item = new QTableWidgetItem(result.m_duration);
230  item->setForeground(QColor(TTK::UI::Color02));
231  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
232  setItem(count, 3, item);
233 
234  item = new QTableWidgetItem;
235  item->setIcon(QIcon(":/tiny/lb_server_type"));
236  item->setToolTip(result.m_type);
237  setItem(count, 4, item);
238 
239  item = new QTableWidgetItem;
240  item->setIcon(QIcon(":/contextMenu/btn_play"));
241  setItem(count, 5, item);
242 
243  item = new QTableWidgetItem;
244  item->setIcon(QIcon(":/contextMenu/btn_add"));
245  setItem(count, 6, item);
246 
247  item = new QTableWidgetItem;
248  item->setIcon(QIcon(":/contextMenu/btn_download"));
249  setItem(count, 7, item);
250 
251  setFixedHeight(rowHeight(0) * (rowCount() + 1));
252 }
253 
255 {
256  if(!isValid(row))
257  {
258  MusicToastLabel::popup(tr("Please select one item first"));
259  return;
260  }
261 
262  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
263  if(row >= songInfos.count())
264  {
265  return;
266  }
267 
268  downloadDataFrom(&songInfos[row], play);
269 }
270 
272 {
273  if(!G_NETWORK_PTR->isOnline())
274  {
275  MusicToastLabel::popup(tr("No resource found"));
276  return false;
277  }
278 
280 
281  if(info->m_songProps.isEmpty())
282  {
283  MusicToastLabel::popup(tr("No resource found"));
284  return false;
285  }
286 
287  const TTK::MusicSongProperty &prop = info->m_songProps.first();
288 
289  MusicResultDataItem item;
291  item.m_time = info->m_duration;
292  item.m_id = info->m_songId;
293  item.m_nickName = prop.m_url;
294  item.m_description = prop.m_format;
295  item.m_count = prop.m_size;
296  item.m_title = play ? MUSIC_PLAY_NOW : MUSIC_PLAY_LATER;
297 
298  if(m_networkRequest)
299  {
300  item.m_id = m_networkRequest->queryServer() + item.m_id;
301  }
302 
304  return true;
305 }
static MusicRightAreaWidget * instance()
const TTK::MusicSongInformationList & items() const noexcept
The class of the download batch widget.
void addSearchMusicToPlaylist(int row, bool play)
The class of the search result data item.
The class of the download widget.
virtual void resizeEvent(QResizeEvent *event) override
The class of the music song property.
Definition: musicobject.h:242
MusicSongPropertyList m_songProps
Definition: musicobject.h:314
#define QtItemSetTextAlignment(p, a)
Item text alignment.
Definition: ttkqtcompat.h:45
static constexpr unsigned int Color02
Definition: musicuiobject.h:34
void showSongSearchedFound(const QString &text)
virtual void itemCellClicked(int row, int column) override
static void popup(const QString &text)
void initialize(const QString &name)
virtual void startToQueryResult(TTK::MusicSongInformation *info, int bitrate)
#define MUSIC_PLAY_NOW
virtual void itemDoubleClicked(int row, int column) override
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
virtual void itemCellEntered(int row, int column) overridefinal
bool isValid() const noexcept
void showArtistFound(const QString &text, const QString &id)
virtual void createResultItem(const MusicResultInfoItem &result) override
void initialize(MusicAbstractQueryRequest *request, const TTKIntList &items)
static MusicSongsContainerWidget * instance()
virtual void removeItems() overridefinal
MusicItemQueryTableWidget(QWidget *parent=nullptr)
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
virtual void itemCellEntered(int row, int column)
void showAlbumFound(const QString &text, const QString &id)
void addSongBufferToPlaylist(const MusicResultDataItem &item)
static const QString MenuStyle02
virtual void contextMenuEvent(QContextMenuEvent *event) override
virtual void downloadQueryResult(int row) override
virtual void removeItems() override
The class of the search result info item.
#define MUSIC_PLAY_LATER
#define G_NETWORK_PTR
virtual void resizeEvent(QResizeEvent *event) overridefinal
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:172
The class of the query table widget.
virtual void startToSearchByValue(const QString &value) overridefinal
virtual void itemCellClicked(int row, int column) override
virtual void startToSearch(const QString &value)=0
virtual void resizeGeometry() overridefinal
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist) noexcept
MusicAbstractQueryRequest * m_networkRequest
#define TTK_CHECKED_ROLE
The class of the music song information.
Definition: musicobject.h:300
#define TTK_BN_128
Definition: ttkglobal.h:428
#define G_SETTING_PTR
QString queryServer() const noexcept