diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index e5f7985b9..db73860ad 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include "containmentinterface.h" #include @@ -85,6 +86,15 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant connect(applet()->containment(), &Plasma::Containment::screenChanged, this, &ContainmentInterface::screenChanged); } + + connect(this, &AppletInterface::expandedChanged, [=](bool expanded) { + //FIXME: this is obviously wrong: the filter should be installed when the + //applet goes popup and removed when it goes normal, + //this is a not really working heuristic + if (fullRepresentationItem() && fullRepresentationItem()->parentItem()) { + fullRepresentationItem()->parentItem()->installEventFilter(this); + } + }); } AppletInterface::AppletInterface(Plasma::Applet *a, const QVariantList &args, QQuickItem *parent) @@ -523,4 +533,35 @@ void AppletInterface::executeAction(const QString &name) } } +bool AppletInterface::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonPress) { + //pass it up to the applet + //well, actually we have to pass it to the *containment* + //because all the code for showing an applet's contextmenu is actually in Containment. + Plasma::Containment *c = applet()->containment(); + if (c) { + const QString trigger = Plasma::ContainmentActions::eventToString(event); + Plasma::ContainmentActions *plugin = c->containmentActions().value(trigger); + if (!plugin) { + return false; + } + ContainmentInterface *ci = c->property("_plasma_graphicObject").value(); + + QMenu desktopMenu; + ci->addAppletActions(desktopMenu, applet(), event); + + if (!desktopMenu.isEmpty()) { + desktopMenu.exec(static_cast(event)->globalPos()); + return true; + } + + return false; + } + } + + return AppletQuickItem::eventFilter(watched, event); +} + + #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 547474b19..d174a73da 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -334,6 +334,9 @@ Q_SIGNALS: protected Q_SLOTS: virtual void init(); +protected: + bool eventFilter(QObject *watched, QEvent *event); + private: QStringList m_actions; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 755bab919..4860b0659 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -656,12 +656,14 @@ QList ContainmentInterface::actions() const //PROTECTED-------------------- -void ContainmentInterface::mousePressEvent(QMouseEvent *event) +void ContainmentInterface::mouseReleaseEvent(QMouseEvent *event) { - event->setAccepted(m_containment->containmentActions().contains(Plasma::ContainmentActions::eventToString(event))); + //event->setAccepted(m_containment->containmentActions().contains(Plasma::ContainmentActions::eventToString(event))); + event->setAccepted(false); } -void ContainmentInterface::mouseReleaseEvent(QMouseEvent *event) +void ContainmentInterface::mousePressEvent(QMouseEvent *event) + { //even if the menu is executed synchronously, other events may be processed //by the qml incubator when plasma is loading, so we need to guard there @@ -721,7 +723,7 @@ void ContainmentInterface::mouseReleaseEvent(QMouseEvent *event) //end workaround desktopMenu.exec(event->globalPos()); - event->accept(); + event->setAccepted(false); } void ContainmentInterface::wheelEvent(QWheelEvent *event) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.h b/src/scriptengines/qml/plasmoid/containmentinterface.h index 50a77b271..5eebff268 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.h +++ b/src/scriptengines/qml/plasmoid/containmentinterface.h @@ -198,6 +198,7 @@ private: KActivities::Info *m_activityInfo; QPointer m_containment; QWeakPointer m_contextMenu; + friend class AppletInterface; }; QML_DECLARE_TYPEINFO(ContainmentInterface, QML_HAS_ATTACHED_PROPERTIES)