|
3 | 3 | #include <QBoxLayout>
|
4 | 4 | #include <QWebView>
|
5 | 5 | #include <QWebFrame>
|
| 6 | +#include <QPushButton> |
| 7 | +#include <QButtonGroup> |
6 | 8 |
|
7 | 9 | KugouWindow::KugouWindow(QWidget *parent)
|
8 | 10 | : QWidget(parent)
|
9 | 11 | {
|
10 |
| - QHBoxLayout *layout = new QHBoxLayout(this); |
| 12 | + QVBoxLayout *layout = new QVBoxLayout(this); |
11 | 13 | layout->setSpacing(0);
|
12 | 14 | layout->setContentsMargins(0, 0, 0, 0);
|
13 | 15 |
|
14 |
| - QWebView *w = new QWebView(this); |
15 |
| - w->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
16 |
| - w->setUrl(QUrl("http://www2.kugou.kugou.com/yueku/v9/html/home.html")); |
| 16 | + const QString radioStyle = "QPushButton{ border:none; color:rgb(135, 135, 135);} \ |
| 17 | + QPushButton:hover{ color:rgb(104, 169, 236);} \ |
| 18 | + QPushButton:checked{ color:rgb(40, 143, 231);} \ |
| 19 | + QWidget{background: white;}"; |
| 20 | + QWidget *top = new QWidget(this); |
| 21 | + top->setFixedHeight(25); |
| 22 | + top->setStyleSheet( radioStyle ); |
| 23 | + QHBoxLayout *topLayout = new QHBoxLayout(top); |
| 24 | + topLayout->setContentsMargins(0, 0, 0, 0); |
17 | 25 |
|
18 |
| - layout->addWidget(w); |
| 26 | + QButtonGroup *buttonGroup = new QButtonGroup(this); |
| 27 | + QPushButton *bt = new QPushButton(tr(" Recommend "), top); |
| 28 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 29 | + buttonGroup->addButton(bt, 0); |
| 30 | + bt = new QPushButton(tr(" Radio "), top); |
| 31 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 32 | + buttonGroup->addButton(bt, 1); |
| 33 | + bt = new QPushButton(tr(" Rank "), top); |
| 34 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 35 | + buttonGroup->addButton(bt, 2); |
| 36 | + bt = new QPushButton(tr(" Singer "), top); |
| 37 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 38 | + buttonGroup->addButton(bt, 3); |
| 39 | + bt = new QPushButton(tr(" Category "), top); |
| 40 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 41 | + buttonGroup->addButton(bt, 4); |
| 42 | + bt = new QPushButton(tr(" Show "), top); |
| 43 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 44 | + buttonGroup->addButton(bt, 5); |
| 45 | + bt = new QPushButton(tr(" CCTV "), top); |
| 46 | + bt->setCursor(QCursor(Qt::PointingHandCursor)); |
| 47 | + buttonGroup->addButton(bt, 6); |
| 48 | + connect(buttonGroup, SIGNAL(buttonClicked(int)), SLOT(differButtonIndexChanged(int))); |
| 49 | + |
| 50 | + topLayout->addStretch(1); |
| 51 | + topLayout->addWidget(buttonGroup->button(0)); |
| 52 | + topLayout->addWidget(buttonGroup->button(1)); |
| 53 | + topLayout->addWidget(buttonGroup->button(2)); |
| 54 | + topLayout->addWidget(buttonGroup->button(3)); |
| 55 | + topLayout->addWidget(buttonGroup->button(4)); |
| 56 | + topLayout->addWidget(buttonGroup->button(5)); |
| 57 | + topLayout->addWidget(buttonGroup->button(6)); |
| 58 | + topLayout->addStretch(1); |
| 59 | + |
| 60 | + m_webView = new QWebView(this); |
| 61 | + m_webView->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); |
| 62 | + m_webView->setUrl(QUrl( KugouUrl::getRecommendUrl() )); |
| 63 | + |
| 64 | + layout->addWidget(top); |
| 65 | + layout->addWidget(m_webView); |
19 | 66 | setLayout(layout);
|
20 | 67 | }
|
21 | 68 |
|
22 | 69 | KugouWindow::~KugouWindow()
|
23 | 70 | {
|
| 71 | + delete m_webView; |
| 72 | +} |
24 | 73 |
|
| 74 | +void KugouWindow::differButtonIndexChanged(int index) |
| 75 | +{ |
| 76 | + QString url = KugouUrl::getRecommendUrl(); |
| 77 | + switch(index) |
| 78 | + { |
| 79 | + case 0: url = KugouUrl::getRecommendUrl(); break; |
| 80 | + case 1: url = KugouUrl::getRadioUrl(); break; |
| 81 | + case 2: url = KugouUrl::getRankUrl(); break; |
| 82 | + case 3: url = KugouUrl::getSingerUrl(); break; |
| 83 | + case 4: url = KugouUrl::getCategoryUrl(); break; |
| 84 | + case 5: url = KugouUrl::getShowUrl(); break; |
| 85 | + case 6: url = KugouUrl::getCCTVUrl(); break; |
| 86 | + } |
| 87 | + m_webView->setUrl(QUrl( url )); |
25 | 88 | }
|
0 commit comments