move drag handling back to Gui

Move the DnD related classes back into
QtGui. Parts of the implementation is currently
commented out and needs to be moved to
QWidgetWindow.

SC incompatible change:
APIs taking QWidget * now take QObject *
bb10
Lars Knoll 2011-05-18 12:56:51 +02:00
parent 1f572c694b
commit 82bba7e4ef
9 changed files with 58 additions and 59 deletions

View File

@ -9,6 +9,8 @@ HEADERS += \
kernel/qclipboard.h \
kernel/qcursor.h \
kernel/qcursor_p.h \
kernel/qdrag.h \
kernel/qdnd_p.h \
kernel/qevent.h \
kernel/qevent_p.h \
kernel/qkeysequence.h \
@ -22,6 +24,9 @@ HEADERS += \
SOURCES += \
kernel/qclipboard.cpp \
kernel/qcursor.cpp \
kernel/qdrag.cpp \
kernel/qdnd.cpp \
kernel/qdnd_qpa.cpp \
kernel/qevent.cpp \
kernel/qkeysequence.cpp \
kernel/qkeymapper.cpp \

View File

@ -49,7 +49,6 @@
#include "qtextcodec.h"
#include "qguiapplication.h"
#include "qpoint.h"
#include "qwidget.h"
#include "qbuffer.h"
#include "qimage.h"
#include "qregexp.h"
@ -162,7 +161,7 @@ QDragManager::~QDragManager()
QDragManager *QDragManager::self()
{
if (!instance && !QApplication::closingDown())
if (!instance && !QGuiApplication::closingDown())
instance = new QDragManager;
return instance;
}
@ -257,7 +256,7 @@ Qt::DropAction QDragManager::defaultAction(Qt::DropActions possibleActions,
return defaultAction;
}
void QDragManager::setCurrentTarget(QWidget *target, bool dropped)
void QDragManager::setCurrentTarget(QObject *target, bool dropped)
{
if (currentDropTarget == target)
return;
@ -270,7 +269,7 @@ void QDragManager::setCurrentTarget(QWidget *target, bool dropped)
}
QWidget *QDragManager::currentTarget()
QObject *QDragManager::currentTarget()
{
return currentDropTarget;
}

View File

@ -56,7 +56,7 @@
#include "QtCore/qobject.h"
#include "QtCore/qmap.h"
#include "QtGui/qmime.h"
#include "QtWidgets/qdrag.h"
#include "QtGui/qdrag.h"
#include "QtGui/qpixmap.h"
#include "QtGui/qcursor.h"
#include "QtCore/qpoint.h"
@ -174,8 +174,8 @@ private:
class QDragPrivate : public QObjectPrivate
{
public:
QWidget *source;
QWidget *target;
QObject *source;
QObject *target;
QMimeData *data;
QPixmap pixmap;
QPoint hotspot;
@ -203,7 +203,7 @@ public:
#endif
};
class QDragManager: public QObject {
class Q_GUI_EXPORT QDragManager: public QObject {
Q_OBJECT
QDragManager();
@ -213,9 +213,6 @@ class QDragManager: public QObject {
friend class QDragMoveEvent;
friend class QDropEvent;
friend class QApplication;
#ifdef Q_WS_MAC
friend class QWidgetPrivate; //dnd is implemented here
#endif
bool eventFilter(QObject *, QEvent *);
void timerEvent(QTimerEvent*);
@ -227,7 +224,7 @@ public:
void move(const QPoint &);
void drop();
void updatePixmap();
QWidget *source() const { return object ? object->d_func()->source : 0; }
QObject *source() const { return object ? object->d_func()->source : 0; }
QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; }
static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; }
@ -252,8 +249,8 @@ public:
void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
void setCurrentTarget(QWidget *target, bool dropped = false);
QWidget *currentTarget();
void setCurrentTarget(QObject *target, bool dropped = false);
QObject *currentTarget();
#ifdef Q_WS_X11
QPixmap xdndMimeTransferedPixmap[2];
@ -269,7 +266,7 @@ private:
QCursor overrideCursor;
#endif
#endif
QWidget *currentDropTarget;
QObject *currentDropTarget;
static QDragManager *instance;
Q_DISABLE_COPY(QDragManager)

View File

@ -43,13 +43,13 @@
#ifndef QT_NO_DRAGANDDROP
#include "qwidget.h"
#include "qdatetime.h"
#include "qbitmap.h"
#include "qcursor.h"
#include "qevent.h"
#include "qpainter.h"
#include "qdnd_p.h"
#include "qwindow.h"
QT_BEGIN_NAMESPACE
@ -86,39 +86,45 @@ static bool qt_qws_dnd_dragging = false;
static Qt::KeyboardModifiers oldstate;
class QShapedPixmapWidget : public QWidget {
class QShapedPixmapWindow : public QWindow {
QPixmap pixmap;
public:
QShapedPixmapWidget() :
QWidget(0, Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint)
QShapedPixmapWindow() :
QWindow(0)
{
// ### Temporary workaround for 4.2-rc1!!! To prevent flickering when
// using drag'n drop in a client application. (task 126956)
// setAttribute() should be done unconditionally!
// if (QApplication::type() == QApplication::GuiServer)
setAttribute(Qt::WA_TransparentForMouseEvents);
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
// ### Should we set the surface type to raster?
// ### FIXME
// setAttribute(Qt::WA_TransparentForMouseEvents);
}
void move(const QPoint &p) {
QRect g = geometry();
g.setTopLeft(p);
setGeometry(g);
}
void setPixmap(QPixmap pm)
{
pixmap = pm;
if (!pixmap.mask().isNull()) {
setMask(pixmap.mask());
} else {
clearMask();
}
resize(pm.width(),pm.height());
// ###
// if (!pixmap.mask().isNull()) {
// setMask(pixmap.mask());
// } else {
// clearMask();
// }
// resize(pm.width(),pm.height());
}
void paintEvent(QPaintEvent*)
{
QPainter p(this);
p.drawPixmap(0,0,pixmap);
}
// ### Get it painted again!
// void paintEvent(QPaintEvent*)
// {
// QPainter p(this);
// p.drawPixmap(0,0,pixmap);
// }
};
static QShapedPixmapWidget *qt_qws_dnd_deco = 0;
static QShapedPixmapWindow *qt_qws_dnd_deco = 0;
void QDragManager::updatePixmap()
@ -175,6 +181,8 @@ void QDragManager::updateCursor()
bool QDragManager::eventFilter(QObject *o, QEvent *e)
{
#if 0
// ###
if (beingCancelled) {
if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
qApp->removeEventFilter(this);
@ -313,7 +321,7 @@ bool QDragManager::eventFilter(QObject *o, QEvent *e)
default:
break;
}
#endif
return false;
}
@ -329,7 +337,7 @@ Qt::DropAction QDragManager::drag(QDrag *o)
}
object = drag_object = o;
qt_qws_dnd_deco = new QShapedPixmapWidget();
qt_qws_dnd_deco = new QShapedPixmapWindow();
oldstate = Qt::NoModifier; // #### Should use state that caused the drag
// drag_mode = mode;

View File

@ -39,7 +39,6 @@
**
****************************************************************************/
#include <qwidget.h>
#include <qdrag.h>
#include <qpixmap.h>
#include <qpoint.h>
@ -66,7 +65,7 @@ QT_BEGIN_NAMESPACE
\snippet doc/src/snippets/dragging/mainwindow.cpp 1
Note that setMimeData() assigns ownership of the QMimeData object to the
QDrag object. The QDrag must be constructed on the heap with a parent QWidget
QDrag object. The QDrag must be constructed on the heap with a parent QObject
to ensure that Qt can clean up after the drag and drop operation has been
completed.
@ -107,7 +106,7 @@ QT_BEGIN_NAMESPACE
/*!
Constructs a new drag object for the widget specified by \a dragSource.
*/
QDrag::QDrag(QWidget *dragSource)
QDrag::QDrag(QObject *dragSource)
: QObject(*new QDragPrivate, dragSource)
{
Q_D(QDrag);
@ -203,7 +202,7 @@ QPoint QDrag::hotSpot() const
Returns the source of the drag object. This is the widget where the drag
and drop operation originated.
*/
QWidget *QDrag::source() const
QObject *QDrag::source() const
{
Q_D(const QDrag);
return d->source;
@ -213,7 +212,7 @@ QWidget *QDrag::source() const
Returns the target of the drag and drop operation. This is the widget where
the drag object was dropped.
*/
QWidget *QDrag::target() const
QObject *QDrag::target() const
{
Q_D(const QDrag);
return d->target;
@ -346,7 +345,7 @@ void QDrag::setDragCursor(const QPixmap &cursor, Qt::DropAction action)
*/
/*!
\fn void QDrag::targetChanged(QWidget *newTarget)
\fn void QDrag::targetChanged(QObject *newTarget)
This signal is emitted when the target of the drag and drop
operation changes, with \a newTarget the new target.

View File

@ -53,7 +53,6 @@ QT_MODULE(Gui)
#ifndef QT_NO_DRAGANDDROP
class QMimeData;
class QDragPrivate;
class QWidget;
class QPixmap;
class QPoint;
class QDragManager;
@ -63,7 +62,7 @@ class Q_GUI_EXPORT QDrag : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QDrag)
public:
explicit QDrag(QWidget *dragSource);
explicit QDrag(QObject *dragSource);
~QDrag();
void setMimeData(QMimeData *data);
@ -75,8 +74,8 @@ public:
void setHotSpot(const QPoint &hotspot);
QPoint hotSpot() const;
QWidget *source() const;
QWidget *target() const;
QObject *source() const;
QObject *target() const;
Qt::DropAction start(Qt::DropActions supportedActions = Qt::CopyAction);
Qt::DropAction exec(Qt::DropActions supportedActions = Qt::MoveAction);
@ -86,12 +85,9 @@ public:
Q_SIGNALS:
void actionChanged(Qt::DropAction action);
void targetChanged(QWidget *newTarget);
void targetChanged(QObject *newTarget);
private:
#ifdef Q_WS_MAC
friend class QWidgetPrivate;
#endif
friend class QDragManager;
Q_DISABLE_COPY(QDrag)
};

View File

@ -757,7 +757,7 @@ QT_CLASS_LIB(QCursor, QtGui, qcursor.h)
QT_CLASS_LIB(QCursor, QtGui, qcursor.h)
QT_CLASS_LIB(QCursorShape, QtWidgets, qcursor.h)
QT_CLASS_LIB(QDesktopWidget, QtWidgets, qdesktopwidget.h)
QT_CLASS_LIB(QDrag, QtGui, qdrag.h)
QT_CLASS_LIB(QDrag, QtWidgets, qdrag.h)
QT_CLASS_LIB(QtEvents, QtGui, qevent.h)
QT_CLASS_LIB(QInputEvent, QtGui, qevent.h)
QT_CLASS_LIB(QMouseEvent, QtGui, qevent.h)

View File

@ -4055,7 +4055,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
bool isProxyWidget = extra && extra->proxyWidget;
if (!isProxyWidget)
#endif
w = QDragManager::self()->currentTarget();
w = qobject_cast<QWidget *>(QDragManager::self()->currentTarget());
if (!w) {
#ifdef Q_WS_MAC

View File

@ -4,14 +4,9 @@ HEADERS += \
to_be_moved/qtextcontrol_p_p.h \
to_be_moved/qshortcut.h \
to_be_moved/qshortcutmap_p.h \
to_be_moved/qdrag.h \
to_be_moved/qdnd_p.h \
SOURCES += \
to_be_moved/qlinecontrol.cpp \
to_be_moved/qtextcontrol.cpp \
to_be_moved/qshortcut.cpp \
to_be_moved/qshortcutmap.cpp \
to_be_moved/qdrag.cpp \
to_be_moved/qdnd.cpp \
to_be_moved/qdnd_qpa.cpp \