SVN commit 1016791 by chani: contextualActions for switchactivity M +25 -7 switch.cpp M +2 -0 switch.h --- trunk/KDE/kdebase/workspace/plasma/containmentactions/switchactivity/switch.cpp #1016790:1016791 @@ -49,7 +49,7 @@ } } -void SwitchActivity::contextEvent(QGraphicsSceneMouseEvent *event) +void SwitchActivity::makeMenu(QMenu *menu) { Plasma::Containment *myCtmt = containment(); if (!myCtmt) { @@ -60,10 +60,6 @@ return; } - KMenu desktopMenu; - - desktopMenu.addTitle(i18n("Activities")); - QList containments = c->containments(); foreach (Plasma::Containment *ctmt, containments) { if (ctmt->containmentType() == Plasma::Containment::PanelContainment || @@ -76,7 +72,7 @@ if (name.isEmpty()) { name = ctmt->name(); } - QAction *action = desktopMenu.addAction(name); + QAction *action = menu->addAction(name); action->setData(QVariant::fromValue >(QPointer(ctmt))); //WARNING this assumes the plugin will only ever be set on activities, not panels! @@ -84,11 +80,33 @@ action->setEnabled(false); } } + connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*))); +} - connect(&desktopMenu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*))); +void SwitchActivity::contextEvent(QGraphicsSceneMouseEvent *event) +{ + KMenu desktopMenu; + + desktopMenu.addTitle(i18n("Activities")); + makeMenu(&desktopMenu); + desktopMenu.exec(event->screenPos()); } +QList SwitchActivity::contextualActions() +{ + QList list; + QMenu *menu = new QMenu(); + + makeMenu(menu); + QAction *action = new QAction(this); //FIXME I hope this doesn't leak + action->setMenu(menu); + menu->setTitle(i18n("Activities")); + + list << action; + return list; +} + void SwitchActivity::switchTo(QAction *action) { QPointer ctmt = action->data().value >(); --- trunk/KDE/kdebase/workspace/plasma/containmentactions/switchactivity/switch.h #1016790:1016791 @@ -33,6 +33,8 @@ void contextEvent(QEvent *event); void contextEvent(QGraphicsSceneMouseEvent *event); void wheelEvent(QGraphicsSceneWheelEvent *event); + QList contextualActions(); + void makeMenu(QMenu *menu); public slots: void switchTo(QAction *action);