TTKMusicPlayer  4.2.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  if(column <= 0 || row < 0 || row >= rowCount() - 1)
55  {
56  return;
57  }
58 
59  addSearchMusicToPlaylist(row, true);
60 }
61 
63 {
64  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
65  const TTKIntList &list = checkedIndexList();
66  if(list.isEmpty())
67  {
68  MusicToastLabel::popup(tr("Please select one item first"));
69  return;
70  }
71 
72  for(int i = 0; i < list.count(); ++i)
73  {
74  const int index = list[i];
75  if(index >= songInfos.count())
76  {
77  continue;
78  }
79 
80  downloadDataFrom(&songInfos[index], play && (i == 0 /* first item row */));
81  }
82 }
83 
85 {
86  const TTKIntList &list = checkedIndexList();
87  if(list.isEmpty())
88  {
89  MusicToastLabel::popup(tr("Please select one item first"));
90  return;
91  }
92 
94  widget.initialize(m_networkRequest, list);
95  widget.exec();
96 }
97 
99 {
100  const int width = G_SETTING_PTR->value(MusicSettingManager::WidgetSize).toSize().width();
101  QHeaderView *headerView = horizontalHeader();
102  headerView->resizeSection(1, 342 + (width - WINDOW_WIDTH_MIN) / 2.0);
103  headerView->resizeSection(2, 110 + (width - WINDOW_WIDTH_MIN) / 2.0);
104 
105  for(int i = 0; i < rowCount(); ++i)
106  {
107  QTableWidgetItem *it = item(i, 1);
108  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
109 
110  it = item(i, 2);
111  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
112  }
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  resizeSection();
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  if(column == 5 || column == 6 || column == 7)
176  {
177  setCursor(QCursor(Qt::PointingHandCursor));
178  }
179  else
180  {
181  unsetCursor();
182  }
183 }
184 
186 {
188 
189  switch(column)
190  {
191  case 5: addSearchMusicToPlaylist(row, true); break;
192  case 6: addSearchMusicToPlaylist(row, false); break;
193  case 7: downloadQueryResult(row); break;
194  default: break;
195  }
196 }
197 
199 {
201  setColumnCount(8);
202 }
203 
205 {
206  const int count = rowCount();
207  setRowCount(count + 1);
208 
209  QHeaderView *headerView = horizontalHeader();
210  QTableWidgetItem *item = new QTableWidgetItem;
211  item->setData(TTK_CHECKED_ROLE, Qt::Unchecked);
212  setItem(count, 0, item);
213 
214  item = new QTableWidgetItem;
215  item->setToolTip(TTK::generateSongName(result.m_songName, result.m_artistName));
216  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 31));
217  item->setForeground(QColor(TTK::UI::Color02));
218  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
219  setItem(count, 1, item);
220 
221  item = new QTableWidgetItem;
222  item->setToolTip(result.m_albumName);
223  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 31));
224  item->setForeground(QColor(TTK::UI::Color02));
225  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
226  setItem(count, 2, item);
227 
228  item = new QTableWidgetItem(result.m_duration);
229  item->setForeground(QColor(TTK::UI::Color02));
230  QtItemSetTextAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
231  setItem(count, 3, item);
232 
233  item = new QTableWidgetItem;
234  item->setIcon(QIcon(":/tiny/lb_server_type"));
235  item->setToolTip(result.m_type);
236  setItem(count, 4, item);
237 
238  item = new QTableWidgetItem;
239  item->setIcon(QIcon(":/contextMenu/btn_play"));
240  setItem(count, 5, item);
241 
242  item = new QTableWidgetItem;
243  item->setIcon(QIcon(":/contextMenu/btn_add"));
244  setItem(count, 6, item);
245 
246  item = new QTableWidgetItem;
247  item->setIcon(QIcon(":/contextMenu/btn_download"));
248  setItem(count, 7, item);
249 
250  setFixedHeight(rowHeight(0) * (rowCount() + 1));
251 }
252 
254 {
255  if(!isValid(row))
256  {
257  MusicToastLabel::popup(tr("Please select one item first"));
258  return;
259  }
260 
261  TTK::MusicSongInformationList songInfos(m_networkRequest->items());
262  if(row >= songInfos.count())
263  {
264  return;
265  }
266 
267  downloadDataFrom(&songInfos[row], play);
268 }
269 
271 {
272  if(!G_NETWORK_PTR->isOnline())
273  {
274  MusicToastLabel::popup(tr("No resource found"));
275  return false;
276  }
277 
279 
280  if(info->m_songProps.isEmpty())
281  {
282  MusicToastLabel::popup(tr("No resource found"));
283  return false;
284  }
285 
286  const TTK::MusicSongProperty &prop = info->m_songProps.front();
287 
288  MusicResultDataItem item;
290  item.m_time = info->m_duration;
291  item.m_id = info->m_songId;
292  item.m_nickName = prop.m_url;
293  item.m_description = prop.m_format;
294  item.m_count = prop.m_size;
295  item.m_title = play ? MUSIC_PLAY_NOW : MUSIC_PLAY_LATER;
296 
297  if(m_networkRequest)
298  {
299  item.m_id = m_networkRequest->queryServer() + item.m_id;
300  }
301 
303  return true;
304 }
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:237
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
#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 startToSearchByText(const QString &text) overridefinal
virtual void resizeEvent(QResizeEvent *event) overridefinal
#define WINDOW_WIDTH_MIN
Definition: musicobject.h:167
The class of the query table widget.
virtual void itemCellClicked(int row, int column) override
virtual void startToSearch(const QString &value)=0
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist) noexcept
Definition: musicsong.cpp:105
MusicAbstractQueryRequest * m_networkRequest
#define TTK_CHECKED_ROLE
The class of the music song information.
Definition: musicobject.h:295
#define TTK_BN_128
Definition: ttkglobal.h:428
#define G_SETTING_PTR
QString queryServer() const noexcept