#include "commonbuttongroupwidget.h"
#include "ui_commonbuttongroupwidget.h"

CommonButtonGroupWidget::CommonButtonGroupWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CommonButtonGroupWidget)
{
    ui->setupUi(this);
}

void CommonButtonGroupWidget::initialize()
{
    ui->loadingProgressBar->setValue(0);
    ui->loadingProgressBar->hide();
    ui->updateButton->hide();
    ui->startButton->hide();
    ui->startButton->setEnabled(false);   
    show();
}

void CommonButtonGroupWidget::updateProgressBar(float value)
{
    ui->loadingProgressBar->setValue(value);
}

void CommonButtonGroupWidget::loadCompleteState()
{
    show();
    ui->updateButton->setEnabled(false);
    ui->startButton->setEnabled(true);
    ui->loadingProgressBar->setValue(100);
    ui->startButton->show();
    ui->loadingProgressBar->hide();
}

void CommonButtonGroupWidget::lastVerInstalledState()
{
    show();
    ui->updateButton->hide();
    ui->loadingProgressBar->hide();
    ui->startButton->setEnabled(true);
    ui->startButton->show();
}

void CommonButtonGroupWidget::disconnectState()
{
    ui->startButton->hide();
    ui->loadingProgressBar->hide();
    ui->updateButton->hide();
    ui->updateButton->setEnabled(false);
}

void CommonButtonGroupWidget::startUpdateState()
{
    ui->updateButton->hide();
    ui->startButton->hide();
    ui->loadingProgressBar->setValue(0);
    ui->loadingProgressBar->show();
}

void CommonButtonGroupWidget::showProgressBar(bool flag)
{
    if (flag) ui->loadingProgressBar->show();
    else ui->loadingProgressBar->hide();
}

void CommonButtonGroupWidget::needUpdateState(bool flag)
{
    ui->startButton->hide();
    ui->updateButton->setEnabled(flag);
    ui->updateButton->show();
}

void CommonButtonGroupWidget::startButtonActive(bool flag)
{
    ui->startButton->setEnabled(flag);
}

void CommonButtonGroupWidget::on_updateButton_clicked()
{
    emit sigSendPacket(PacketType::TYPE_UPDATE);
    startUpdateState();
    emit sigUpdateCommonWidget();

}

void CommonButtonGroupWidget::on_startButton_clicked()
{
    emit sigStartUnityClient();
}

CommonButtonGroupWidget::~CommonButtonGroupWidget()
{
    delete ui;
}




