summaryrefslogtreecommitdiffstats
path: root/src/plugins
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/plugins
parent07f8aecb52571d6a2d04133c24d8b8cd68769470 (diff)
add a platform interface for DnD
Use the simple in process DnD implementation for xcb.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/dnd/dnd.pri4
-rw-r--r--src/plugins/platforms/dnd/qsimpledrag.cpp202
-rw-r--r--src/plugins/platforms/dnd/qsimpledrag.h75
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp8
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.h3
-rw-r--r--src/plugins/platforms/xcb/xcb.pro1
6 files changed, 293 insertions, 0 deletions
diff --git a/src/plugins/platforms/dnd/dnd.pri b/src/plugins/platforms/dnd/dnd.pri
new file mode 100644
index 0000000000..d2a326b499
--- /dev/null
+++ b/src/plugins/platforms/dnd/dnd.pri
@@ -0,0 +1,4 @@
+INCLUDEPATH += $$PWD
+HEADERS += $$PWD/qsimpledrag.h
+SOURCES += $$PWD/qsimpledrag.cpp
+QT += gui-private
diff --git a/src/plugins/platforms/dnd/qsimpledrag.cpp b/src/plugins/platforms/dnd/qsimpledrag.cpp
new file mode 100644
index 0000000000..8032149875
--- /dev/null
+++ b/src/plugins/platforms/dnd/qsimpledrag.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "qsimpledrag.h"
+
+#include "qbitmap.h"
+#include "qdrag.h"
+#include "qpixmap.h"
+#include "qevent.h"
+#include "qfile.h"
+#include "qtextcodec.h"
+#include "qguiapplication.h"
+#include "qpoint.h"
+#include "qbuffer.h"
+#include "qimage.h"
+#include "qregexp.h"
+#include "qdir.h"
+#include "qimagereader.h"
+#include "qimagewriter.h"
+
+#include <private/qguiapplication_p.h>
+#include <private/qdnd_p.h>
+
+QT_BEGIN_NAMESPACE
+
+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;
+};
+
+QSimpleDrag::QSimpleDrag()
+{
+ m_dropData = new QDropData();
+ currentWindow = 0;
+}
+
+QSimpleDrag::~QSimpleDrag()
+{
+ delete m_dropData;
+}
+
+QMimeData *QSimpleDrag::platformDropData()
+{
+ return m_dropData;
+}
+
+void QSimpleDrag::cancel()
+{
+ QDragManager *m = QDragManager::self();
+// qDebug("QDragManager::cancel");
+ if (m->object->target()) {
+ QDragLeaveEvent dle;
+ QCoreApplication::sendEvent(m->object->target(), &dle);
+ }
+
+}
+
+void QSimpleDrag::move(const QMouseEvent *me)
+{
+ QWindow *window = QGuiApplication::topLevelAt(me->globalPos());
+ QPoint pos;
+ if (window)
+ pos = me->globalPos() - window->geometry().topLeft();
+
+ QDragManager *m = QDragManager::self();
+
+ if (me->buttons()) {
+ Qt::DropAction prevAction = m->global_accepted_action;
+
+ if (currentWindow != window) {
+ if (currentWindow) {
+ QDragLeaveEvent dle;
+ QCoreApplication::sendEvent(currentWindow, &dle);
+ m->willDrop = false;
+ m->global_accepted_action = Qt::IgnoreAction;
+ }
+ currentWindow = window;
+ if (currentWindow) {
+ QDragEnterEvent dee(pos, m->possible_actions, m->dropData(), me->buttons(), me->modifiers());
+ QCoreApplication::sendEvent(currentWindow, &dee);
+ m->willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
+ m->global_accepted_action = m->willDrop ? dee.dropAction() : Qt::IgnoreAction;
+ }
+ m->updateCursor();
+ } else if (window) {
+ Q_ASSERT(currentWindow);
+ QDragMoveEvent dme(pos, m->possible_actions, m->dropData(), me->buttons(), me->modifiers());
+ if (m->global_accepted_action != Qt::IgnoreAction) {
+ dme.setDropAction(m->global_accepted_action);
+ dme.accept();
+ }
+ QCoreApplication::sendEvent(currentWindow, &dme);
+ m->willDrop = dme.isAccepted();
+ m->global_accepted_action = m->willDrop ? dme.dropAction() : Qt::IgnoreAction;
+ m->updatePixmap();
+ m->updateCursor();
+ }
+ if (m->global_accepted_action != prevAction)
+ m->emitActionChanged(m->global_accepted_action);
+ }
+}
+
+void QSimpleDrag::drop(const QMouseEvent *me)
+{
+ QDragManager *m = QDragManager::self();
+
+ QWindow *window = QGuiApplication::topLevelAt(me->globalPos());
+
+ if (window) {
+ QPoint pos = me->globalPos() - window->geometry().topLeft();
+
+ QDropEvent de(pos, m->possible_actions, m->dropData(), me->buttons(), me->modifiers());
+ QCoreApplication::sendEvent(window, &de);
+ if (de.isAccepted())
+ m->global_accepted_action = de.dropAction();
+ else
+ m->global_accepted_action = Qt::IgnoreAction;
+ }
+ currentWindow = 0;
+}
+
+
+
+QDropData::QDropData()
+ : QInternalMimeData()
+{
+}
+
+QDropData::~QDropData()
+{
+}
+
+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;
+}
+
+bool QDropData::hasFormat_sys(const QString &format) const
+{
+ return formats().contains(format);
+}
+
+QStringList QDropData::formats_sys() const
+{
+ QDrag *object = QDragManager::self()->object;
+ if (object)
+ return object->mimeData()->formats();
+ return QStringList();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/dnd/qsimpledrag.h b/src/plugins/platforms/dnd/qsimpledrag.h
new file mode 100644
index 0000000000..82668a68c9
--- /dev/null
+++ b/src/plugins/platforms/dnd/qsimpledrag.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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 QSIMPLEDRAG_H
+#define QSIMPLEDRAG_H
+
+#include <qplatformdrag_qpa.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMouseEvent;
+class QWindow;
+
+class QDropData;
+
+class QSimpleDrag : public QPlatformDrag
+{
+public:
+ QSimpleDrag();
+ ~QSimpleDrag();
+
+ virtual QMimeData *platformDropData();
+
+// virtual Qt::DropAction drag(QDrag *);
+
+ virtual void cancel();
+ virtual void move(const QMouseEvent *me);
+ virtual void drop(const QMouseEvent *me);
+private:
+ QDropData *m_dropData;
+
+ QWindow *currentWindow;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index 7bf2c840b7..2c89bd6e80 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -46,6 +46,7 @@
#include "qxcbwindowsurface.h"
#include "qxcbnativeinterface.h"
#include "qxcbclipboard.h"
+#include <qsimpledrag.h>
#include <qgenericunixprintersupport.h>
@@ -69,11 +70,13 @@ QXcbIntegration::QXcbIntegration()
m_fontDatabase = new QGenericUnixFontDatabase();
m_nativeInterface = new QXcbNativeInterface;
+ m_drag = new QSimpleDrag;
}
QXcbIntegration::~QXcbIntegration()
{
delete m_connection;
+ delete m_drag;
}
bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
@@ -161,3 +164,8 @@ QPlatformClipboard *QXcbIntegration::clipboard() const
{
return m_connection->clipboard();
}
+
+QPlatformDrag *QXcbIntegration::drag() const
+{
+ return m_drag;
+}
diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h
index 65e2906bd2..2ddbe9fa49 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.h
+++ b/src/plugins/platforms/xcb/qxcbintegration.h
@@ -48,6 +48,7 @@
QT_BEGIN_NAMESPACE
class QXcbConnection;
+class QSimpleDrag;
class QXcbIntegration : public QPlatformIntegration
{
@@ -71,6 +72,7 @@ public:
QPlatformPrinterSupport *printerSupport() const;
QPlatformClipboard *clipboard() const;
+ QPlatformDrag *drag() const;
private:
bool hasOpenGL() const;
@@ -80,6 +82,7 @@ private:
QPlatformFontDatabase *m_fontDatabase;
QPlatformNativeInterface *m_nativeInterface;
QPlatformPrinterSupport *m_printerSupport;
+ QSimpleDrag *m_drag;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro
index 84d3d53f94..2091bb069d 100644
--- a/src/plugins/platforms/xcb/xcb.pro
+++ b/src/plugins/platforms/xcb/xcb.pro
@@ -74,6 +74,7 @@ LIBS += -lxcb -lxcb-image -lxcb-keysyms -lxcb-icccm -lxcb-sync
include (../fontdatabases/genericunix/genericunix.pri)
include (../printersupport/genericunix/genericunix.pri)
+include (../dnd/dnd.pri)
target.path += $$[QT_INSTALL_PLUGINS]/platforms
INSTALLS += target