From 4c6707dbed37b1e1ba845f1dc190f2c324e1e071 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 13 May 2016 17:52:52 +0200 Subject: [PATCH] Alternatives: Add new applet only after the old one was removed New applet is now added at the same position as the old one. CCBUG: 358827 Differential Revision: https://phabricator.kde.org/D1134 --- shell/alternativeshelper.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/shell/alternativeshelper.cpp b/shell/alternativeshelper.cpp index 94af47321..a96b2664a 100644 --- a/shell/alternativeshelper.cpp +++ b/shell/alternativeshelper.cpp @@ -68,19 +68,22 @@ void AlternativesHelper::loadAlternative(const QString &plugin) return; } - Plasma::Applet *newApplet = Q_NULLPTR; - //TODO: map the position to containment coordinates - QMetaObject::invokeMethod(contItem, "createApplet", Q_RETURN_ARG(Plasma::Applet *, newApplet), Q_ARG(QString, plugin), Q_ARG(QVariantList, QVariantList()), Q_ARG(QPoint, appletItem->mapToItem(contItem, QPointF(0,0)).toPoint())); - // ensure the global shortcut is moved to the new applet const QKeySequence &shortcut = m_applet->globalShortcut(); m_applet->setGlobalShortcut(QKeySequence()); // need to unmap the old one first - if (newApplet) { - newApplet->setGlobalShortcut(shortcut); - } + const QPoint newPos = appletItem->mapToItem(contItem, QPointF(0,0)).toPoint(); m_applet->destroy(); + + connect(m_applet, &QObject::destroyed, [=]() { + Plasma::Applet *newApplet = Q_NULLPTR; + QMetaObject::invokeMethod(contItem, "createApplet", Q_RETURN_ARG(Plasma::Applet *, newApplet), Q_ARG(QString, plugin), Q_ARG(QVariantList, QVariantList()), Q_ARG(QPoint, newPos)); + + if (newApplet) { + newApplet->setGlobalShortcut(shortcut); + } + }); } #include "moc_alternativeshelper.cpp"