we do actually still want context menus on applets, even with the hover thing.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738430
This commit is contained in:
Aaron J. Seigo 2007-11-18 22:02:01 +00:00
parent c9ce91e944
commit 5b4dbbe303
2 changed files with 38 additions and 7 deletions

View File

@ -1189,12 +1189,14 @@ void Applet::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
//kDebug() << "context menu event!"; //kDebug() << "context menu event!";
if (!scene()) { if (!scene()) {
//kDebug() << "no scene?!";
return; return;
} }
Applet* containment = dynamic_cast<Plasma::Applet*>(topLevelItem()); Applet* containment = dynamic_cast<Plasma::Applet*>(topLevelItem());
if (!containment) { if (!containment) {
//kDebug() << "no containment. hm.";
Widget::contextMenuEvent(event); Widget::contextMenuEvent(event);
return; return;
} }
@ -1202,7 +1204,6 @@ void Applet::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
// we want to pass up the context menu event to the Containment at // we want to pass up the context menu event to the Containment at
// this point // this point
containment->contextMenuEvent(event); containment->contextMenuEvent(event);
return;
} }
} // Plasma namespace } // Plasma namespace

View File

@ -163,7 +163,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
} }
KMenu desktopMenu; KMenu desktopMenu;
//kDebug() << "context menu event " << immutable; //kDebug() << "context menu event " << (QObject*)applet;
if (!applet) { if (!applet) {
if (!scene() || static_cast<Corona*>(scene())->isImmutable()) { if (!scene() || static_cast<Corona*>(scene())->isImmutable()) {
//kDebug() << "immutability"; //kDebug() << "immutability";
@ -185,9 +185,40 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
desktopMenu.addAction(action); desktopMenu.addAction(action);
} }
} else { } else {
//kDebug() << "immutable applet"; bool hasEntries = false;
QGraphicsItem::contextMenuEvent(event); if (applet->hasConfigurationInterface()) {
return; QAction* configureApplet = new QAction(i18n("%1 Settings...", applet->name()), &desktopMenu);
connect(configureApplet, SIGNAL(triggered(bool)),
applet, SLOT(showConfigurationInterface()));
desktopMenu.addAction(configureApplet);
hasEntries = true;
}
if (scene() && !static_cast<Corona*>(scene())->isImmutable()) {
QAction* closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
QVariant appletV;
appletV.setValue((QObject*)applet);
closeApplet->setData(appletV);
connect(closeApplet, SIGNAL(triggered(bool)),
this, SLOT(destroyApplet()));
desktopMenu.addAction(closeApplet);
hasEntries = true;
}
QList<QAction*> actions = applet->contextActions();
if (!actions.isEmpty()) {
desktopMenu.addSeparator();
foreach(QAction* action, actions) {
desktopMenu.addAction(action);
}
hasEntries = true;
}
if (!hasEntries) {
QGraphicsItem::contextMenuEvent(event);
kDebug() << "no entries";
return;
}
} }
event->accept(); event->accept();
@ -529,8 +560,7 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
switch (event->type()) { switch (event->type()) {
case QEvent::GraphicsSceneHoverEnter: case QEvent::GraphicsSceneHoverEnter:
if (!d->immutable && !applet->isImmutable() if (!d->immutable && !applet->isImmutable() && !d->handles.contains(applet)) {
&& !d->handles.contains(applet)) {
AppletHandle *handle = new AppletHandle(this, applet); AppletHandle *handle = new AppletHandle(this, applet);
d->handles[applet] = handle; d->handles[applet] = handle;
connect(handle, SIGNAL(disappearDone(AppletHandle*)), connect(handle, SIGNAL(disappearDone(AppletHandle*)),