port plasma1 popupapplet event filter logic
use an event filter to open popup menus inside popups. requires a recent 5.3 revision and a small change in the shell package
This commit is contained in:
parent
120132879a
commit
1baddcc004
@ -44,6 +44,7 @@
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Package>
|
||||
#include <Plasma/PluginLoader>
|
||||
#include <Plasma/ContainmentActions>
|
||||
|
||||
#include "containmentinterface.h"
|
||||
#include <kdeclarative/configpropertymap.h>
|
||||
@ -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<ContainmentInterface *>();
|
||||
|
||||
QMenu desktopMenu;
|
||||
ci->addAppletActions(desktopMenu, applet(), event);
|
||||
|
||||
if (!desktopMenu.isEmpty()) {
|
||||
desktopMenu.exec(static_cast<QMouseEvent*>(event)->globalPos());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return AppletQuickItem::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
|
||||
#include "moc_appletinterface.cpp"
|
||||
|
@ -334,6 +334,9 @@ Q_SIGNALS:
|
||||
protected Q_SLOTS:
|
||||
virtual void init();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
QStringList m_actions;
|
||||
|
@ -656,12 +656,14 @@ QList<QObject *> 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)
|
||||
|
@ -198,6 +198,7 @@ private:
|
||||
KActivities::Info *m_activityInfo;
|
||||
QPointer<Plasma::Containment> m_containment;
|
||||
QWeakPointer<QMenu> m_contextMenu;
|
||||
friend class AppletInterface;
|
||||
};
|
||||
|
||||
QML_DECLARE_TYPEINFO(ContainmentInterface, QML_HAS_ATTACHED_PROPERTIES)
|
||||
|
Loading…
Reference in New Issue
Block a user