#include "controlvolumewidget.h"
#include "ui_controlvolumewidget.h"

ControlVolumeWidget::ControlVolumeWidget(QWidget *parent,QList<LedCard *> *list) :
    QWidget(parent),
    ui(new Ui::ControlVolumeWidget)
{
    m_pLedlist=list;
    ui->setupUi(this);
    refreshLable();
    m_pStackedW = new QStackedWidget;
    m_pManual = new ControlVolumeManual(this,m_pLedlist);
    m_pSchedule = new ControlVolumeSchedule(this,m_pLedlist);
    m_pStackedW->addWidget(m_pManual);
    m_pStackedW->addWidget(m_pSchedule);
    ui->horizontalLayout_2->addWidget(m_pStackedW);
    init();
    connect(parent->parent()->parent(),SIGNAL(sigSelectedDeviceList(QList<LedCard *> *)),this,SLOT(onSelectedDeviceList(QList<LedCard *> *)));
    connect(parent->parent(),SIGNAL(sigChangeLanguage()),this,SLOT(refreshLable()));
    connect(m_pSchedule,SIGNAL(sigHaveSchedule(bool)),this,SLOT(OnGetVolumeModeType(bool)));

}

ControlVolumeWidget::~ControlVolumeWidget()
{
    m_pStackedW->deleteLater()  ;
    m_pManual->deleteLater()  ;
    m_pSchedule->deleteLater()  ;
    delete ui;
}
void ControlVolumeWidget::refreshLable()
{
    ui->labelVolumeControl->setText(tr("Volume Control"));
    ui->radioButtonManual->setText(tr("Manual"));
    ui->radioButtonSchedule->setText(tr("Schedule"));
}

void ControlVolumeWidget::init()
{
    m_buttonGroup = new QButtonGroup;
    //第二个参数id可以自行定义
    m_buttonGroup->addButton(ui->radioButtonManual,0);
    m_buttonGroup->addButton(ui->radioButtonSchedule,1);
    connect(m_buttonGroup,SIGNAL(buttonClicked(int)),m_pStackedW,SLOT(setCurrentIndex(int)));
    ui->radioButtonManual->setChecked(true);
    m_pStackedW->setCurrentIndex(0);

}
void ControlVolumeWidget::OnGetVolumeModeType(bool b)
{
    if(b)
    {
        m_pStackedW->setCurrentIndex(1);
        ui->radioButtonSchedule->setChecked(true);
    }
    else
    {
        m_pStackedW->setCurrentIndex(0);
        ui->radioButtonManual->setChecked(true);
    }
}
