create a simple context menu

It will have to use containment action plugins
This commit is contained in:
Marco Martin 2013-02-15 14:01:53 +01:00
parent 44699e7e0d
commit 4049c092be
2 changed files with 31 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include <QQmlProperty>
#include <KDebug>
#include <KMenu>
#include <Plasma/Corona>
#include <Plasma/Package>
@ -36,6 +37,9 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
: AppletInterface(parent),
m_wallpaperQmlObject(0)
{
//TODO: will accept all events specified as registered with containment actions
setAcceptedMouseButtons(Qt::RightButton);
qmlRegisterType<ContainmentInterface>();
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *)));
@ -197,4 +201,27 @@ QString ContainmentInterface::activityId() const
return containment()->activity();
}
void ContainmentInterface::mousePressEvent(QMouseEvent *event)
{
event->accept();
}
void ContainmentInterface::mouseReleaseEvent(QMouseEvent *event)
{
KMenu desktopMenu;
desktopMenu.addAction("Menu Item 1");
desktopMenu.addAction("Menu Item 2");
foreach (QAction *action, applet()->contextualActions()) {
if (action) {
desktopMenu.addAction(action);
}
}
desktopMenu.exec(event->globalPos());
event->accept();
}
#include "moc_containmentinterface.cpp"

View File

@ -63,6 +63,10 @@ public:
Q_INVOKABLE QRectF screenGeometry(int id) const;
Q_INVOKABLE QVariantList availableScreenRegion(int id) const;
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
Q_SIGNALS:
void appletAdded(QObject *applet, const QPointF &pos);
void appletRemoved(QObject *applet);