From 11e1a73adb61e5c5fa859e56fddcfbd622ab2045 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 21 May 2024 14:19:45 +0300 Subject: [PATCH] plasma: use pulse animation for Plasma::ItemStatus::NeedsAttentionStatus because Plasma::IconWidget state is messed up if pressed is set manually and it is possible for it to be activated (if it accepts mouse button events). it is also fancier, especially when the icon is not very small Signed-off-by: Ivailo Monev --- plasma/popupapplet.cpp | 65 +++++++++++++++++++++------------- plasma/private/popupapplet_p.h | 9 ++--- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/plasma/popupapplet.cpp b/plasma/popupapplet.cpp index 753ceac9..04c656c4 100644 --- a/plasma/popupapplet.cpp +++ b/plasma/popupapplet.cpp @@ -164,6 +164,11 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) { Plasma::FormFactor f = q->formFactor(); + // stop the animation, its snapshot has to be updated + if (statusAnimation && constraints & Plasma::SizeConstraint) { + statusAnimation->stop(); + } + if (constraints & Plasma::FormFactorConstraint || constraints & Plasma::StartupCompletedConstraint || (constraints & Plasma::SizeConstraint && @@ -322,11 +327,13 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) //kDebug() << "about to switch to a popup"; if (!qWidget && !gWidget) { delete dialogPtr.data(); + maybeStartAnimation(); return; } //there was already a dialog? don't make the switch again if (dialogPtr) { + maybeStartAnimation(); return; } @@ -398,6 +405,8 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) // the size changings emit q->sizeHintChanged(Qt::PreferredSize); } + + maybeStartAnimation(); } void PopupAppletPrivate::appletActivated() @@ -530,16 +539,6 @@ void PopupApplet::timerEvent(QTimerEvent *event) } else if (event->timerId() == d->showDialogTimer.timerId()) { d->showDialogTimer.stop(); d->showDialog(); - } else if (event->timerId() == d->statusTimer.timerId()) { - if (d->icon) { - if (d->statusTick <= 0) { - d->statusTick++; - d->icon->setPressed(true); - } else { - d->statusTick--; - d->icon->setPressed(false); - } - } } else { Applet::timerEvent(event); } @@ -605,16 +604,16 @@ bool PopupApplet::isIconified() const } PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet) - : q(applet), - icon(nullptr), - widget(nullptr), - popupPlacement(Plasma::FloatingPopup), - popupAlignment(Qt::AlignLeft), - savedAspectRatio(Plasma::InvalidAspectRatioMode), - autohideTimer(nullptr), - statusTick(0), - popupLostFocus(false), - passive(false) + : q(applet), + icon(nullptr), + widget(nullptr), + popupPlacement(Plasma::FloatingPopup), + popupAlignment(Qt::AlignLeft), + savedAspectRatio(Plasma::InvalidAspectRatioMode), + autohideTimer(nullptr), + statusAnimation(nullptr), + popupLostFocus(false), + passive(false) { int iconSize = IconSize(KIconLoader::Desktop); q->resize(iconSize, iconSize); @@ -759,11 +758,18 @@ void PopupAppletPrivate::dialogStatusChanged(bool shown) void PopupAppletPrivate::statusChange(Plasma::ItemStatus status) { if (status == Plasma::ItemStatus::NeedsAttentionStatus) { - statusTimer.start(500, q); - } else { - statusTimer.stop(); + if (icon && !statusAnimation) { + statusAnimation = Animator::create(Animator::PulseAnimation, q); + statusAnimation->setTargetWidget(icon); + statusAnimation->setDuration(1000); + statusAnimation->setLoopCount(-1); + } if (icon) { - icon->setPressed(false); + statusAnimation->start(QAbstractAnimation::KeepWhenStopped); + } + } else { + if (statusAnimation) { + statusAnimation->stop(); } } } @@ -786,6 +792,17 @@ void PopupAppletPrivate::createIconWidget() q->setLayout(layout); } +void PopupAppletPrivate::maybeStartAnimation() +{ + if (statusAnimation && q->status() == Plasma::ItemStatus::NeedsAttentionStatus) { + // not if the dialog is visible + if (dialogPtr && dialogPtr.data()->isVisible()) { + return; + } + statusAnimation->start(QAbstractAnimation::KeepWhenStopped); + } +} + void PopupAppletPrivate::restoreDialogSize() { Plasma::Dialog *dialog = dialogPtr.data(); diff --git a/plasma/private/popupapplet_p.h b/plasma/private/popupapplet_p.h index ddf33f0a..afb567d5 100644 --- a/plasma/private/popupapplet_p.h +++ b/plasma/private/popupapplet_p.h @@ -22,9 +22,11 @@ #include #include -#include +#include +#include #include +#include namespace Plasma { @@ -49,7 +51,7 @@ public: void appletActivated(); void statusChange(Plasma::ItemStatus status); void createIconWidget(); - + void maybeStartAnimation(); PopupApplet *q; Plasma::IconWidget *icon; @@ -63,8 +65,7 @@ public: QTimer *autohideTimer; QBasicTimer delayedShowTimer; QBasicTimer showDialogTimer; - QBasicTimer statusTimer; - int statusTick; + Plasma::Animation* statusAnimation; QPoint clicked; bool popupLostFocus; bool passive;