summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-05-31 20:45:27 +0200
committerLars Knoll <lars.knoll@nokia.com>2011-06-01 09:55:39 +0200
commit38745b341c5c4d49fdb0e87f79f2714f105f63fe (patch)
tree50b9d0dc446758258f034e1d7ec188a16c2b8217 /src/gui
parent07f8aecb52571d6a2d04133c24d8b8cd68769470 (diff)
add a platform interface for DnD
Use the simple in process DnD implementation for xcb.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/kernel.pri1
-rw-r--r--src/gui/kernel/qdnd.cpp174
-rw-r--r--src/gui/kernel/qdnd_p.h20
-rw-r--r--src/gui/kernel/qplatformdrag_qpa.h66
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp8
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h4
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp1
7 files changed, 132 insertions, 142 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index b40f699a3b..b7c49a3db8 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -42,6 +42,7 @@ qpa {
kernel/qwindowsysteminterface_qpa.h \
kernel/qwindowsysteminterface_qpa_p.h \
kernel/qplatformintegration_qpa.h \
+ kernel/qplatformdrag_qpa.h \
kernel/qplatformscreen_qpa.h \
kernel/qplatformintegrationfactory_qpa_p.h \
kernel/qplatformintegrationplugin_qpa.h \
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp
index f9d51f442b..ae2f3779a8 100644
--- a/src/gui/kernel/qdnd.cpp
+++ b/src/gui/kernel/qdnd.cpp
@@ -58,6 +58,7 @@
#include "qimagewriter.h"
#include "qdebug.h"
#include <ctype.h>
+#include <qplatformdrag_qpa.h>
#include <private/qguiapplication_p.h>
@@ -121,19 +122,6 @@ QString KeyboardModifiersToString(Qt::KeyboardModifiers moderfies)
}
#endif
-class QDropData : public QInternalMimeData
-{
-public:
- QDropData();
- ~QDropData();
-
-protected:
- bool hasFormat_sys(const QString &mimeType) const;
- QStringList formats_sys() const;
- QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
-};
-
-
// the universe's only drag manager
QDragManager *QDragManager::instance = 0;
@@ -151,15 +139,19 @@ QDragManager::QDragManager()
restoreCursor = false;
willDrop = false;
eventLoop = 0;
- platformDropData = new QDropData();
currentDropTarget = 0;
#ifdef Q_WS_X11
xdndMimeTransferedPixmapIndex = 0;
#endif
- currentWindow = 0;
-
possible_actions = Qt::IgnoreAction;
+
+ QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
+ platformDrag = pi->drag();
+
+ platformDropData = 0;
+ if (platformDrag)
+ platformDropData = platformDrag->platformDropData();
}
@@ -170,7 +162,6 @@ QDragManager::~QDragManager()
QGuiApplication::restoreOverrideCursor();
#endif
instance = 0;
- delete platformDropData;
}
QDragManager *QDragManager::self()
@@ -304,8 +295,6 @@ static const char *const default_pm[] = {
"X X X X X X X",
};
-// Shift/Ctrl handling, and final drop status
-static Qt::DropAction global_accepted_action = Qt::CopyAction;
static Qt::KeyboardModifiers oldstate;
@@ -375,50 +364,6 @@ void QDragManager::updatePixmap()
}
}
-void QDragManager::move(const QMouseEvent *me)
-{
- QWindow *window = QGuiApplication::topLevelAt(me->globalPos());
- QPoint pos;
- if (window)
- pos = me->globalPos() - window->geometry().topLeft();
-
- if (me->buttons()) {
- Qt::DropAction prevAction = global_accepted_action;
-
- if (currentWindow != window) {
- if (currentWindow) {
- QDragLeaveEvent dle;
- QCoreApplication::sendEvent(currentWindow, &dle);
- willDrop = false;
- global_accepted_action = Qt::IgnoreAction;
- }
- currentWindow = window;
- if (currentWindow) {
- QDragEnterEvent dee(pos, possible_actions, dropData(), me->buttons(), me->modifiers());
- QCoreApplication::sendEvent(currentWindow, &dee);
- willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
- global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction;
- }
- updateCursor();
- restoreCursor = true;
- } else if (window) {
- Q_ASSERT(currentWindow);
- QDragMoveEvent dme(pos, possible_actions, dropData(), me->buttons(), me->modifiers());
- if (global_accepted_action != Qt::IgnoreAction) {
- dme.setDropAction(global_accepted_action);
- dme.accept();
- }
- QCoreApplication::sendEvent(currentWindow, &dme);
- willDrop = dme.isAccepted();
- global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction;
- updatePixmap();
- updateCursor();
- }
- if (global_accepted_action != prevAction)
- emitActionChanged(global_accepted_action);
- }
-}
-
void QDragManager::updateCursor()
{
#ifndef QT_NO_CURSOR
@@ -508,9 +453,14 @@ bool QDragManager::eventFilter(QObject *o, QEvent *e)
Qt::DropAction QDragManager::drag(QDrag *o)
{
- if (object == o || !o || !o->source())
+ if (!o || object == o)
return Qt::IgnoreAction;
+ if (!platformDrag || !o->source()) {
+ o->deleteLater();
+ return Qt::IgnoreAction;
+ }
+
if (object) {
cancel();
qApp->removeEventFilter(this);
@@ -526,9 +476,6 @@ Qt::DropAction QDragManager::drag(QDrag *o)
possible_actions = dragPrivate()->possible_actions;
willDrop = false;
- updatePixmap();
- updateCursor();
- restoreCursor = true;
object->d_func()->target = 0;
qApp->installEventFilter(this);
@@ -538,6 +485,7 @@ Qt::DropAction QDragManager::drag(QDrag *o)
restoreCursor = true;
updateCursor();
#endif
+ updatePixmap();
eventLoop = new QEventLoop;
(void) eventLoop->exec();
@@ -550,16 +498,18 @@ Qt::DropAction QDragManager::drag(QDrag *o)
return global_accepted_action;
}
-
-void QDragManager::cancel(bool deleteSource)
+void QDragManager::move(const QMouseEvent *me)
{
-// qDebug("QDragManager::cancel");
- beingCancelled = true;
+ if (!platformDrag)
+ return;
- if (object->target()) {
- QDragLeaveEvent dle;
- QCoreApplication::sendEvent(object->target(), &dle);
- }
+ platformDrag->move(me);
+}
+
+void QDragManager::drop(const QMouseEvent *me)
+{
+ if (!platformDrag)
+ return;
#ifndef QT_NO_CURSOR
if (restoreCursor) {
@@ -567,22 +517,20 @@ void QDragManager::cancel(bool deleteSource)
restoreCursor = false;
}
#endif
+ willDrop = false;
- if (object) {
- if (deleteSource)
- object->deleteLater();
- object = 0;
- }
-
- delete qt_qws_dnd_deco;
- qt_qws_dnd_deco = 0;
+ platformDrag->drop(me);
- global_accepted_action = Qt::IgnoreAction;
+ if (object)
+ object->deleteLater();
+ object = 0;
}
-
-void QDragManager::drop(const QMouseEvent *me)
+void QDragManager::cancel(bool deleteSource)
{
+ if (!platformDrag)
+ return;
+
#ifndef QT_NO_CURSOR
if (restoreCursor) {
QGuiApplication::restoreOverrideCursor();
@@ -590,57 +538,15 @@ void QDragManager::drop(const QMouseEvent *me)
}
#endif
- willDrop = false;
- QWindow *window = QGuiApplication::topLevelAt(me->globalPos());
-
- if (window) {
- QPoint pos = me->globalPos() - window->geometry().topLeft();
-
- QDropEvent de(pos, possible_actions, dropData(), me->buttons(), me->modifiers());
- QCoreApplication::sendEvent(window, &de);
- if (de.isAccepted())
- global_accepted_action = de.dropAction();
- else
- global_accepted_action = Qt::IgnoreAction;
-
- if (object)
- object->deleteLater();
- object = 0;
- }
- currentWindow = 0;
-}
-
-QDropData::QDropData()
- : QInternalMimeData()
-{
-}
-
-QDropData::~QDropData()
-{
-}
+ beingCancelled = true;
-QVariant QDropData::retrieveData_sys(const QString &mimetype, QVariant::Type type) const
-{
- QDrag *object = QDragManager::self()->object;
- if (!object)
- return QVariant();
- QByteArray data = object->mimeData()->data(mimetype);
- if (type == QVariant::String)
- return QString::fromUtf8(data);
- return data;
-}
+ platformDrag->cancel();
-bool QDropData::hasFormat_sys(const QString &format) const
-{
- return formats().contains(format);
-}
+ if (object && deleteSource)
+ object->deleteLater();
+ object = 0;
-QStringList QDropData::formats_sys() const
-{
- QDrag *object = QDragManager::self()->object;
- if (object)
- return object->mimeData()->formats();
- return QStringList();
+ global_accepted_action = Qt::IgnoreAction;
}
#endif // QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qdnd_p.h b/src/gui/kernel/qdnd_p.h
index 04c5139fbb..3ba2869a8f 100644
--- a/src/gui/kernel/qdnd_p.h
+++ b/src/gui/kernel/qdnd_p.h
@@ -66,6 +66,7 @@ QT_BEGIN_NAMESPACE
class QEventLoop;
class QMouseEvent;
+class QPlatformDrag;
#ifndef QT_NO_DRAGANDDROP
@@ -142,32 +143,35 @@ public:
inline QMimeData *dropData()
{ return object ? dragPrivate()->data : platformDropData; }
+ void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
+
+ void setCurrentTarget(QObject *target, bool dropped = false);
+ QObject *currentTarget();
+
QDrag *object;
- QMimeData *platformDropData;
bool beingCancelled;
bool restoreCursor;
bool willDrop;
QEventLoop *eventLoop;
- void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
-
- void setCurrentTarget(QObject *target, bool dropped = false);
- QObject *currentTarget();
- QWindow *currentWindow;
-
Qt::DropActions possible_actions;
+ // Shift/Ctrl handling, and final drop status
+ Qt::DropAction global_accepted_action;
private:
+ QMimeData *platformDropData;
+
Qt::DropAction currentActionForOverrideCursor;
QObject *currentDropTarget;
+ QPlatformDrag *platformDrag;
+
static QDragManager *instance;
Q_DISABLE_COPY(QDragManager)
};
-
#endif // !QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qplatformdrag_qpa.h b/src/gui/kernel/qplatformdrag_qpa.h
new file mode 100644
index 0000000000..16d8363b03
--- /dev/null
+++ b/src/gui/kernel/qplatformdrag_qpa.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMDRAG_H
+#define QPLATFORMDRAG_H
+
+#include <qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMimeData;
+class QMouseEvent;
+
+class QPlatformDrag
+{
+public:
+ virtual ~QPlatformDrag() {}
+
+ virtual QMimeData *platformDropData() = 0;
+
+ virtual void move(const QMouseEvent *me) = 0;
+ virtual void drop(const QMouseEvent *me) = 0;
+ virtual void cancel() = 0;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp
index b335dd5a97..12b8760ffd 100644
--- a/src/gui/kernel/qplatformintegration_qpa.cpp
+++ b/src/gui/kernel/qplatformintegration_qpa.cpp
@@ -44,6 +44,7 @@
#include <QtGui/QPlatformFontDatabase>
#include <QtGui/QPlatformClipboard>
#include <QtGui/QPlatformPrinterSupport>
+#include <private/qdnd_p.h>
QT_BEGIN_NAMESPACE
@@ -107,6 +108,13 @@ QPlatformClipboard *QPlatformIntegration::clipboard() const
#endif
+#ifndef QT_NO_DRAGANDDROP
+QPlatformDrag *QPlatformIntegration::drag() const
+{
+ return 0;
+}
+#endif
+
QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
{
return 0;
diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h
index c3d311eb1e..1a96d84a5e 100644
--- a/src/gui/kernel/qplatformintegration_qpa.h
+++ b/src/gui/kernel/qplatformintegration_qpa.h
@@ -61,6 +61,7 @@ class QPlatformFontDatabase;
class QPlatformClipboard;
class QPlatformNativeInterface;
class QPlatformPrinterSupport;
+class QPlatformDrag;
class Q_GUI_EXPORT QPlatformIntegration
{
@@ -90,6 +91,9 @@ public:
#ifndef QT_NO_CLIPBOARD
virtual QPlatformClipboard *clipboard() const;
#endif
+#ifndef QT_NO_DRAGANDDROP
+ virtual QPlatformDrag *drag() const;
+#endif
// Experimental in mainthread eventloop integration
// This should only be used if it is only possible to do window system event processing in
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
index fbe5fbdd7a..6b59fb26a7 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp
+++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
@@ -42,6 +42,7 @@
#include "qwindowsysteminterface_qpa_p.h"
#include "private/qguiapplication_p.h"
#include <QAbstractEventDispatcher>
+#include <qdebug.h>
QT_BEGIN_NAMESPACE