diff --git a/containment.cpp b/containment.cpp index 467f10358..c22b8910e 100644 --- a/containment.cpp +++ b/containment.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include @@ -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(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" diff --git a/containment.h b/containment.h index 4bb434142..9dac8a530 100644 --- a/containment.h +++ b/containment.h @@ -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) diff --git a/corona.cpp b/corona.cpp index 50dd1b946..224afacd8 100644 --- a/corona.cpp +++ b/corona.cpp @@ -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 diff --git a/corona.h b/corona.h index 3622d83e3..a8e931e27 100644 --- a/corona.h +++ b/corona.h @@ -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: diff --git a/widgets/layoutitem.cpp b/widgets/layoutitem.cpp index 133b0e2c0..6b45df022 100644 --- a/widgets/layoutitem.cpp +++ b/widgets/layoutitem.cpp @@ -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