#include "egifattr.h"
#include "ui_egifattr.h"
#include "egif.h"

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

    ui->wFile        ->setText (data.name);
    ui->wPlayDuration->setValue(data.playDuration);
    ui->wPlayTimes   ->setValue(data.playTimes);

    connect(ui->wPlayDuration, SIGNAL(valueChanged(int)), this, SLOT(onAttrChanged()));
    connect(ui->wPlayTimes,    SIGNAL(valueChanged(int)), this, SLOT(onAttrChanged()));
    connect(ui->bnSelectFile,  SIGNAL(clicked(bool)),     this, SLOT(onSelectFile()));
}

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

void eGifAttr::onSelectFile()
{
    QString file = LoAppTools::getInstance()->selectFile(eGif::filters(), this);
    if(!file.isNull()) {
        ui->wFile->setText(QFileInfo(file).fileName());
        emit sResChanged(file);
    }
}

void eGifAttr::onAttrChanged()
{
    eGif::Data data;
    data.playDuration = ui->wPlayDuration->value();
    data.playTimes    = ui->wPlayTimes->value();
    emit sAttrChanged(data);
}
