#include "AnimationResizeWidget.h"
#include <QtCore/QEventLoop>
AnimationResizeWidget::AnimationResizeWidget(QWidget *parent) {
setAttribute(Qt::WA_StyledBackground);
m_pAnimation = new QPropertyAnimation(this);
m_pAnimation->setEasingCurve(QEasingCurve::Linear);
m_pAnimation->setTargetObject(this);
m_pAnimation->setPropertyName("animSize");
connect(m_pAnimation, &QPropertyAnimation::valueChanged, [this](){
emit animSizeChanged();
});
setDuration(200);
}
AnimationResizeWidget::~AnimationResizeWidget() {
delete m_pAnimation;
}
void AnimationResizeWidget::setDuration(int msecs) {
m_pAnimation->setDuration(msecs);
}
const int AnimationResizeWidget::duration() const {
return m_pAnimation->duration();
}
QSize AnimationResizeWidget::animSize() const {
return size();
}
void AnimationResizeWidget::setAnimSize(QSize size) {
setFixedSize(size);
}
void AnimationResizeWidget::setStartSize(const QSize &size) {
m_pAnimation->setStartValue(size);
}
QSize AnimationResizeWidget::startSize() const {
return m_pAnimation->startValue().toSize();
}
void AnimationResizeWidget::setEndSize(const QSize &size) {
m_pAnimation->setEndValue(size);
}
QSize AnimationResizeWidget::endSize() const {
return m_pAnimation->endValue().toSize();
}
void AnimationResizeWidget::run() {
if(m_pAnimation->startValue() == m_pAnimation->endValue())
return;
QEventLoop loop;
connect(m_pAnimation, &QAbstractAnimation::finished, [&](){
loop.quit();
});
emit animStarted();
m_pAnimation->start();
loop.exec();
m_pAnimation->disconnect(m_pAnimation, &QAbstractAnimation::finished, nullptr, nullptr);
emit animFinished();
}