#include "etempattr.h"
#include "ui_etempattr.h"

eTempAttr::eTempAttr(const eTemp::Data &data, QWidget *parent) :
    eAttr(parent),
    ui(new Ui::eTempAttr)
{
    ui->setupUi(this);

    ui->wTemp->setChecked(data.bTemperature);
    ui->wComp->setValue(data.compensation);
    if(data.temperatureType == 0) {
        ui->wCelsius->setChecked(true);
    } else {
        ui->wFahrenheit->setChecked(true);
    }
    ui->wLabelTemp->setText(data.labelTemperature);
   // ui->wText->setText(data.text);
    ui->checkBox_Title->setChecked(data.bTitle);
    ui->lineEdit_Title->setText(data.labelTitle);

    ui->checkBox_Humidity->setChecked(data.bHumidity);
    ui->lineEdit_Humidity->setText(data.labelHumidity);

    ui->checkBox_Noise->setChecked(data.bNoise);
    ui->lineEdit_Noise->setText(data.labelNoise);

    ui->checkBox_WindSpeed->setChecked(data.bWindSpeed);
    ui->lineEdit_WindSpeed->setText(data.labelWindSpeed);

    ui->checkBox_WindDirection->setChecked(data.bWindDirection);
    ui->lineEdit_WindDirection->setText(data.labelWindDirectiton);

    ui->checkBox_PM25->setChecked(data.bPM25);
    ui->lineEdit_PM25->setText(data.labelPm25);

    ui->checkBox_PM10->setChecked(data.bPM10);
    ui->lineEdit_PM10->setText(data.labelPm10);


    ui->wFontFamily->setCurrentText(data.fontFamily);
    ui->wFontSize->setValue(data.fontSize);
    ui->wFontBold->setChecked(data.fontBold);
    ui->wFontItalics->setChecked(data.fontItalics);
    ui->wFontUnderline->setChecked(data.fontUnderline);
    ui->wColor->setColor(data.textColor);
    ui->wPlayRefresh->setValue(data.playRefresh);
    ui->wPlayDuration->setValue(data.playDuration);
    ui->checkBox_paomadeng->setChecked(data.bSingleScroll);
    if(data.bSingleScroll)
    {
        ui->radioButtonLeft->setVisible(false);
        ui->radioButtonCenter->setVisible(false);
        ui->radioButtonRight->setVisible(false);
    }
    else {
        ui->radioButtonLeft->setVisible(true);
        ui->radioButtonCenter->setVisible(true);
        ui->radioButtonRight->setVisible(true);

    }
    ui->spinBoxSpeed->setValue(data.iScrollSpeed);
    ui->wBackgroundColor->setColor(data.cBackground);


    connect(ui->wTemp,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->wComp,          SIGNAL(valueChanged(int)),                  this, SLOT(onAttrChanged()));
    connect(ui->wCelsius,       SIGNAL(toggled(bool)),                      this, SLOT(onRadioChecked(bool)));
    connect(ui->wFahrenheit,    SIGNAL(toggled(bool)),                      this, SLOT(onRadioChecked(bool)));
    connect(ui->wLabelTemp,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_Title,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_Title,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_Humidity,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_Humidity,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_Noise,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_Noise,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_WindSpeed,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_WindSpeed,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_WindDirection,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_WindDirection,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_PM10,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_PM10,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));
    connect(ui->checkBox_PM25,          SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->lineEdit_PM25,     SIGNAL(textChanged(const QString&)),        this, SLOT(onAttrChanged()));

    //connect(ui->wText,          SIGNAL(textChanged()),                      this, SLOT(onAttrChanged()));
    connect(ui->wFontFamily,    SIGNAL(currentTextChanged(const QString&)), this, SLOT(onAttrChanged()));
    connect(ui->wFontSize,      SIGNAL(valueChanged(int)),                  this, SLOT(onAttrChanged()));
    connect(ui->wFontBold,      SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->wFontItalics,   SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->wFontUnderline, SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
    connect(ui->wColor,         SIGNAL(sColorChanged(const QColor&)),       this, SLOT(onAttrChanged()));
    connect(ui->wPlayRefresh,   SIGNAL(valueChanged(int)),                  this, SLOT(onAttrChanged()));
    connect(ui->wPlayDuration,  SIGNAL(valueChanged(int)),                  this, SLOT(onAttrChanged()));
    connect(ui->radioButtonLeft,       SIGNAL(toggled(bool)),                      this, SLOT(onRadioChecked(bool)));
    connect(ui->radioButtonCenter,    SIGNAL(toggled(bool)),                      this, SLOT(onRadioChecked(bool)));
    connect(ui->radioButtonRight,    SIGNAL(toggled(bool)),                      this, SLOT(onRadioChecked(bool)));
    connect(ui->checkBox_paomadeng,   SIGNAL(toggled(bool)),                      this, SLOT(onAttrChanged()));
   // connect(ui->wBackgroundColor,   SIGNAL(sColorChanged(const QColor &)),     this, SLOT(BackgroundColor(const QColor &)));
    connect(ui->wBackgroundColor,   SIGNAL(sColorChanged(const QColor &)),     this, SLOT(onAttrChanged()));
    connect(ui->spinBoxSpeed,          SIGNAL(valueChanged(int)),                 this, SLOT(onAttrChanged()));
}

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

void eTempAttr::onAttrChanged()
{
    eTemp::Data data;
    data.bTemperature          = ui->wTemp->isChecked();
    data.compensation          = ui->wComp->value();
    data.temperatureType      = ui->wCelsius->isChecked() ? 0 : 1;
    data.labelTemperature     = ui->wLabelTemp->text();
    data.bTitle=ui->checkBox_Title->isChecked();
    data.labelTitle          = ui->lineEdit_Title->text();
    data.bHumidity=ui->checkBox_Humidity->isChecked();
    data.labelHumidity          = ui->lineEdit_Humidity->text();
    data.bWindSpeed=ui->checkBox_WindSpeed->isChecked();
    data.labelWindSpeed          = ui->lineEdit_WindSpeed->text();
    data.bWindDirection=ui->checkBox_WindDirection->isChecked();
    data.labelWindDirectiton          = ui->lineEdit_WindDirection->text();
    data.bNoise=ui->checkBox_Noise->isChecked();
    data.labelNoise          = ui->lineEdit_Noise->text();
    data.bPM10=ui->checkBox_PM10->isChecked();
    data.labelPm10        = ui->lineEdit_PM10->text();
    data.bPM25=ui->checkBox_PM25->isChecked();
    data.labelPm25          = ui->lineEdit_PM25->text();

    data.fontFamily    = ui->wFontFamily->currentText();
    data.fontSize      = ui->wFontSize->value();
    data.fontBold      = ui->wFontBold->isChecked();
    data.fontItalics   = ui->wFontItalics->isChecked();
    data.fontUnderline = ui->wFontUnderline->isChecked();
    data.textColor     = ui->wColor->color();
    data.playRefresh   = ui->wPlayRefresh->value();
    data.playDuration  = ui->wPlayDuration->value();
    if(ui->radioButtonLeft->isChecked())
        data.iAlignType  = 0;
    else if(ui->radioButtonCenter->isChecked())
        data.iAlignType  = 1;
    else if(ui->radioButtonRight->isChecked())
        data.iAlignType  = 2;
    data.bSingleScroll=ui->checkBox_paomadeng->isChecked();
    if(data.bSingleScroll)
    {
        ui->radioButtonLeft->setVisible(false);
        ui->radioButtonCenter->setVisible(false);
        ui->radioButtonRight->setVisible(false);
    }
    else {
        ui->radioButtonLeft->setVisible(true);
        ui->radioButtonCenter->setVisible(true);
        ui->radioButtonRight->setVisible(true);

    }
    data.iScrollSpeed=ui->spinBoxSpeed->value();
    data.cBackground=ui->wBackgroundColor->color();
    emit sAttrChanged(data);
}
void eTempAttr::BackgroundColor(const QColor & col)
{
    if (!col.isValid())
        return;
    emit sBackgroundColorChanged(col);
}
