From kde-commits Fri Aug 28 22:23:16 2009 From: Chani Armitage Date: Fri, 28 Aug 2009 22:23:16 +0000 To: kde-commits Subject: KDE/kdebase/workspace/plasma/containmentactions/switchdesktop Message-Id: <1251498196.066655.28125.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=125150006206788 SVN commit 1016792 by chani: contextualActions for switchdesktop M +25 -6 desktop.cpp M +2 -0 desktop.h --- trunk/KDE/kdebase/workspace/plasma/containmentactions/switchdesktop/desktop.cpp #1016791:1016792 @@ -45,27 +45,46 @@ } } -void SwitchDesktop::contextEvent(QGraphicsSceneMouseEvent *event) +void SwitchDesktop::makeMenu(QMenu *menu) { int numDesktops = KWindowSystem::numberOfDesktops(); int currentDesktop = KWindowSystem::currentDesktop(); - KMenu desktopMenu; - desktopMenu.addTitle(i18n("Virtual Desktops")); - for (int i=1; i<=numDesktops; ++i) { QString name = KWindowSystem::desktopName(i); - QAction *action = desktopMenu.addAction(QString("%1: %2").arg(i).arg(name)); + QAction *action = menu->addAction(QString("%1: %2").arg(i).arg(name)); action->setData(i); if (i==currentDesktop) { action->setEnabled(false); } } + connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*))); +} - connect(&desktopMenu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*))); +void SwitchDesktop::contextEvent(QGraphicsSceneMouseEvent *event) +{ + KMenu desktopMenu; + + desktopMenu.addTitle(i18n("Virtual Desktops")); + makeMenu(&desktopMenu); + desktopMenu.exec(event->screenPos()); } +QList SwitchDesktop::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("Virtual Desktops")); + + list << action; + return list; +} + void SwitchDesktop::switchTo(QAction *action) { int desktop = action->data().toInt(); --- trunk/KDE/kdebase/workspace/plasma/containmentactions/switchdesktop/desktop.h #1016791:1016792 @@ -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);