TTKMusicPlayer  4.1.3.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;
38 }
39 
41 {
43  {
44  if(!isValid(row))
45  {
46  MusicToastLabel::popup(tr("Please select one item first"));
47  return;
48  }
49 
50  downloadLocalMovie(row);
51  }
52  else
53  {
55  }
56 }
57 
59 {
60  if(!G_NETWORK_PTR->isOnline()) //no network connection
61  {
62  removeItems();
63  return;
64  }
65 
66  setLoadingStatus(true);
67  setQueryInput(G_DOWNLOAD_QUERY_PTR->makeMovieRequest(this));
68 
69  m_singleRadioMode = false;
71 }
72 
74 {
75  if(!G_NETWORK_PTR->isOnline()) //no network connection
76  {
77  removeItems();
78  return;
79  }
80 
81  setQueryInput(G_DOWNLOAD_QUERY_PTR->makeMovieRequest(this));
82 
83  m_singleRadioMode = true;
85 }
86 
88 {
89  QHeaderView *headerView = horizontalHeader();
90  headerView->resizeSection(0, 30);
91  headerView->resizeSection(1, 306 + delta * 0.5);
92  headerView->resizeSection(2, 159 + delta * 0.5);
93  headerView->resizeSection(3, 55);
94  headerView->resizeSection(4, 24);
95  headerView->resizeSection(5, 24);
96  headerView->resizeSection(6, 24);
97  headerView->resizeSection(7, 24);
98  headerView->resizeSection(8, 24);
99 
100  //resize row
101  for(int i = 0; i < rowCount(); ++i)
102  {
103  QTableWidgetItem *it = item(i, 1);
104  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(1) - 5));
105 
106  it = item(i, 2);
107  it->setText(TTK::Widget::elidedText(font(), it->toolTip(), Qt::ElideRight, headerView->sectionSize(2) - 5));
108  }
109 }
110 
112 {
114  if(column == 6 || column == 7 || column == 8)
115  {
116  setCursor(QCursor(Qt::PointingHandCursor));
117  }
118  else
119  {
120  unsetCursor();
121  }
122 }
123 
125 {
127  switch(column)
128  {
129  case 6:
130  case 7: itemDoubleClicked(row, TTK_HIGH_LEVEL); break;
131  case 8: downloadQueryResult(row); break;
132  default:break;
133  }
134 }
135 
137 {
138  if(column <= 0 || row < 0 || row >= rowCount() - 1)
139  {
140  return;
141  }
142 
143  const TTK::MusicSongInformation &info = m_networkRequest->items()[row];
144  TTK::MusicSongPropertyList props = info.m_songProps;
145  std::sort(props.begin(), props.end()); //to find out the min bitrate
146 
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 }
void setQueryInput(MusicAbstractQueryRequest *query)
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:105
The class of the download widget.
void queryMediaProps(TTK::MusicSongPropertyList &props)
The class of the search item table widget.
The class of the music song property.
Definition: musicobject.h:225
TTK_MODULE_EXPORT void initRandom()
Definition: ttktime.cpp:7
virtual void itemCellClicked(int row, int column) overridefinal
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
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
void initialize(const QString &name)
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:260
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:283
virtual void startToSearchByText(const QString &text) overridefinal