From c765e808a724659f45a4bfc5107d7df4933e85ad Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Thu, 22 Oct 2009 22:14:22 +0000 Subject: [PATCH] * the drop position is always relative to the containment; don't need to do store the scene pos. this fixes drops on panels * allow drops on the toolbox, this gives is a place to drop things on the panel at all times, similar to the context menu on toolbox * small delay on showing the drop zone indicator so that when dragging into the tasks widget, for example, we don't end up flickering as it crosses the panel containment edge svn path=/trunk/KDE/kdelibs/; revision=1039186 --- containment.cpp | 45 +++++++++++++++++++++++++++++++---------- containment.h | 8 +++++++- private/containment_p.h | 12 +++++++++-- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/containment.cpp b/containment.cpp index c798003f4..86bf8770d 100644 --- a/containment.cpp +++ b/containment.cpp @@ -1167,21 +1167,44 @@ void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event) } } - if (event->isAccepted() && view()) { - showDropZone(view()->mapFromScene(event->scenePos())); + if (event->isAccepted()) { + if (!d->showDropZoneDelayTimer) { + d->showDropZoneDelayTimer = new QTimer(this); + d->showDropZoneDelayTimer->setInterval(300); + d->showDropZoneDelayTimer->setSingleShot(true); + connect(d->showDropZoneDelayTimer, SIGNAL(timeout()), this, SLOT(showDropZoneDelayed())); + } + + d->dropPoints.insert(0, event->pos()); + d->showDropZoneDelayTimer->start(); } } +void Containment::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) +{ + if (d->showDropZoneDelayTimer) { + d->showDropZoneDelayTimer->stop(); + } +} + +void ContainmentPrivate::showDropZoneDelayed() +{ + q->showDropZone(dropPoints.value(0).toPoint()); + dropPoints.remove(0); +} + void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event) { QGraphicsItem *item = scene()->itemAt(event->scenePos()); - event->setAccepted(item == this || !item); - Plasma::Containment *c = containment(); - if (c && c->immutability() == Plasma::Mutable && - (event->mimeData()->hasFormat(static_cast(scene())->appletMimeType()) || - KUrl::List::canDecode(event->mimeData())) && view()) { - showDropZone(view()->mapFromScene(event->scenePos())); - } + event->setAccepted(item == this || item == d->toolBox || !item); + if (!event->isAccepted()) { + if (d->showDropZoneDelayTimer) { + d->showDropZoneDelayTimer->stop(); + } + } else if (!d->showDropZoneDelayTimer->isActive() && immutability() == Plasma::Mutable) { + kDebug() << event->pos().toPoint(); + showDropZone(event->pos().toPoint()); + } } void Containment::dropEvent(QGraphicsSceneDragDropEvent *event) @@ -1250,7 +1273,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS foreach (const KUrl &url, urls) { if (AccessManager::supportedProtocols().contains(url.protocol())) { AccessAppletJob *job = AccessManager::self()->accessRemoteApplet(url); - dropPoints[job] = dropEvent->scenePos(); + dropPoints[job] = dropEvent->pos(); QObject::connect(AccessManager::self(), SIGNAL(finished(Plasma::AccessAppletJob*)), q, SLOT(remoteAppletReady(Plasma::AccessAppletJob*))); } else { @@ -1270,7 +1293,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS // It may be a directory or a file, let's stat KIO::JobFlags flags = KIO::HideProgressInfo; KIO::TransferJob *job = KIO::get(url, KIO::NoReload, flags); - dropPoints[job] = dropEvent->scenePos(); + dropPoints[job] = dropEvent->pos(); QObject::connect(job, SIGNAL(result(KJob*)), q, SLOT(dropJobResult(KJob*))); QObject::connect(job, SIGNAL(mimetype(KIO::Job *, const QString&)), q, SLOT(mimeTypeRetrieved(KIO::Job *, const QString&))); diff --git a/containment.h b/containment.h index 21dc063c4..c441a5cec 100644 --- a/containment.h +++ b/containment.h @@ -547,6 +547,12 @@ class PLASMA_EXPORT Containment : public Applet */ void dragEnterEvent(QGraphicsSceneDragDropEvent *event); + /** + * @reimp + * @sa QGraphicsItem::dragLeaveEvent() + */ + void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); + /** * @reimp * @sa QGraphicsItem::dragMoveEvent() @@ -597,7 +603,7 @@ class PLASMA_EXPORT Containment : public Applet Q_PRIVATE_SLOT(d, void zoomOut()) Q_PRIVATE_SLOT(d, void requestConfiguration()) Q_PRIVATE_SLOT(d, void updateToolBoxVisibility()) - + Q_PRIVATE_SLOT(d, void showDropZoneDelayed()) Q_PRIVATE_SLOT(d, void remoteAppletReady(Plasma::AccessAppletJob *)) /** * This slot is called when the 'stat' after a job event has finished. diff --git a/private/containment_p.h b/private/containment_p.h index bcbf0171f..93544816b 100644 --- a/private/containment_p.h +++ b/private/containment_p.h @@ -51,6 +51,7 @@ public: toolBox(0), con(0), type(Containment::NoContainmentType), + showDropZoneDelayTimer(0), drawWallpaper(true) { } @@ -138,6 +139,13 @@ public: */ bool showAppletContextMenu(Applet *applet, const QPoint &screenPos); + /** + * Delayed drop zone display + */ + void showDropZoneDelayed(); + + static bool s_positioning; + Containment *q; FormFactor formFactor; Location location; @@ -151,10 +159,10 @@ public: AbstractToolBox *toolBox; Context *con; Containment::Type type; - static bool s_positioning; - bool drawWallpaper; QHash dropPoints; QHash dropMenus; + QTimer *showDropZoneDelayTimer; + bool drawWallpaper; }; } // Plasma namespace