diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-06-05 23:29:26 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-06-07 15:50:53 +0200 |
commit | c3f9de62966d32d8e33d62eb374fe2657a4cfebe (patch) | |
tree | e8c36f4d887d3647a2ff71fd534cc1a550553822 /src/gui | |
parent | 30b7c6512cde501e0e5da6e2a6dd2d8113092269 (diff) |
Implement XDnD in the xcb plugin
Ported most of the code to support dragging
from qdnd_x11.cpp to xcb. Some features are still
not working 100% correct, but it's becoming
usable.
Reviewed-by: Samuel
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qdnd.cpp | 68 | ||||
-rw-r--r-- | src/gui/kernel/qdnd_p.h | 41 |
2 files changed, 55 insertions, 54 deletions
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp index 793c2e87d5..8ce4f119c0 100644 --- a/src/gui/kernel/qdnd.cpp +++ b/src/gui/kernel/qdnd.cpp @@ -143,6 +143,7 @@ QDragManager::QDragManager() #ifdef Q_WS_X11 xdndMimeTransferedPixmapIndex = 0; #endif + shapedPixmapWindow = 0; possible_actions = Qt::IgnoreAction; @@ -298,50 +299,9 @@ static const char *const default_pm[] = { static Qt::KeyboardModifiers oldstate; -class QShapedPixmapWindow : public QWindow { - QPixmap pixmap; -public: - QShapedPixmapWindow() : - QWindow(0) - { - 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(); -// } - setGeometry(QRect(geometry().topLeft(), pm.size())); - } - - // ### Get it painted again! -// void paintEvent(QPaintEvent*) -// { -// QPainter p(this); -// p.drawPixmap(0,0,pixmap); -// } -}; - - -static QShapedPixmapWindow *qt_qws_dnd_deco = 0; - - void QDragManager::updatePixmap() { - if (qt_qws_dnd_deco) { + if (shapedPixmapWindow) { QPixmap pm; QPoint pm_hot(default_pm_hotx,default_pm_hoty); if (object) { @@ -354,12 +314,12 @@ void QDragManager::updatePixmap() defaultPm = new QPixmap(default_pm); pm = *defaultPm; } - qt_qws_dnd_deco->setPixmap(pm); - qt_qws_dnd_deco->move(QCursor::pos()-pm_hot); + shapedPixmapWindow->setPixmap(pm); + shapedPixmapWindow->move(QCursor::pos()-pm_hot); if (willDrop) { - qt_qws_dnd_deco->show(); + shapedPixmapWindow->show(); } else { - qt_qws_dnd_deco->hide(); + shapedPixmapWindow->hide(); } } } @@ -368,8 +328,8 @@ void QDragManager::updateCursor() { #ifndef QT_NO_CURSOR if (willDrop) { - if (qt_qws_dnd_deco) - qt_qws_dnd_deco->show(); + if (shapedPixmapWindow) + shapedPixmapWindow->show(); if (currentActionForOverrideCursor != global_accepted_action) { QGuiApplication::changeOverrideCursor(QCursor(dragCursor(global_accepted_action), 0, 0)); currentActionForOverrideCursor = global_accepted_action; @@ -380,8 +340,8 @@ void QDragManager::updateCursor() QGuiApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor)); currentActionForOverrideCursor = Qt::IgnoreAction; } - if (qt_qws_dnd_deco) - qt_qws_dnd_deco->hide(); + if (shapedPixmapWindow) + shapedPixmapWindow->hide(); } #endif } @@ -468,8 +428,8 @@ Qt::DropAction QDragManager::drag(QDrag *o) } object = o; - if (!qt_qws_dnd_deco) - qt_qws_dnd_deco = new QShapedPixmapWindow(); + if (!shapedPixmapWindow) + shapedPixmapWindow = new QShapedPixmapWindow(); oldstate = Qt::NoModifier; // #### Should use state that caused the drag // drag_mode = mode; @@ -494,8 +454,8 @@ Qt::DropAction QDragManager::drag(QDrag *o) delete eventLoop; eventLoop = 0; - delete qt_qws_dnd_deco; - qt_qws_dnd_deco = 0; + delete shapedPixmapWindow; + shapedPixmapWindow = 0; return global_accepted_action; } diff --git a/src/gui/kernel/qdnd_p.h b/src/gui/kernel/qdnd_p.h index 3ba2869a8f..2eebcf6158 100644 --- a/src/gui/kernel/qdnd_p.h +++ b/src/gui/kernel/qdnd_p.h @@ -59,6 +59,7 @@ #include "QtGui/qdrag.h" #include "QtGui/qpixmap.h" #include "QtGui/qcursor.h" +#include "QtGui/qwindow.h" #include "QtCore/qpoint.h" #include "private/qobject_p.h" @@ -108,6 +109,44 @@ public: Qt::DropAction defaultDropAction; }; +class QShapedPixmapWindow : public QWindow { + QPixmap pixmap; +public: + QShapedPixmapWindow() : + QWindow(0) + { + 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(); +// } + setGeometry(QRect(geometry().topLeft(), pm.size())); + } + + // ### Get it painted again! +// void paintEvent(QPaintEvent*) +// { +// QPainter p(this); +// p.drawPixmap(0,0,pixmap); +// } +}; + + class Q_GUI_EXPORT QDragManager : public QObject { Q_OBJECT @@ -159,6 +198,8 @@ public: // Shift/Ctrl handling, and final drop status Qt::DropAction global_accepted_action; + QShapedPixmapWindow *shapedPixmapWindow; + private: QMimeData *platformDropData; |