#include "../headers/qmodernpushbuttonoverlay.h" QModernPushButtonOverlay::QModernPushButtonOverlay(QWidget* overlayWidget, QObject *parent) : QObject(parent) { this->widget = overlayWidget; this->widget->setVisible(false); this->effect = new QGraphicsOpacityEffect(overlayWidget); this->effect->setOpacity(0); this->effect->setEnabled(false); this->widget->setGraphicsEffect(this->effect); this->animation = new QPropertyAnimation(this->effect, "opacity"); this->animation->setDuration(400); this->animation->setEasingCurve(QEasingCurve(QEasingCurve::InOutQuad)); this->setEffectEnabled(false); connect(this->animation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this, SLOT(handleAnimationStateChanged(QAbstractAnimation::State, QAbstractAnimation::State))); } void QModernPushButtonOverlay::setAnimationDuration(int duration) { this->animation->setDuration(duration); } void QModernPushButtonOverlay::setVisible(bool visible) { if(this->widget->isVisible() == visible) return; int startValue = visible ? 0:1; this->animation->setStartValue(startValue); this->animation->setEndValue(1-startValue); this->animation->start(); } void QModernPushButtonOverlay::setEffectEnabled(bool enabled) { if(enabled) { this->effect->setEnabled(true); this->widget->setVisible(true); } else { this->widget->setVisible(this->effect->opacity() > 0); this->effect->setEnabled(false); } } void QModernPushButtonOverlay::handleAnimationStateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State) { switch (newState) { case QAbstractAnimation::Running: this->setEffectEnabled(true); break; case QAbstractAnimation::Stopped: this->setEffectEnabled(false); break; default: break; } }