TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicvideosearchtablewidget.cpp
Go to the documentation of this file.
3 #include "musictoastlabel.h"
4 #include "musicconnectionpool.h"
5 #include "musicdownloadwidget.h"
6 
9  m_singleRadioMode(false)
10 {
11  setColumnCount(9);
12  resizeSection(0);
13 
15 
16  G_CONNECTION_PTR->setValue(className(), this);
17 }
18 
20 {
21  G_CONNECTION_PTR->removeValue(this);
22  removeItems();
23 }
24 
26 {
27  if(!G_NETWORK_PTR->isOnline()) //no network connection
28  {
29  removeItems();
30  return;
31  }
32 
33  setLoadingStatus(true);
34  setQueryInput(G_DOWNLOAD_QUERY_PTR->makeMovieRequest(this));
35 
36  m_singleRadioMode = false;
39 }
40 
42 {
44  {
45  if(!isValid(row))
46  {
47  MusicToastLabel::popup(tr("Please select one item first"));
48  return;
49  }
50 
51  downloadLocalMovie(row);
52  }
53  else
54  {
56  }
57 }
58 
60 {
61  if(!G_NETWORK_PTR->isOnline()) //no network connection
62  {
63  removeItems();
64  return;
65  }
66 
67  setLoadingStatus(true);
68  setQueryInput(G_DOWNLOAD_QUERY_PTR->makeMovieRequest(this));
69 
70  m_singleRadioMode = false;
73 }
74 
76 {
77  if(!G_NETWORK_PTR->isOnline()) //no network connection
78  {
79  removeItems();
80  return;
81  }
82 
83  setQueryInput(G_DOWNLOAD_QUERY_PTR->makeMovieRequest(this));
84 
85  m_singleRadioMode = true;
87 }
88 
90 {
91  QHeaderView *headerView = horizontalHeader();
92  headerView->resizeSection(0, 30);
93  headerView->resizeSection(1, 306 + delta * 0.5);
94  headerView->resizeSection(2, 159 + delta * 0.5);
95  headerView->resizeSection(3, 55);
96  headerView->resizeSection(4, 24);
97  headerView->resizeSection(5, 24);
98  headerView->resizeSection(6, 24);
99  headerView->resizeSection(7, 24);
100  headerView->resizeSection(8, 24);
101 
102  //resize row
103  for(int i = 0; i < rowCount(); ++i)
104  {
105  QTableWidgetItem *it = item(i, 1);
106  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 5));
107 
108  it = item(i, 2);
109  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 5));
110  }
111 }
112 
114 {
116  if(column == 6 || column == 7 || column == 8)
117  {
118  setCursor(QCursor(Qt::PointingHandCursor));
119  }
120  else
121  {
122  unsetCursor();
123  }
124 }
125 
127 {
129  switch(column)
130  {
131  case 6:
132  case 7: itemDoubleClicked(row, TTK_HIGH_LEVEL); break;
133  case 8: downloadQueryResult(row); break;
134  default:break;
135  }
136 }
137 
139 {
140  if(column <= 0 || row < 0 || row >= rowCount() - 1)
141  {
142  return;
143  }
144 
145  const TTK::MusicSongInformation &info = m_networkRequest->items()[row];
146  const TTK::MusicSongPropertyList &props = info.m_songProps;
147  if(!props.isEmpty())
148  {
149  const TTK::MusicSongProperty &prop = props.front();
150  MusicVideoItem data;
151  data.m_name = TTK::generateSongName(item(row, 1)->toolTip(), item(row, 2)->toolTip());
152  data.m_url = prop.m_url;
153  data.m_id = info.m_songId;
154  data.m_cover = info.m_coverUrl;
156  Q_EMIT mediaUrlPathChanged(data);
157  }
158 }
159 
161 {
163  setColumnCount(9);
164 }
165 
167 {
168  const int count = rowCount();
169  setRowCount(count + 1);
170 
171  QHeaderView *headerView = horizontalHeader();
172  QTableWidgetItem *item = new QTableWidgetItem;
173  item->setData(TTK_CHECKED_ROLE, Qt::Unchecked);
174  item->setBackground(m_backgroundColor);
175  setItem(count, 0, item);
176 
177  item = new QTableWidgetItem;
178  item->setToolTip(songItem.m_songName);
179  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 5));
180  item->setForeground(QColor(TTK::UI::Color02));
181  setItem(count, 1, item);
182 
183  item = new QTableWidgetItem;
184  item->setToolTip(songItem.m_artistName);
185  item->setText(TTK::Widget::elidedText(font(), item->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 5));
186  item->setForeground(QColor(TTK::UI::Color02));
187  setItem(count, 2, item);
188 
189  item = new QTableWidgetItem(songItem.m_duration);
190  item->setForeground(QColor(TTK::UI::Color02));
191  setItem(count, 3, item);
192 
193  item = new QTableWidgetItem;
194  item->setIcon(QIcon(randSimulation()));
195  setItem(count, 4, item);
196 
197  item = new QTableWidgetItem;
198  item->setIcon(QIcon(":/tiny/lb_server_type"));
199  item->setToolTip(songItem.m_type);
200  setItem(count, 5, item);
201 
202  item = new QTableWidgetItem;
203  item->setIcon(QIcon(":/video/btn_mv"));
204  setItem(count, 6, item);
205 
206  item = new QTableWidgetItem;
207  item->setIcon(QIcon(":/video/btn_audition"));
208  setItem(count, 7, item);
209 
210  item = new QTableWidgetItem;
211  item->setIcon(QIcon(":/video/btn_download"));
212  setItem(count, 8, item);
213 }
214 
215 void MusicVideoSearchTableWidget::queryMediaProps(TTK::MusicSongPropertyList &props)
216 {
217  if(!m_networkRequest)
218  {
219  return;
220  }
221 
222  const int row = !m_singleRadioMode ? m_previousClickRow : 0;
223  const TTK::MusicSongInformationList songInfos(m_networkRequest->items());
224  props = (!songInfos.isEmpty() && row != -1) ? songInfos[row].m_songProps : TTK::MusicSongPropertyList();
225 }
226 
228 {
229  if(!m_singleRadioMode)
230  {
231  if(m_previousClickRow != -1 && currentRow() != -1)
232  {
233  downloadLocalMovie(currentRow());
234  }
235  }
236  else
237  {
239  }
240 }
241 
242 void MusicVideoSearchTableWidget::contextMenuEvent(QContextMenuEvent *event)
243 {
244  MusicItemSearchTableWidget::contextMenuEvent(event);
245 
246  QMenu menu(this);
247  createContextMenu(menu);
248  menu.exec(QCursor::pos());
249 }
250 
252 {
253  if(!isValid(row))
254  {
255  return;
256  }
257 
258  MusicDownloadWidget *widget = new MusicDownloadWidget(this);
259  widget->initialize(m_networkRequest, row);
260  widget->show();
261 }
virtual void setQueryInput(MusicAbstractQueryRequest *query)
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:112
The class of the download widget.
void initialize(MusicAbstractQueryRequest *request, int row)
void queryMediaProps(TTK::MusicSongPropertyList &props)
The class of the search item table widget.
The class of the music song property.
Definition: musicobject.h:223
TTK_MODULE_EXPORT void initRandom()
Definition: ttktime.cpp:7
virtual void itemCellClicked(int row, int column) overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:295
static constexpr unsigned int Color02
Definition: musicuiobject.h:34
virtual void downloadQueryResult(int row) overridefinal
#define G_CONNECTION_PTR
virtual void startToSearchByID(const QString &value)
static void popup(const QString &text)
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
virtual void createResultItem(const MusicResultInfoItem &songItem) overridefinal
TTK_MODULE_EXPORT QString elidedText(const QFont &font, const QString &text, Qt::TextElideMode mode, int width)
virtual void itemCellEntered(int row, int column)
virtual void itemDoubleClicked(int row, int column) overridefinal
#define TTK_HIGH_LEVEL
Definition: ttkglobal.h:255
virtual void removeItems() override
The class of the search result info item.
virtual void removeItems() overridefinal
void startToSearchByID(const QString &text)
void setItems(const TTK::MusicSongInformationList &items)
#define G_NETWORK_PTR
virtual void itemCellEntered(int row, int column) overridefinal
The class of the video item play data item.
#define G_DOWNLOAD_QUERY_PTR
void mediaUrlPathChanged(const MusicVideoItem &item)
virtual void itemCellClicked(int row, int column) override
virtual void startToSearch(const QString &value)=0
const TTK::MusicSongInformationList & items() const
MusicVideoSearchTableWidget(QWidget *parent=nullptr)
void setLoadingStatus(bool status) const
MusicAbstractQueryRequest * m_networkRequest
#define TTK_CHECKED_ROLE
The class of the music song information.
Definition: musicobject.h:281
virtual void startToSearchByText(const QString &text) overridefinal