move the desktop context menu out of corona. this reflects the design better where different views may want different menus; the dekstop menu only being appropriate for, well, the desktop; other apps may be using Corona for which "desktop" is completely irrelevant.

this also moves the desktop related items out of libplasma, making it a bit more light.

functionality has moved into CoronaView, which will soon be renamed

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=689123
This commit is contained in:
Aaron J. Seigo 2007-07-17 17:55:05 +00:00
parent 5151879373
commit acbfadae12
3 changed files with 10 additions and 135 deletions

View File

@ -42,9 +42,6 @@ set(plasmagik_HEADERS
package.h package.h
) )
set(krunner_xml ${CMAKE_SOURCE_DIR}/workspace/krunner/org.kde.krunner.Interface.xml)
QT4_ADD_DBUS_INTERFACE(plasma_LIB_SRCS ${krunner_xml} krunner_interface)
kde4_add_library(plasma SHARED ${plasma_LIB_SRCS}) kde4_add_library(plasma SHARED ${plasma_LIB_SRCS})
target_link_libraries(plasma ${KDE4_KIO_LIBS}) target_link_libraries(plasma ${KDE4_KIO_LIBS})

View File

@ -27,12 +27,9 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QStringList> #include <QStringList>
#include <KAuthorized>
#include <KDebug> #include <KDebug>
#include <KLocale> #include <KLocale>
#include <KMenu>
#include <KMimeType> #include <KMimeType>
#include <KRun>
#include <KWindowSystem> #include <KWindowSystem>
#include "applet.h" #include "applet.h"
@ -42,8 +39,6 @@
#include "widgets/vboxlayout.h" #include "widgets/vboxlayout.h"
#include "widgets/icon.h" #include "widgets/icon.h"
#include "krunner_interface.h"
using namespace Plasma; using namespace Plasma;
namespace Plasma namespace Plasma
@ -53,10 +48,10 @@ class Corona::Private
{ {
public: public:
Private() Private()
: formFactor(Planar), : immutable(false),
formFactor(Planar),
location(Floating), location(Floating),
layout(0), layout(0)
engineExplorerAction(0)
{ {
} }
@ -71,53 +66,27 @@ public:
FormFactor formFactor; FormFactor formFactor;
Location location; Location location;
Layout* layout; Layout* layout;
QAction *engineExplorerAction;
QAction *runCommandAction;
}; };
Corona::Corona(QObject * parent) Corona::Corona(QObject * parent)
: QGraphicsScene(parent), : QGraphicsScene(parent),
d(new Private) d(new Private)
{ {
init(); //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
} }
Corona::Corona(const QRectF & sceneRect, QObject * parent ) Corona::Corona(const QRectF & sceneRect, QObject * parent )
: QGraphicsScene(sceneRect, parent), : QGraphicsScene(sceneRect, parent),
d(new Private) d(new Private)
{ {
init(); //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
} }
Corona::Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent) Corona::Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent)
: QGraphicsScene(x, y, width, height, parent), : QGraphicsScene(x, y, width, height, parent),
d(new Private) d(new Private)
{ {
init(); //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
}
void Corona::init()
{
/* QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent);
setPalette(pal);*/
//setViewport(new QGLWidget ( QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel) ));
/*
KPluginInfo::List applets = Applet::knownApplets();
kDebug() << "======= Applets =========" << endl;
foreach (KPluginInfo* info, applets) {
kDebug() << info->pluginName() << ": " << info->name() << endl;
}
kDebug() << "=========================" << endl;
*/
//TODO: should we delay the init of the actions until we actually need them?
d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer()));
d->runCommandAction = new QAction(i18n("Run Command..."), this);
connect(d->runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
d->immutable = false;
} }
Corona::~Corona() Corona::~Corona()
@ -274,96 +243,9 @@ void Corona::dropEvent(QGraphicsSceneDragDropEvent *event)
} }
} }
void Corona::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent) // void Corona::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
{ // {
if (!KAuthorized::authorizeKAction("desktop_contextmenu")) { // }
return;
}
QPointF point = contextMenuEvent->scenePos();
/*
* example for displaying the SuperKaramba context menu
QGraphicsItem *item = itemAt(point);
if(item) {
QObject *object = dynamic_cast<QObject*>(item->parentItem());
if(object && object->objectName().startsWith("karamba")) {
QContextMenuEvent event(QContextMenuEvent::Mouse, point);
contextMenuEvent(&event);
return;
}
}
*/
contextMenuEvent->accept();
QGraphicsItem* item = itemAt(point);
Applet* applet = 0;
while (item) {
applet = qgraphicsitem_cast<Applet*>(item);
if (applet) {
break;
}
item = item->parentItem();
}
KMenu desktopMenu;
//kDebug() << "context menu event " << d->immutable << endl;
if (!applet) {
if (d->immutable) {
return;
}
//FIXME: change this to show this only in debug mode (or not at all?)
// before final release
desktopMenu.addAction(d->engineExplorerAction);
if (KAuthorized::authorizeKAction("run_command")) {
desktopMenu.addAction(d->runCommandAction);
}
} else if (applet->immutable()) {
return;
} else {
//desktopMenu.addSeparator();
bool hasEntries = false;
if (applet->hasConfigurationInterface()) {
QAction* configureApplet = new QAction(i18n("%1 Settings...", applet->name()), this);
connect(configureApplet, SIGNAL(triggered(bool)),
applet, SLOT(showConfigurationInterface()));
desktopMenu.addAction(configureApplet);
hasEntries = true;
}
if (!d->immutable) {
QAction* closeApplet = new QAction(i18n("Close this %1", applet->name()), this);
connect(closeApplet, SIGNAL(triggered(bool)),
applet, SLOT(deleteLater()));
desktopMenu.addAction(closeApplet);
hasEntries = true;
}
if (!hasEntries) {
return;
}
}
desktopMenu.exec(point.toPoint());
}
void Corona::launchExplorer()
{
KRun::run("plasmaengineexplorer", KUrl::List(), 0);
}
void Corona::runCommand()
{
if (!KAuthorized::authorizeKAction("run_command")) {
return;
}
QString interface("org.kde.krunner");
org::kde::krunner::Interface krunner(interface, "/Interface",
QDBusConnection::sessionBus());
krunner.display();
}
void Corona::appletDestroyed(QObject* object) void Corona::appletDestroyed(QObject* object)
{ {

View File

@ -108,16 +108,12 @@ protected:
void dragLeaveEvent(QGraphicsSceneDragDropEvent* event); void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
void dragMoveEvent(QGraphicsSceneDragDropEvent* event); void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
void dropEvent(QGraphicsSceneDragDropEvent* event); void dropEvent(QGraphicsSceneDragDropEvent* event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent); // void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
protected Q_SLOTS: protected Q_SLOTS:
void launchExplorer();
void runCommand();
void appletDestroyed(QObject*); void appletDestroyed(QObject*);
private: private:
void init();
class Private; class Private;
Private * const d; Private * const d;
}; };