#include "animatedtbutton.h"
#include <QPropertyAnimation>

AnimatedtButton::AnimatedtButton(QWidget *parent)
    :QPushButton(parent)
{

}

void AnimatedtButton::enterEvent(QEvent *e)
{
    this->raise();
    this->setStyleSheet("background-color:white");
    QPropertyAnimation *a = new QPropertyAnimation(this,"size");
    a->setDuration(300);
    a->setStartValue(this->size());
    QSize h = this->size();
    QSize h2 = QSize(parentWidget()->size().width(), h.height());
    a->setEndValue(h2);
    a->setEasingCurve(QEasingCurve::InOutCubic);
    a->start();
    QPushButton::enterEvent(e);
}

void AnimatedtButton::leaveEvent(QEvent *e)
{
    QPropertyAnimation *a = new QPropertyAnimation(this,"size");
    connect(a,SIGNAL(finished()),((AnimatedtButton *)this),SLOT(resetStyle()));
    a->setDuration(300);
    a->setStartValue(this->size());
    QSize h2 = QSize(85, 50);
    a->setEndValue(h2);
    a->setEasingCurve(QEasingCurve::InOutCubic);
    a->start(QPropertyAnimation::DeleteWhenStopped);
    emit backExit();
    QPushButton::leaveEvent(e);
}

void AnimatedtButton::resetStyle()
{
    this->setStyleSheet("background-color: rbga(255, 255, 255, 0); color:rgba(0,0,0,0);");
}


