TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicadvancedsearchedwidget.cpp
Go to the documentation of this file.
3 #include "musicitemsearchedit.h"
4 #include "musicrightareawidget.h"
6 #include "musictoastlabel.h"
7 #include "musicwidgetheaders.h"
8 #include "ttktabbutton.h"
9 
11  : QWidget(parent)
12 {
13  setStyleSheet(TTK::UI::BackgroundStyle10);
14 
15  QVBoxLayout *layout = new QVBoxLayout(this);
16  layout->setSpacing(0);
17  layout->setContentsMargins(0, 0, 0, 0);
18 
19  QWidget *mainWidget = new QWidget(this);
20  QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
21  mainLayout->setSpacing(20);
22  mainLayout->setContentsMargins(30, 30, 30, 30);
23  mainWidget->setLayout(mainLayout);
24  layout->addWidget(mainWidget);
25  setLayout(layout);
26 
27  m_tabWidget = new TTKTabButton(mainWidget);
28  m_tabWidget->addButtons({tr("Song"), tr("Artist"), tr("Album"), tr("Playlist"), tr("Movie")});
29  connect(m_tabWidget, SIGNAL(clicked(int)), SLOT(typeIndexChanged(int)));
30 
31  QWidget *containerWidget = new QWidget(mainWidget);
32  containerWidget->setFixedHeight(250);
33  QVBoxLayout *containerLayout = new QVBoxLayout(containerWidget);
34  containerLayout->setContentsMargins(0, 0, 0, 0);
35 
36  m_searchLabel = new QLabel(containerWidget);
37  m_searchLabel->setStyleSheet(TTK::UI::FontStyle05);
38  m_searchEdit = new MusicItemSearchEdit(containerWidget);
39  m_searchEdit->setFixedHeight(40);
40 
41  containerLayout->setSpacing(10);
42  containerLayout->addStretch(1);
43  containerLayout->addWidget(m_searchLabel);
44  containerLayout->addWidget(m_searchEdit);
45  containerLayout->addStretch(1);
46  containerWidget->setLayout(containerLayout);
47 
48  mainLayout->addStretch(1);
49  mainLayout->addWidget(m_tabWidget);
50  mainLayout->addWidget(containerWidget);
51 
52  QPushButton *button = new QPushButton(tr("Search"), mainWidget);
53  button->setFixedSize(100, 35);
54  button->setStyleSheet(TTK::UI::PushButtonStyle03);
55  button->setCursor(QCursor(Qt::PointingHandCursor));
56  connect(button, SIGNAL(clicked()), SLOT(searchButtonClicked()));
57 #ifdef Q_OS_UNIX
58  button->setFocusPolicy(Qt::NoFocus);
59 #endif
60  mainLayout->addWidget(button, 0, Qt::AlignCenter);
61  mainLayout->addStretch(1);
62 
64 }
65 
67 {
68  delete m_tabWidget;
69 }
70 
72 {
73  switch(index)
74  {
75  case 0:
76  {
77  m_searchLabel->setText(tr("Input song id or url link"));
79  {
80  case MusicAbstractQueryRequest::QueryServer::WY: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(WY_SG_SHARE, MDII_SHR_KEY, false).arg("28830412")); break;
81  case MusicAbstractQueryRequest::QueryServer::KW: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KW_SG_SHARE, MDII_SHR_KEY, false).arg("23983067")); break;
82  case MusicAbstractQueryRequest::QueryServer::KG: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KG_SG_SHARE, MDII_SHR_KEY, false).arg("f9b7637d5a482015b9bdb4fbea704e8e")); break;
83  default: break;
84  }
85  break;
86  }
87  case 1:
88  {
89  m_searchLabel->setText(tr("Input artist id or url link"));
91  {
92  case MusicAbstractQueryRequest::QueryServer::WY: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(WY_AR_SHARE, MDII_SHR_KEY, false).arg("964486")); break;
93  case MusicAbstractQueryRequest::QueryServer::KW: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KW_AR_SHARE, MDII_SHR_KEY, false).arg("373")); break;
94  case MusicAbstractQueryRequest::QueryServer::KG: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KG_AR_SHARE, MDII_SHR_KEY, false).arg("832532")); break;
95  default: break;
96  }
97  break;
98  }
99  case 2:
100  {
101  m_searchLabel->setText(tr("Input album id or url link"));
103  {
104  case MusicAbstractQueryRequest::QueryServer::WY: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(WY_AL_SHARE, MDII_SHR_KEY, false).arg("2901140")); break;
105  case MusicAbstractQueryRequest::QueryServer::KW: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KW_AL_SHARE, MDII_SHR_KEY, false).arg("2698608")); break;
106  case MusicAbstractQueryRequest::QueryServer::KG: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KG_AL_SHARE, MDII_SHR_KEY, false).arg("41169925")); break;
107  default: break;
108  }
109  break;
110  }
111  case 3:
112  {
113  m_searchLabel->setText(tr("Input playlist id or url link"));
115  {
116  case MusicAbstractQueryRequest::QueryServer::WY: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(WY_PL_SHARE, MDII_SHR_KEY, false).arg("988604820")); break;
117  case MusicAbstractQueryRequest::QueryServer::KW: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KW_PL_SHARE, MDII_SHR_KEY, false).arg("3565578939")); break;
118  case MusicAbstractQueryRequest::QueryServer::KG: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KG_PL_SHARE, MDII_SHR_KEY, false).arg("3339907")); break;
119  default: break;
120  }
121  break;
122  }
123  case 4:
124  {
125  m_searchLabel->setText(tr("Input movie id or url link"));
127  {
128  case MusicAbstractQueryRequest::QueryServer::WY: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(WY_MV_SHARE, MDII_SHR_KEY, false).arg("5343487")); break;
129  case MusicAbstractQueryRequest::QueryServer::KW: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KW_MV_SHARE, MDII_SHR_KEY, false).arg("156505081")); break;
130  case MusicAbstractQueryRequest::QueryServer::KG: m_searchEdit->editor()->setPlaceholderText(TTK::Algorithm::mdII(KG_MV_SHARE, MDII_SHR_KEY, false).arg("g9ai88")); break;
131  default: break;
132  }
133  break;
134  }
135  default: break;
136  }
137 }
138 
140 {
141  const int server = G_SETTING_PTR->value(MusicSettingManager::DownloadServerIndex).toInt();
142  if(server > 3 || server < 0)
143  {
144  MusicToastLabel::popup(tr("Current server is not support search"));
145  return;
146  }
147 
148  const QString &url = !m_searchEdit->editor()->text().isEmpty() ? m_searchEdit->editor()->text() : m_searchEdit->editor()->placeholderText();
149  const QString &key = searchedKeyWork(m_tabWidget->currentIndex(), url);
150  if(key.isEmpty())
151  {
152  MusicToastLabel::popup(tr("Can not parse the url"));
153  return;
154  }
155 
156  switch(m_tabWidget->currentIndex())
157  {
159  case 1: MusicRightAreaWidget::instance()->showArtistFound({}, key); break;
160  case 2: MusicRightAreaWidget::instance()->showAlbumFound({}, key); break;
161  case 3: MusicRightAreaWidget::instance()->showPlaylistFound(key); break;
163  default: break;
164  }
165 }
166 
167 QString MusicAdvancedSearchedWidget::searchedKeyWork(int type, const QString &url)
168 {
169  QString key;
171  {
173  {
174  static TTKRegularExpression regx("id=(\\d+)");
175  key = (regx.match(url) != -1) ? regx.captured(1) : QString();
176  break;
177  }
179  {
181  switch(type)
182  {
183  case 1: regx.setPattern("id=(\\d+)"); break;
184  case 3: regx.setPattern("pid=(\\d+)"); break;
185  default: regx.setPattern("/(\\d+)"); break;
186  }
187 
188  key = (regx.match(url) != -1) ? regx.captured(1) : QString();
189  break;
190  }
192  {
194  switch(type)
195  {
196  case 0: regx.setPattern("hash=(\\w+)"); break;
197  case 4: regx.setPattern("/mv_(\\w+)"); break;
198  default: regx.setPattern("/(\\d+)"); break;
199  }
200 
201  key = (regx.match(url) != -1) ? regx.captured(1) : QString();
202  break;
203  }
204  default: break;
205  }
206  return key;
207 }
void showSingleSearchedFound(const QString &id)
static constexpr const char * WY_SG_SHARE
static MusicRightAreaWidget * instance()
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:231
QString captured(int index) const
static constexpr const char * KW_PL_SHARE
MusicAdvancedSearchedWidget(QWidget *parent=nullptr)
static constexpr const char * KG_SG_SHARE
static constexpr const char * WY_MV_SHARE
static constexpr const char * KW_AR_SHARE
static constexpr const char * KG_AL_SHARE
void addButtons(const QStringList &titles)
void setPattern(const QString &v)
static void popup(const QString &text)
MusicSearchEdit * editor() const noexcept
static const QString FontStyle05
static const QString PushButtonStyle03
The class of the search line edit widget.
void showArtistFound(const QString &text, const QString &id)
static constexpr wchar_t key[]
static constexpr const char * KW_SG_SHARE
static constexpr const char * KG_AR_SHARE
QString searchedKeyWork(int type, const QString &url)
static constexpr const char * KW_AL_SHARE
static constexpr const char * KG_MV_SHARE
static constexpr const char * WY_PL_SHARE
void showAlbumFound(const QString &text, const QString &id)
static const QString BackgroundStyle10
void showPlaylistFound(const QString &id)
The class of the regular expression.
int currentIndex() const noexcept
Definition: ttktabbutton.h:54
The class of the tab button module.
Definition: ttktabbutton.h:29
static constexpr const char * WY_AL_SHARE
int match(const QString &str, int pos=0)
static constexpr const char * KW_MV_SHARE
static constexpr const char * WY_AR_SHARE
static constexpr const char * MDII_SHR_KEY
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
static constexpr const char * KG_PL_SHARE
void showMovieSearchedFound(const QString &name, const QString &id)
#define G_SETTING_PTR