Make drag-n-drop applets work again.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=716003
This commit is contained in:
parent
4e4a77901e
commit
d29805caef
@ -23,6 +23,7 @@
|
|||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGraphicsSceneContextMenuEvent>
|
#include <QGraphicsSceneContextMenuEvent>
|
||||||
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyleOptionGraphicsItem>
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
@ -30,6 +31,7 @@
|
|||||||
#include <KAuthorized>
|
#include <KAuthorized>
|
||||||
#include <KIcon>
|
#include <KIcon>
|
||||||
#include <KMenu>
|
#include <KMenu>
|
||||||
|
#include <KMimeType>
|
||||||
#include <KRun>
|
#include <KRun>
|
||||||
#include <KServiceTypeTrader>
|
#include <KServiceTypeTrader>
|
||||||
|
|
||||||
@ -122,6 +124,7 @@ void Containment::init()
|
|||||||
//kDebug() << "SVG wallpaper!";
|
//kDebug() << "SVG wallpaper!";
|
||||||
d->background = new Plasma::Svg("widgets/wallpaper", this);
|
d->background = new Plasma::Svg("widgets/wallpaper", this);
|
||||||
}
|
}
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::initConstraints(KConfigGroup* group)
|
void Containment::initConstraints(KConfigGroup* group)
|
||||||
@ -564,6 +567,42 @@ KPluginInfo::List Containment::knownContainmentsForMimetype(const QString &mimet
|
|||||||
return KPluginInfo::fromServices(offers);
|
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"
|
#include "containment.moc"
|
||||||
|
@ -232,6 +232,7 @@ class PLASMA_EXPORT Containment : public Applet
|
|||||||
void runCommand();
|
void runCommand();
|
||||||
void lockScreen();
|
void lockScreen();
|
||||||
void logout();
|
void logout();
|
||||||
|
void dropEvent(QGraphicsSceneDragDropEvent* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Containment)
|
Q_DISABLE_COPY(Containment)
|
||||||
|
40
corona.cpp
40
corona.cpp
@ -328,46 +328,6 @@ void Corona::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|||||||
//kDebug() << "Corona::dragMoveEvent(QDragMoveEvent* 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)
|
void Corona::containmentDestroyed(QObject* obj)
|
||||||
{
|
{
|
||||||
// we do a static_cast here since it really isn't an Containment by this
|
// we do a static_cast here since it really isn't an Containment by this
|
||||||
|
1
corona.h
1
corona.h
@ -156,7 +156,6 @@ protected:
|
|||||||
void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
|
void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
|
||||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
|
void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);
|
||||||
void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
|
void dragMoveEvent(QGraphicsSceneDragDropEvent* event);
|
||||||
void dropEvent(QGraphicsSceneDragDropEvent* event);
|
|
||||||
//void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
|
//void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
|
@ -90,17 +90,17 @@ void LayoutItem::setLayout(Layout* layout)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->layout = layout;
|
|
||||||
|
|
||||||
if (layout) {
|
if (layout) {
|
||||||
layout->setParent(this);
|
layout->setParent(this);
|
||||||
} else {
|
} else if (d->layout) {
|
||||||
// FIXME: we had a layout, but now it has been removed
|
// FIXME: we had a layout, but now it has been removed
|
||||||
// and we are without layout; we should tell our
|
// and we are without layout; we should tell our
|
||||||
// children about this, but LayoutItem doesn't know
|
// children about this, but LayoutItem doesn't know
|
||||||
// about children =/
|
// about children =/
|
||||||
kDebug() << "layout removed from under us. expect crashes";
|
kDebug() << "layout removed from under us. expect crashes";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->layout = layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout* LayoutItem::layout() const
|
Layout* LayoutItem::layout() const
|
||||||
|
Loading…
Reference in New Issue
Block a user