make is possible to ask for the containment's own context menu
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=857605
This commit is contained in:
parent
cd4565ce3d
commit
99e664d0c5
@ -405,6 +405,11 @@ void Containment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Containment::showContextMenu(const QPointF &containmentPos, const QPoint &screenPos)
|
||||||
|
{
|
||||||
|
d->showContextMenu(mapToScene(containmentPos), screenPos, false);
|
||||||
|
}
|
||||||
|
|
||||||
void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
//kDebug() << "let's see if we manage to get a context menu here, huh";
|
//kDebug() << "let's see if we manage to get a context menu here, huh";
|
||||||
@ -413,14 +418,22 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF point = event->scenePos();
|
if (!d->showContextMenu(event->scenePos(), event->screenPos(), true)) {
|
||||||
QGraphicsItem* item = scene()->itemAt(point);
|
Applet::contextMenuEvent(event);
|
||||||
if (item == this) {
|
} else {
|
||||||
item = 0;
|
event->accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ContainmentPrivate::showContextMenu(const QPointF &point, const QPoint &screenPos, bool includeApplet)
|
||||||
|
{
|
||||||
Applet* applet = 0;
|
Applet* applet = 0;
|
||||||
|
|
||||||
|
QGraphicsItem* item = q->scene()->itemAt(point);
|
||||||
|
if (item == q) {
|
||||||
|
item = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (item) {
|
while (item) {
|
||||||
applet = qgraphicsitem_cast<Applet*>(item);
|
applet = qgraphicsitem_cast<Applet*>(item);
|
||||||
if (applet && !applet->isContainment()) {
|
if (applet && !applet->isContainment()) {
|
||||||
@ -436,8 +449,10 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
//kDebug() << "context menu event " << (QObject*)applet;
|
//kDebug() << "context menu event " << (QObject*)applet;
|
||||||
if (applet) {
|
if (applet) {
|
||||||
bool hasEntries = false;
|
bool hasEntries = false;
|
||||||
|
QList<QAction*> actions;
|
||||||
|
|
||||||
QList<QAction*> actions = applet->contextualActions();
|
if (includeApplet) {
|
||||||
|
actions = applet->contextualActions();
|
||||||
if (!actions.isEmpty()) {
|
if (!actions.isEmpty()) {
|
||||||
foreach(QAction* action, actions) {
|
foreach(QAction* action, actions) {
|
||||||
if (action) {
|
if (action) {
|
||||||
@ -446,6 +461,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
}
|
}
|
||||||
hasEntries = true;
|
hasEntries = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (applet->hasConfigurationInterface()) {
|
if (applet->hasConfigurationInterface()) {
|
||||||
QAction* configureApplet = applet->d->actions.action("configure");
|
QAction* configureApplet = applet->d->actions.action("configure");
|
||||||
@ -455,7 +471,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> containmentActions = contextualActions();
|
QList<QAction*> containmentActions = q->contextualActions();
|
||||||
if (!containmentActions.isEmpty()) {
|
if (!containmentActions.isEmpty()) {
|
||||||
if (hasEntries) {
|
if (hasEntries) {
|
||||||
desktopMenu.addSeparator();
|
desktopMenu.addSeparator();
|
||||||
@ -465,7 +481,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
QMenu *containmentActionMenu = &desktopMenu;
|
QMenu *containmentActionMenu = &desktopMenu;
|
||||||
|
|
||||||
if (!actions.isEmpty() && containmentActions.count() > 2) {
|
if (!actions.isEmpty() && containmentActions.count() > 2) {
|
||||||
containmentActionMenu = new KMenu(i18n("%1 Options", name()), &desktopMenu);
|
containmentActionMenu = new KMenu(i18n("%1 Options", q->name()), &desktopMenu);
|
||||||
desktopMenu.addMenu(containmentActionMenu);
|
desktopMenu.addMenu(containmentActionMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +492,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scene() && static_cast<Corona*>(scene())->immutability() == Mutable) {
|
if (static_cast<Corona*>(q->scene())->immutability() == Mutable) {
|
||||||
if (hasEntries) {
|
if (hasEntries) {
|
||||||
desktopMenu.addSeparator();
|
desktopMenu.addSeparator();
|
||||||
}
|
}
|
||||||
@ -486,30 +502,28 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
kDebug() << "no remove action!!!!!!!!";
|
kDebug() << "no remove action!!!!!!!!";
|
||||||
closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
|
closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
|
||||||
closeApplet->setIcon(KIcon("edit-delete"));
|
closeApplet->setIcon(KIcon("edit-delete"));
|
||||||
connect(closeApplet, SIGNAL(triggered(bool)), applet, SLOT(destroy()));
|
QObject::connect(closeApplet, SIGNAL(triggered(bool)), applet, SLOT(destroy()));
|
||||||
}
|
}
|
||||||
desktopMenu.addAction(closeApplet);
|
desktopMenu.addAction(closeApplet);
|
||||||
hasEntries = true;
|
hasEntries = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasEntries) {
|
if (!hasEntries) {
|
||||||
Applet::contextMenuEvent(event);
|
|
||||||
kDebug() << "no entries";
|
kDebug() << "no entries";
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!scene() || (static_cast<Corona*>(scene())->immutability() != Mutable && !KAuthorized::authorizeKAction("unlock_desktop"))) {
|
if (static_cast<Corona*>(q->scene())->immutability() != Mutable &&
|
||||||
|
!KAuthorized::authorizeKAction("unlock_desktop")) {
|
||||||
//kDebug() << "immutability";
|
//kDebug() << "immutability";
|
||||||
Applet::contextMenuEvent(event);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> actions = contextualActions();
|
QList<QAction*> actions = q->contextualActions();
|
||||||
|
|
||||||
if (actions.count() < 1) {
|
if (actions.count() < 1) {
|
||||||
//kDebug() << "no applet, but no actions";
|
//kDebug() << "no applet, but no actions";
|
||||||
Applet::contextMenuEvent(event);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QAction* action, actions) {
|
foreach (QAction* action, actions) {
|
||||||
@ -519,9 +533,9 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
//kDebug() << "executing at" << screenPos;
|
||||||
//kDebug() << "executing at" << event->screenPos();
|
desktopMenu.exec(screenPos);
|
||||||
desktopMenu.exec(event->screenPos());
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::setFormFactor(FormFactor formFactor)
|
void Containment::setFormFactor(FormFactor formFactor)
|
||||||
|
@ -310,6 +310,12 @@ class PLASMA_EXPORT Containment : public Applet
|
|||||||
*/
|
*/
|
||||||
QString activity() const;
|
QString activity() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the context menu for the containment directly, bypassing Applets
|
||||||
|
* altogether.
|
||||||
|
*/
|
||||||
|
void showContextMenu(const QPointF &containmentPos, const QPoint &screenPos);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* This signal is emitted when a new applet is created by the containment
|
* This signal is emitted when a new applet is created by the containment
|
||||||
|
@ -74,6 +74,7 @@ public:
|
|||||||
void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
|
bool showContextMenu(const QPointF &point, const QPoint &screenPos, bool includeApplet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks or unlocks plasma's applets.
|
* Locks or unlocks plasma's applets.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user