mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-24 23:08:07 -05:00
Use QPropertyAnimation::DeleteWhenStopped PulseWidget() when once is set
Also fixes potential crash when waiting for single shot timer when looping and widget and animations are deleted in the meantime
This commit is contained in:
parent
4253c99cf2
commit
6fb8297275
|
|
@ -883,36 +883,39 @@ bool windowPosValid(QPoint pos)
|
|||
QMetaObject::Connection PulseWidget(QWidget *widget, QColor startColor,
|
||||
QColor endColor, bool once)
|
||||
{
|
||||
QGraphicsColorizeEffect *eEffect = new QGraphicsColorizeEffect(widget);
|
||||
widget->setGraphicsEffect(eEffect);
|
||||
QPropertyAnimation *paAnimation =
|
||||
new QPropertyAnimation(eEffect, "color");
|
||||
paAnimation->setStartValue(startColor);
|
||||
paAnimation->setEndValue(endColor);
|
||||
paAnimation->setDuration(1000);
|
||||
QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect(widget);
|
||||
widget->setGraphicsEffect(effect);
|
||||
QPropertyAnimation *animation =
|
||||
new QPropertyAnimation(effect, "color", widget);
|
||||
animation->setStartValue(startColor);
|
||||
animation->setEndValue(endColor);
|
||||
animation->setDuration(1000);
|
||||
|
||||
QMetaObject::Connection con;
|
||||
if (once) {
|
||||
auto widgetPtr = widget;
|
||||
con = QWidget::connect(
|
||||
paAnimation, &QPropertyAnimation::finished,
|
||||
animation, &QPropertyAnimation::finished,
|
||||
[widgetPtr]() {
|
||||
if (widgetPtr) {
|
||||
widgetPtr->setGraphicsEffect(nullptr);
|
||||
}
|
||||
});
|
||||
animation->start(QPropertyAnimation::DeleteWhenStopped);
|
||||
} else {
|
||||
auto widgetPtr = widget;
|
||||
con = QWidget::connect(
|
||||
paAnimation, &QPropertyAnimation::finished,
|
||||
[paAnimation]() {
|
||||
QTimer::singleShot(1000, [paAnimation] {
|
||||
paAnimation->start();
|
||||
});
|
||||
animation, &QPropertyAnimation::finished,
|
||||
[animation, widgetPtr]() {
|
||||
QTimer *timer = new QTimer(widgetPtr);
|
||||
QWidget::connect(timer, &QTimer::timeout,
|
||||
[animation] {
|
||||
animation->start();
|
||||
});
|
||||
timer->start(1000);
|
||||
});
|
||||
animation->start();
|
||||
}
|
||||
|
||||
paAnimation->start();
|
||||
|
||||
return con;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user