This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
modern-linbo-gui/sources/qmodernpushbuttonoverlay.cpp
Dorian Zedler c01d1b884d
- added some fancy animations to the start action buttons
- Made everything depend on the LinboBackend state
2020-11-23 11:57:51 +01:00

60 lines
1.9 KiB
C++

#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;
}
}