TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
qkugouwindow.cpp
Go to the documentation of this file.
1 #include "qkugouwindow.h"
2 #include "qkugouuiobject.h"
3 
4 #ifdef TTK_MINIBLINK
5 # include "miniblink/miniblink.h"
6 #elif defined TTK_WEBKIT
7 # if TTK_QT_VERSION_CHECK(5,0,0)
8 # include <QtWebKitWidgets/QWebView>
9 # include <QtWebKitWidgets/QWebFrame>
10 # else
11 # include <QtWebKit/QWebView>
12 # include <QtWebKit/QWebFrame>
13 # endif
14 #elif defined TTK_WEBENGINE
15 # include <QtWebEngineWidgets/QWebEngineView>
16 # include <QtWebEngineWidgets/QWebEngineSettings>
17 #endif
18 
19 #include <QLabel>
20 #include <QTimer>
21 #include <QBoxLayout>
22 #include <QPushButton>
23 #include <QButtonGroup>
24 
28 class QKugouWindowPrivate : public TTKPrivate<QKugouWindow>
29 {
30 public:
33 
34  QWidget *m_webView, *m_topWidget;
35  QButtonGroup *m_buttonGroup;
36 };
37 
39  : m_webView(nullptr),
40  m_topWidget(nullptr),
41  m_buttonGroup(nullptr)
42 {
43 
44 }
45 
47 {
48  delete m_buttonGroup;
49  delete m_topWidget;
50  delete m_webView;
51 }
52 
53 
54 
55 QKugouWindow::QKugouWindow(Module type, QWidget *parent)
56  : QWidget(parent)
57 {
59 
60 #ifdef TTK_WEBKIT
61  QWebSettings *settings = QWebSettings::globalSettings();
62  settings->setAttribute(QWebSettings::PluginsEnabled, true);
63  settings->setAttribute(QWebSettings::JavascriptEnabled, true);
64  settings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
65  settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
66 #elif defined TTK_WEBENGINE
67  QWebEngineSettings *settings = QWebEngineSettings::defaultSettings();
68  settings->setAttribute(QWebEngineSettings::PluginsEnabled, true);
69  settings->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
70  settings->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);
71 #endif
72 
73  if(type != KuGouSong && type != None)
74  {
75  createWebViewer(type);
76  }
77  else
78  {
80  }
81 }
82 
83 void QKugouWindow::setUrl(const QString &url)
84 {
86 #ifdef TTK_MINIBLINK
88  if(w)
89  {
90  w->setUrl(url);
91  }
92 #elif defined TTK_WEBKIT
93  QWebView *w = TTKObjectCast(QWebView*, d->m_webView);
94  if(w)
95  {
96  w->setUrl(url);
97  }
98 #elif defined TTK_WEBENGINE
99  QWebEngineView *w = TTKObjectCast(QWebEngineView*, d->m_webView);
100  if(w)
101  {
102  w->setUrl(url);
103  }
104 #else
105  Q_UNUSED(url);
106  Q_UNUSED(d);
107 #endif
108 }
109 
111 {
113 #ifdef TTK_MINIBLINK
115  if(w)
116  {
117  w->reload();
118  }
119 #elif defined TTK_WEBKIT
120  QWebView *w = TTKObjectCast(QWebView*, d->m_webView);
121  if(w)
122  {
123  w->reload();
124  }
125 #elif defined TTK_WEBENGINE
126  QWebEngineView *w = TTKObjectCast(QWebEngineView*, d->m_webView);
127  if(w)
128  {
129  w->reload();
130  }
131 #else
132  Q_UNUSED(d);
133 #endif
134 }
135 
137 {
138  if(index == 0)
139  {
141  const QList<QAbstractButton*> &buttons = d->m_buttonGroup->buttons();
142  buttons[index]->setStyleSheet(TTK::UI::PushButtonStyle02);
144  }
145  else
146  {
147  Q_EMIT buttonClicked(index + 5); // from kugou song submoudle
148  }
149 }
150 
152 {
154  delete d->m_webView;
155  d->m_webView = nullptr;
156 #ifdef TTK_MINIBLINK
158  {
159  Miniblink *view = new Miniblink(this);
160  d->m_webView = view;
161  }
162 #elif defined TTK_WEBKIT
163  QWebView *view = new QWebView(this);
164  view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
165  view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
166  d->m_webView = view;
167 #elif defined TTK_WEBENGINE
168  QWebEngineView *view = new QWebEngineView(this);
169  d->m_webView = view;
170 #endif
171 }
172 
174 {
176  QVBoxLayout *layout = new QVBoxLayout(this);
177  layout->setSpacing(0);
178  layout->setContentsMargins(0, 0, 0, 0);
179 #if defined TTK_MINIBLINK || defined TTK_WEBKIT || defined TTK_WEBENGINE
180  createWebViewer();
181  if(d->m_webView)
182  {
183  layout->addWidget(d->m_webView);
184 
185  switch(type)
186  {
190  default: break;
191  }
192  }
193  else
194  {
195  QLabel *pix = new QLabel(this);
196  pix->setAlignment(Qt::AlignCenter);
197  pix->setStyleSheet(TTK::UI::WidgetStyle01);
198  pix->setPixmap(QPixmap(":/image/lb_no_module"));
199  layout->addWidget(pix);
200  }
201 #else
202  Q_UNUSED(d);
203  QLabel *pix = new QLabel(this);
204  pix->setAlignment(Qt::AlignCenter);
205  pix->setStyleSheet(TTK::UI::WidgetStyle01);
206  pix->setPixmap(QPixmap(":/image/lb_no_module"));
207  layout->addWidget(pix);
208 #endif
209  setLayout(layout);
210 }
211 
213 {
215  QVBoxLayout *layout = new QVBoxLayout(this);
216  layout->setSpacing(0);
217  layout->setContentsMargins(0, 0, 0, 0);
218 #if defined TTK_MINIBLINK || defined TTK_WEBKIT || defined TTK_WEBENGINE
219  d->m_topWidget = new QWidget(this);
220  d->m_topWidget->setFixedHeight(25);
221  d->m_topWidget->setStyleSheet(TTK::UI::PushButtonStyle01 + TTK::UI::WidgetStyle01);
222  QHBoxLayout *topLayout = new QHBoxLayout(d->m_topWidget);
223  topLayout->setContentsMargins(0, 0, 0, 0);
224  topLayout->setSpacing(25);
225 
226  d->m_buttonGroup = new QButtonGroup(this);
227  QPushButton *bt = new QPushButton(tr("Discovery"), d->m_topWidget);
228  bt->setCursor(QCursor(Qt::PointingHandCursor));
229  d->m_buttonGroup->addButton(bt, 0);
230  bt = new QPushButton(tr("Recommend"), d->m_topWidget);
231  bt->setCursor(QCursor(Qt::PointingHandCursor));
232  d->m_buttonGroup->addButton(bt, 1);
233  bt = new QPushButton(tr("Toplist"), d->m_topWidget);
234  bt->setCursor(QCursor(Qt::PointingHandCursor));
235  d->m_buttonGroup->addButton(bt, 2);
236  bt = new QPushButton(tr("Artists"), d->m_topWidget);
237  bt->setCursor(QCursor(Qt::PointingHandCursor));
238  d->m_buttonGroup->addButton(bt, 3);
239  bt = new QPushButton(tr("Category"), d->m_topWidget);
240  bt->setCursor(QCursor(Qt::PointingHandCursor));
241  d->m_buttonGroup->addButton(bt, 4);
242  QtButtonGroupConnect(d->m_buttonGroup, this, kugouSongIndexChanged, TTK_SLOT);
243 
244  topLayout->addStretch(1);
245  topLayout->addWidget(d->m_buttonGroup->button(0));
246  topLayout->addWidget(d->m_buttonGroup->button(1));
247  topLayout->addWidget(d->m_buttonGroup->button(2));
248  topLayout->addWidget(d->m_buttonGroup->button(3));
249  topLayout->addWidget(d->m_buttonGroup->button(4));
250  topLayout->addStretch(1);
251 
252 #ifdef Q_OS_UNIX
253  d->m_buttonGroup->button(0)->setFocusPolicy(Qt::NoFocus);
254  d->m_buttonGroup->button(1)->setFocusPolicy(Qt::NoFocus);
255  d->m_buttonGroup->button(2)->setFocusPolicy(Qt::NoFocus);
256  d->m_buttonGroup->button(3)->setFocusPolicy(Qt::NoFocus);
257  d->m_buttonGroup->button(4)->setFocusPolicy(Qt::NoFocus);
258 #endif
259 
260  layout->addWidget(d->m_topWidget);
261 
262  if(power)
263  {
264  createWebViewer();
265  if(d->m_webView)
266  {
267  layout->addWidget(d->m_webView);
268  }
269  else
270  {
271  QLabel *pix = new QLabel(this);
272  pix->setAlignment(Qt::AlignCenter);
273  pix->setStyleSheet(TTK::UI::WidgetStyle01);
274  pix->setPixmap(QPixmap(":/image/lb_no_module"));
275  layout->addWidget(pix);
276  }
277  }
278  else
279  {
280  QLabel *pix = new QLabel(this);
281  pix->setAlignment(Qt::AlignCenter);
282  pix->setStyleSheet(TTK::UI::WidgetStyle01);
283  pix->setPixmap(QPixmap(":/image/lb_no_power_mode"));
284  layout->addWidget(pix);
285  }
286 
288 #else
289  Q_UNUSED(d);
290  QLabel *pix = new QLabel(this);
291  pix->setAlignment(Qt::AlignCenter);
292  pix->setStyleSheet(TTK::UI::WidgetStyle01);
293  pix->setPixmap(QPixmap(":/image/lb_no_module"));
294  layout->addWidget(pix);
295 #endif
296  setLayout(layout);
297 }
void createWebViewer()
void buttonClicked(int index)
static const QString PushButtonStyle01
PushButton.
static const QString WidgetStyle01
Widget.
static QString makeMovieRecommendUrl()
Definition: qkugouurl.cpp:18
QButtonGroup * m_buttonGroup
static const QString PushButtonStyle02
QKugouWindow(Module type, QWidget *parent=nullptr)
The class of the kugou window widget.
Definition: qkugouwindow.h:30
void kugouSongIndexChanged(int index)
static QString makeRadioPublicUrl()
Definition: qkugouurl.cpp:13
#define TTK_SLOT
Definition: ttkqtglobal.h:181
#define QtButtonGroupConnect(p, q, f, s)
Button group connect.
Definition: ttkqtcompat.h:101
static QString makeKuiSheUrl()
Definition: qkugouurl.cpp:23
The class of the kugou window widget private.
static QString makeSongRecommendUrl()
Definition: qkugouurl.cpp:8
void createKugouSongWidget(bool power)
#define TTK_INIT_PRIVATE(Class)
Definition: ttkprivate.h:33
The class of the ttk private base.
Definition: ttkprivate.h:48
void setUrl(const QString &url)
#define TTK_D(Class)
Definition: ttkprivate.h:41
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:76