forked from spygg/QBaiduFm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
channelswidget.cpp
70 lines (56 loc) · 1.92 KB
/
channelswidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "channelswidget.h"
#include "ui_channelswidget.h"
#include <QPropertyAnimation>
#include <QSettings>
ChannelsWidget::ChannelsWidget(QWidget *parent, QNetworkCookieJar *cookJar) :
QFrame(parent),
ui(new Ui::ChannelsWidget)
{
ui->setupUi(this);
setFrameStyle(QFrame::NoFrame);
m_getChannelList = new GetBaiduChannel(0, cookJar);
m_gridlayOut = new QGridLayout;
m_channelList = getChannelList();
for(int i = 0, k = 0; i < m_channelList.size() / 4; i++, k += 4)
{
for(int j = 0; j < 4; j++)
{
QPushButton *btn = new QPushButton(this);
btn->setText(m_channelList.at(k + j).channelName);
//qDebug() << m_channelList.at(k + j).channelName;
m_gridlayOut->addWidget(btn, i, j);
//qDebug() << k + j;
m_btnGroup.addButton(btn, k + j);
}
}
setLayout(m_gridlayOut);
connect( &m_btnGroup, SIGNAL(buttonClicked (int)), this, SLOT(channelSelected(int)) );
m_iLastChannelIndex = 0;
}
void ChannelsWidget::channelSelected(int iChannel)
{
//先还原样式表
m_btnGroup.button(m_iLastChannelIndex)->setStyleSheet("");
m_btnGroup.button(iChannel)->setStyleSheet("QPushButton{ font-weight:600;color:#5500ff;}");
m_iLastChannelIndex = iChannel;
emit channelChanged(m_channelList.at(iChannel));
//记录当前频道信息
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm");
settings.beginGroup("User");
settings.setValue("ChannelId", m_channelList.at(iChannel).channelId);
settings.setValue("ChannelName", m_channelList.at(iChannel).channelName);
settings.setValue("ChannelIndex", iChannel);
settings.endGroup();
}
ChannelsWidget::~ChannelsWidget()
{
delete ui;
}
void ChannelsWidget::leaveEvent(QEvent *event)
{
hide();
}
QList<CHANNEL_INFO> ChannelsWidget::getChannelList()
{
return m_getChannelList->getMusicChannel();
}