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

#define ICON_SIZE QSize(30, 30)

tips::tips(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::tips)
{
    ui->setupUi(this);
	ui->labelLogo->setGeometry(25,7,30,30);
    ui->labelContent->setGeometry(65,0,210,50);
	ui->widgetCheckBox->hide();
	//ui->widgetCheckBox->removeItem(ui->horizontalSpacer);
	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)));
}

void tips::information(QString content, bool next)
{
    QFont f;

    f = ui->labelContent->font();
    f.setPixelSize(16);
    ui->labelContent->setFont(f);
    f=ui->checkBox->font();
    f.setPixelSize(16);
    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)
{
    QFont f;

    f = ui->labelContent->font();
    f.setPixelSize(16);
    ui->labelContent->setFont(f);
    f=ui->checkBox->font();
    f.setPixelSize(16);
    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::question(QString content, bool next)
{
    QFont f;

    f = ui->labelContent->font();
    f.setPixelSize(16);
    ui->labelContent->setFont(f);
    f=ui->checkBox->font();
    f.setPixelSize(16);
    ui->checkBox->setFont(f);
    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;
}
