#include "tips.h"
#include "ui_tips.h"
#include "src/po/translation.h"
#include "src/view/modaldialog.h"
#include "src/model/logicmain.h"
#include <QDebug>
#include <ukuistylehelper/ukuistylehelper.h>

#define ICON_SIZE QSize(30, 30)

tips::tips(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::tips)
{
    this->setObjectName("kylin-burner_tips");
    ui->setupUi(this);

    ui->checkBox->setAccessibleName("kylin-burner_QCheckBox_tips_checkBox");
    ui->labelContent->setAccessibleName("kylin-burner_QLabel_tips_labelContent");
    ui->labelLogo->setAccessibleName("kylin-burner_QLabel_tips_labelLogo");
    ui->widget->setAccessibleName("kylin-burner_QWidget_tips_widget");
    ui->widgetCheckBox->setAccessibleName("kylin-burner_QWidget_tips_widgetCheckBox");

    ui->labelLogo->setGeometry(25,7,30,30);
    ui->labelContent->setGeometry(65,0,210,50);
    ui->widgetCheckBox->hide();
    ui->verticalLayout->removeWidget(ui->widgetCheckBox);
    ui->checkBox->hide();
    connect(this, SIGNAL(success(QString)), this, SLOT(slotsSuccess(QString)));
    connect(this, SIGNAL(fail(QString)), this, SLOT(slotsFailed(QString)));
    connect(ui->checkBox, SIGNAL(toggled(bool)), this, SIGNAL(checked(bool)));

    slotChangeUIFontSize(LogicMain::instance()->GetSystemFontSize());
    connect(LogicMain::instance(), &LogicMain::systemFontSizeChanged, this, &tips::slotChangeUIFontSize);
}

void tips::information(QString content, bool next)
{
    ui->labelContent->setText(content);
    ui->checkBox->setText(_("Donot show agian."));
    ui->checkBox->setChecked(false);
    ui->checkBox->setHidden(next);
    ui->labelLogo->setPixmap(QIcon::fromTheme("dialog-information").pixmap(ICON_SIZE));
}

void tips::error(QString content, bool next)
{
    ui->labelContent->setFixedWidth(300);
    ui->labelContent->setText(content);
    ui->checkBox->setText(_("Donot show agian."));
    ui->checkBox->setChecked(false);
    ui->checkBox->setHidden(next);
    ui->labelLogo->setPixmap(QIcon::fromTheme("dialog-error").pixmap(ICON_SIZE));
}

void tips::slotChangeUIFontSize(int fontSize)
{
    int scaleRatio = qAbs(fontSize - 10.0);

    QFont font;
    font = ui->labelContent->font();
    font.setPixelSize(16 + scaleRatio);
    ui->labelContent->setFont(font);
    font = ui->checkBox->font();
    font.setPixelSize(16 + scaleRatio);
    ui->checkBox->setFont(font);

}

void tips::question(QString content, bool next)
{
    ui->labelContent->setFixedWidth(320);
    ui->labelContent->setText(content);
    ui->checkBox->setChecked(false);
    ui->checkBox->setText(_("Donot show agian."));
    ui->checkBox->setHidden(next);
    ui->labelLogo->setPixmap(QIcon::fromTheme("dialog-question").pixmap(ICON_SIZE));
}

void tips::slotsSuccess(QString name)
{
    QFont f;

    MODAL->showPage(ModalDialog::Tip);
    MODAL->show();
    qDebug()<<__LINE__<<__func__<<"tips"<<name;
    f = ui->labelContent->font();
    f.setPixelSize(24);
    f.setWeight(400);
    ui->widgetCheckBox->hide();
    ui->labelContent->setFont(f);
    ui->labelContent->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
    ui->labelContent->setText(name + _(" Success"));
    ui->labelLogo->setPixmap(QIcon::fromTheme("ukui-dialog-success").pixmap(ICON_SIZE));
}

void tips::slotsFailed(QString name)
{
    QFont f;

    MODAL->showPage(ModalDialog::Tip);
    MODAL->show();

    f = ui->labelContent->font();
    f.setPixelSize(24);
    f.setWeight(400);
    ui->widgetCheckBox->hide();
    ui->labelContent->setFont(f);
    ui->labelContent->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
    ui->labelContent->setText(name + _(" Failed"));
    ui->labelLogo->setPixmap(QIcon::fromTheme("dialog-error").pixmap(ICON_SIZE));
}

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