Make drag-n-drop applets work again.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=716003
This commit is contained in:
Alex Merry 2007-09-23 18:03:37 +00:00
parent 4e4a77901e
commit d29805caef
5 changed files with 44 additions and 45 deletions

View File

@ -23,6 +23,7 @@
#include <QDesktopWidget>
#include <QFile>
#include <QGraphicsSceneContextMenuEvent>
#include <QMimeData>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
@ -30,6 +31,7 @@
#include <KAuthorized>
#include <KIcon>
#include <KMenu>
#include <KMimeType>
#include <KRun>
#include <KServiceTypeTrader>
@ -122,6 +124,7 @@ void Containment::init()
//kDebug() << "SVG wallpaper!";
d->background = new Plasma::Svg("widgets/wallpaper", this);
}
setAcceptDrops(true);
}
void Containment::initConstraints(KConfigGroup* group)
@ -564,6 +567,42 @@ KPluginInfo::List Containment::knownContainmentsForMimetype(const QString &mimet
return KPluginInfo::fromServices(offers);
}
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
{
//kDebug() << "drop event:" << event->mimeData()->text();
QString mimetype(static_cast<Corona*>(scene())->appletMimeType());
if (event->mimeData()->hasFormat(mimetype) && scene()) {
QString plasmoidName;
plasmoidName = event->mimeData()->data(mimetype);
QRectF geom(event->scenePos(), QSize(0, 0));
addApplet(plasmoidName, QVariantList(), 0, geom);
event->acceptProposedAction();
} else if (KUrl::List::canDecode(event->mimeData())) {
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
foreach (const KUrl& url, urls) {
KMimeType::Ptr mime = KMimeType::findByUrl(url);
QString mimeName = mime->name();
QRectF geom(event->scenePos(), QSize(0, 0));
QVariantList args;
args << url.url();
// kDebug() << mimeName;
KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName);
if (appletList.isEmpty()) {
// no special applet associated with this mimetype, let's
addApplet("url", args, 0, geom);
} else {
//TODO: should we show a dialog here to choose which plasmoid load if
//appletList.count() > 0?
addApplet(appletList.first().pluginName(), args, 0, geom);
}
}
event->acceptProposedAction();
}
}
}
#include "containment.moc"

View File

@ -232,6 +232,7 @@ class PLASMA_EXPORT Containment : public Applet
void runCommand();
void lockScreen();
void logout();
void dropEvent(QGraphicsSceneDragDropEvent* event);
private:
Q_DISABLE_COPY(Containment)

View File

@ -328,46 +328,6 @@ void Corona::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
//kDebug() << "Corona::dragMoveEvent(QDragMoveEvent* event)";
}
void Corona::dropEvent(QGraphicsSceneDragDropEvent *event)
{
if (itemAt(event->scenePos())) {
QGraphicsScene::dropEvent(event);
return;
}
//kDebug() << "Corona::dropEvent(QDropEvent* event)";
if (event->mimeData()->hasFormat(d->mimetype)) {
QString plasmoidName;
plasmoidName = event->mimeData()->data(d->mimetype);
QRectF geom(event->scenePos(), QSize(0, 0));
addApplet(plasmoidName, QVariantList(), 0, geom);
event->acceptProposedAction();
} else if (KUrl::List::canDecode(event->mimeData())) {
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
foreach (const KUrl& url, urls) {
KMimeType::Ptr mime = KMimeType::findByUrl(url);
QString mimeName = mime->name();
QRectF geom(event->scenePos(), QSize(0, 0));
QVariantList args;
args << url.url();
// kDebug() << mimeName;
KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName);
if (appletList.isEmpty()) {
// no special applet associated with this mimetype, let's
addApplet("url", args, 0, geom);
} else {
//TODO: should we show a dialog here to choose which plasmoid load if
//appletList.count() > 0?
addApplet(appletList.first().pluginName(), args, 0, geom);
}
}
event->acceptProposedAction();
} else {
QGraphicsScene::dropEvent(event);
}
}
void Corona::containmentDestroyed(QObject* obj)
{
// we do a static_cast here since it really isn't an Containment by this

View File

@ -156,7 +156,6 @@ protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
void dropEvent(QGraphicsSceneDragDropEvent* event);
//void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
protected Q_SLOTS:

View File

@ -86,21 +86,21 @@ qreal LayoutItem::widthForHeight(qreal h) const
void LayoutItem::setLayout(Layout* layout)
{
if (d->layout && layout) {
kDebug() << " already have a layout.";
kDebug() << "already have a layout.";
return;
}
d->layout = layout;
if (layout) {
layout->setParent(this);
} else {
} else if (d->layout) {
// FIXME: we had a layout, but now it has been removed
// and we are without layout; we should tell our
// children about this, but LayoutItem doesn't know
// about children =/
kDebug() << "layout removed from under us. expect crashes";
}
d->layout = layout;
}
Layout* LayoutItem::layout() const