diff --git a/plasma/popupapplet.cpp b/plasma/popupapplet.cpp index 0a57ac3c..15ffb35f 100644 --- a/plasma/popupapplet.cpp +++ b/plasma/popupapplet.cpp @@ -604,6 +604,16 @@ 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); } @@ -670,13 +680,13 @@ bool PopupApplet::isIconified() const PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet) : q(applet), - icon(0), - widget(0), + icon(nullptr), + widget(nullptr), popupPlacement(Plasma::FloatingPopup), popupAlignment(Qt::AlignLeft), savedAspectRatio(Plasma::InvalidAspectRatioMode), - autohideTimer(0), - preShowStatus(UnknownStatus), + autohideTimer(nullptr), + statusTick(0), popupLostFocus(false), passive(false) { @@ -685,6 +695,7 @@ PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet) q->setAcceptDrops(true); QObject::disconnect(q, SIGNAL(activate()), static_cast(q), SLOT(setFocus())); QObject::connect(q, SIGNAL(activate()), q, SLOT(appletActivated())); + QObject::connect(q, SIGNAL(newStatus(Plasma::ItemStatus)), q, SLOT(statusChange(Plasma::ItemStatus))); QObject::connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), q, SLOT(iconSizeChanged(int))); } @@ -820,24 +831,27 @@ void PopupAppletPrivate::dialogSizeChanged() void PopupAppletPrivate::dialogStatusChanged(bool shown) { + q->setStatus(q->status()); if (shown) { - preShowStatus = q->status(); - q->setStatus(NeedsAttentionStatus); - QObject::connect(q, SIGNAL(newStatus(Plasma::ItemStatus)), - q, SLOT(statusChangeWhileShown(Plasma::ItemStatus)), - Qt::UniqueConnection); + // the dialog is getting attention + statusChange(Plasma::ItemStatus::UnknownStatus); } else { - QObject::disconnect(q, SIGNAL(newStatus(Plasma::ItemStatus)), - q, SLOT(statusChangeWhileShown(Plasma::ItemStatus))); - q->setStatus(preShowStatus); + // back to needs attention, maybe + statusChange(q->status()); } - q->popupEvent(shown); } -void PopupAppletPrivate::statusChangeWhileShown(Plasma::ItemStatus status) +void PopupAppletPrivate::statusChange(Plasma::ItemStatus status) { - preShowStatus = status; + if (status == Plasma::ItemStatus::NeedsAttentionStatus) { + statusTimer.start(500, q); + } else { + statusTimer.stop(); + if (icon) { + icon->setPressed(false); + } + } } void PopupAppletPrivate::createIconWidget() diff --git a/plasma/popupapplet.h b/plasma/popupapplet.h index b80e5043..07fc4e06 100644 --- a/plasma/popupapplet.h +++ b/plasma/popupapplet.h @@ -219,7 +219,7 @@ private: Q_PRIVATE_SLOT(d, void updateDialogPosition()) Q_PRIVATE_SLOT(d, void appletActivated()) Q_PRIVATE_SLOT(d, void iconSizeChanged(int)) - Q_PRIVATE_SLOT(d, void statusChangeWhileShown(Plasma::ItemStatus status)) + Q_PRIVATE_SLOT(d, void statusChange(Plasma::ItemStatus status)) friend class Applet; friend class AppletPrivate; diff --git a/plasma/private/popupapplet_p.h b/plasma/private/popupapplet_p.h index 6f578d80..8ef02bb2 100644 --- a/plasma/private/popupapplet_p.h +++ b/plasma/private/popupapplet_p.h @@ -48,7 +48,7 @@ public: void checkExtenderAppearance(Plasma::FormFactor f); KConfigGroup popupConfigGroup(); void appletActivated(); - void statusChangeWhileShown(Plasma::ItemStatus status); + void statusChange(Plasma::ItemStatus status); void createIconWidget(); @@ -64,10 +64,11 @@ public: QTimer *autohideTimer; QBasicTimer delayedShowTimer; QBasicTimer showDialogTimer; + QBasicTimer statusTimer; + int statusTick; QPoint clicked; - ItemStatus preShowStatus; - bool popupLostFocus : 1; - bool passive : 1; + bool popupLostFocus; + bool passive; }; } // Plasma namespace diff --git a/plasma/widgets/iconwidget.cpp b/plasma/widgets/iconwidget.cpp index aa12e069..a10ad8fa 100644 --- a/plasma/widgets/iconwidget.cpp +++ b/plasma/widgets/iconwidget.cpp @@ -339,7 +339,7 @@ IconWidget::IconWidget(QGraphicsItem *parent) IconWidget::IconWidget(const QString &text, QGraphicsItem *parent) : QGraphicsWidget(parent), - d(new IconWidgetPrivate(this)) + d(new IconWidgetPrivate(this)) { d->init(); setText(text); @@ -557,12 +557,12 @@ QSizeF IconWidgetPrivate::iconSizeForWidgetSize(const QStyleOptionGraphicsItem * { setActiveMargins(); - //calculate icon size based on the available space - qreal iconWidth; + // calculate icon size based on the available space + qreal iconWidth = 0.0; if (orientation == Qt::Vertical) { qreal heightAvail; - //if there is text resize the icon in order to make room for the text + // if there is text resize the icon in order to make room for the text if (text.isEmpty() && infoText.isEmpty()) { heightAvail = rect.height(); } else { @@ -1527,7 +1527,7 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const { d->setActiveMargins(); if (d->text.isEmpty() && d->infoText.isEmpty()) { - //no text, just the icon size + // no text, just the icon size return d->addMargin(QSizeF(iconWidth, iconWidth), IconWidgetPrivate::ItemMargin); } @@ -1553,15 +1553,12 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const d->horizontalMargin[IconWidgetPrivate::TextMargin].left + d->horizontalMargin[IconWidgetPrivate::TextMargin].right; } - - qreal height; - qreal textHeight; - QStyleOptionGraphicsItem option; option.state = QStyle::State_None; option.rect = QRect(0, 0, width, QWIDGETSIZE_MAX); - textHeight = d->displaySizeHint(&option, width).height(); + qreal textHeight = d->displaySizeHint(&option, width).height(); + qreal height = 0.0; if (d->orientation == Qt::Vertical) { height = iconWidth + textHeight + d->verticalMargin[IconWidgetPrivate::TextMargin].top + diff --git a/plasma/widgets/iconwidget_p.h b/plasma/widgets/iconwidget_p.h index 06d704b1..7ce97c1e 100644 --- a/plasma/widgets/iconwidget_p.h +++ b/plasma/widgets/iconwidget_p.h @@ -294,8 +294,11 @@ Qt::LayoutDirection IconWidgetPrivate::iconDirection(const QStyleOptionGraphicsI void IconWidgetPrivate::setActiveMargins() { - //sync here itemmargin with contentsrect, not overly pretty but it's where it's more reliable - qreal left, top, right, bottom; + // sync here item margin with contents rect, not overly pretty but it's where it's more reliable + qreal left = 0.0; + qreal top = 0.0; + qreal right = 0.0; + qreal bottom = 0.0; q->getContentsMargins(&left, &top, &right, &bottom); if (left || top || right || bottom) { verticalMargin[ItemMargin].left = horizontalMargin[ItemMargin].left = left;