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 <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-21 14:19:45 +03:00
parent 46f5e8cbc2
commit 11e1a73adb
2 changed files with 46 additions and 28 deletions

View file

@ -164,6 +164,11 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
{ {
Plasma::FormFactor f = q->formFactor(); 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 || if (constraints & Plasma::FormFactorConstraint ||
constraints & Plasma::StartupCompletedConstraint || constraints & Plasma::StartupCompletedConstraint ||
(constraints & Plasma::SizeConstraint && (constraints & Plasma::SizeConstraint &&
@ -322,11 +327,13 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
//kDebug() << "about to switch to a popup"; //kDebug() << "about to switch to a popup";
if (!qWidget && !gWidget) { if (!qWidget && !gWidget) {
delete dialogPtr.data(); delete dialogPtr.data();
maybeStartAnimation();
return; return;
} }
//there was already a dialog? don't make the switch again //there was already a dialog? don't make the switch again
if (dialogPtr) { if (dialogPtr) {
maybeStartAnimation();
return; return;
} }
@ -398,6 +405,8 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
// the size changings // the size changings
emit q->sizeHintChanged(Qt::PreferredSize); emit q->sizeHintChanged(Qt::PreferredSize);
} }
maybeStartAnimation();
} }
void PopupAppletPrivate::appletActivated() void PopupAppletPrivate::appletActivated()
@ -530,16 +539,6 @@ void PopupApplet::timerEvent(QTimerEvent *event)
} else if (event->timerId() == d->showDialogTimer.timerId()) { } else if (event->timerId() == d->showDialogTimer.timerId()) {
d->showDialogTimer.stop(); d->showDialogTimer.stop();
d->showDialog(); 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 { } else {
Applet::timerEvent(event); Applet::timerEvent(event);
} }
@ -605,16 +604,16 @@ bool PopupApplet::isIconified() const
} }
PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet) PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
: q(applet), : q(applet),
icon(nullptr), icon(nullptr),
widget(nullptr), widget(nullptr),
popupPlacement(Plasma::FloatingPopup), popupPlacement(Plasma::FloatingPopup),
popupAlignment(Qt::AlignLeft), popupAlignment(Qt::AlignLeft),
savedAspectRatio(Plasma::InvalidAspectRatioMode), savedAspectRatio(Plasma::InvalidAspectRatioMode),
autohideTimer(nullptr), autohideTimer(nullptr),
statusTick(0), statusAnimation(nullptr),
popupLostFocus(false), popupLostFocus(false),
passive(false) passive(false)
{ {
int iconSize = IconSize(KIconLoader::Desktop); int iconSize = IconSize(KIconLoader::Desktop);
q->resize(iconSize, iconSize); q->resize(iconSize, iconSize);
@ -759,11 +758,18 @@ void PopupAppletPrivate::dialogStatusChanged(bool shown)
void PopupAppletPrivate::statusChange(Plasma::ItemStatus status) void PopupAppletPrivate::statusChange(Plasma::ItemStatus status)
{ {
if (status == Plasma::ItemStatus::NeedsAttentionStatus) { if (status == Plasma::ItemStatus::NeedsAttentionStatus) {
statusTimer.start(500, q); if (icon && !statusAnimation) {
} else { statusAnimation = Animator::create(Animator::PulseAnimation, q);
statusTimer.stop(); statusAnimation->setTargetWidget(icon);
statusAnimation->setDuration(1000);
statusAnimation->setLoopCount(-1);
}
if (icon) { if (icon) {
icon->setPressed(false); statusAnimation->start(QAbstractAnimation::KeepWhenStopped);
}
} else {
if (statusAnimation) {
statusAnimation->stop();
} }
} }
} }
@ -786,6 +792,17 @@ void PopupAppletPrivate::createIconWidget()
q->setLayout(layout); 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() void PopupAppletPrivate::restoreDialogSize()
{ {
Plasma::Dialog *dialog = dialogPtr.data(); Plasma::Dialog *dialog = dialogPtr.data();

View file

@ -22,9 +22,11 @@
#include <QTimer> #include <QTimer>
#include <QBasicTimer> #include <QBasicTimer>
#include <QtCore/qsharedpointer.h> #include <QWeakPointer>
#include <QTimeLine>
#include <plasma/plasma.h> #include <plasma/plasma.h>
#include <plasma/animations/animation.h>
namespace Plasma namespace Plasma
{ {
@ -49,7 +51,7 @@ public:
void appletActivated(); void appletActivated();
void statusChange(Plasma::ItemStatus status); void statusChange(Plasma::ItemStatus status);
void createIconWidget(); void createIconWidget();
void maybeStartAnimation();
PopupApplet *q; PopupApplet *q;
Plasma::IconWidget *icon; Plasma::IconWidget *icon;
@ -63,8 +65,7 @@ public:
QTimer *autohideTimer; QTimer *autohideTimer;
QBasicTimer delayedShowTimer; QBasicTimer delayedShowTimer;
QBasicTimer showDialogTimer; QBasicTimer showDialogTimer;
QBasicTimer statusTimer; Plasma::Animation* statusAnimation;
int statusTick;
QPoint clicked; QPoint clicked;
bool popupLostFocus; bool popupLostFocus;
bool passive; bool passive;