summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qdnd.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-09-20 18:10:39 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-21 12:07:19 +0200
commitc9c33bd227f0199b368d92131a0ee566d2651061 (patch)
tree8e0bc6559f5cc6cdcc8b0912f76904aded83df37 /src/gui/kernel/qdnd.cpp
parent0d4918950e61f3cbfd01c9fae37c463352c69dd3 (diff)
Fix support for drag pixmaps
Re-add the support for drag pixmaps to qdnd. Use the new WindowTransparentForMouseEvents flag for the window that shows the drag pixmap. Change-Id: I4b594085c161475988b9be0ffdc02c75fcc37f66 Reviewed-on: http://codereview.qt-project.org/5261 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/gui/kernel/qdnd.cpp')
-rw-r--r--src/gui/kernel/qdnd.cpp68
1 files changed, 46 insertions, 22 deletions
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp
index 4ed2515115..9a90c213cf 100644
--- a/src/gui/kernel/qdnd.cpp
+++ b/src/gui/kernel/qdnd.cpp
@@ -51,6 +51,7 @@
#include "qpoint.h"
#include "qbuffer.h"
#include "qimage.h"
+#include "qpainter.h"
#include "qregexp.h"
#include "qdir.h"
#include "qdnd_p.h"
@@ -277,7 +278,6 @@ QObject *QDragManager::currentTarget()
}
-static QPixmap *defaultPm = 0;
static const int default_pm_hotx = -2;
static const int default_pm_hoty = -16;
static const char *const default_pm[] = {
@@ -297,39 +297,65 @@ static const char *const default_pm[] = {
};
+QShapedPixmapWindow::QShapedPixmapWindow()
+ : QWindow()
+{
+ setSurfaceType(RasterSurface);
+ setWindowFlags(Qt::Tool | Qt::FramelessWindowHint |
+ Qt::X11BypassWindowManagerHint | Qt::WindowTransparentForInput);
+ create();
+ backingStore = new QBackingStore(this);
+}
+
+void QShapedPixmapWindow::render()
+{
+ QRect rect(QPoint(), geometry().size());
+ backingStore->resize(rect.size());
+
+ backingStore->beginPaint(rect);
+
+ QPaintDevice *device = backingStore->paintDevice();
+
+ {
+ QPainter p(device);
+ p.drawPixmap(0, 0, pixmap);
+ }
+
+ backingStore->endPaint();
+ backingStore->flush(rect);
+}
+
+
+
+
static Qt::KeyboardModifiers oldstate;
void QDragManager::updatePixmap()
{
if (shapedPixmapWindow) {
- QPixmap pm;
- QPoint pm_hot(default_pm_hotx,default_pm_hoty);
+ shapedPixmapWindow->pixmap = QPixmap();
+ shapedPixmapWindow->hotSpot = QPoint(default_pm_hotx,default_pm_hoty);
if (object) {
- pm = object->pixmap();
- if (!pm.isNull())
- pm_hot = object->hotSpot();
- }
- if (pm.isNull()) {
- if (!defaultPm)
- defaultPm = new QPixmap(default_pm);
- pm = *defaultPm;
- }
- shapedPixmapWindow->setPixmap(pm);
- shapedPixmapWindow->move(QCursor::pos()-pm_hot);
- if (willDrop) {
- shapedPixmapWindow->show();
- } else {
- shapedPixmapWindow->hide();
+ shapedPixmapWindow->pixmap = object->pixmap();
+ if (!shapedPixmapWindow->pixmap.isNull())
+ shapedPixmapWindow->hotSpot = object->hotSpot();
}
+ if (shapedPixmapWindow->pixmap.isNull())
+ shapedPixmapWindow->pixmap = QPixmap(default_pm);
+ shapedPixmapWindow->setGeometry(QRect(QCursor::pos() - shapedPixmapWindow->hotSpot, shapedPixmapWindow->pixmap.size()));
+ shapedPixmapWindow->show();
+ shapedPixmapWindow->render();
}
}
void QDragManager::updateCursor()
{
+ if (shapedPixmapWindow) {
+ shapedPixmapWindow->render(); // ### Hack
+ shapedPixmapWindow->move(QCursor::pos() - shapedPixmapWindow->hotSpot);
+ }
#ifndef QT_NO_CURSOR
if (willDrop) {
- if (shapedPixmapWindow)
- shapedPixmapWindow->show();
if (currentActionForOverrideCursor != global_accepted_action) {
QGuiApplication::changeOverrideCursor(QCursor(dragCursor(global_accepted_action), 0, 0));
currentActionForOverrideCursor = global_accepted_action;
@@ -340,8 +366,6 @@ void QDragManager::updateCursor()
QGuiApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor));
currentActionForOverrideCursor = Qt::IgnoreAction;
}
- if (shapedPixmapWindow)
- shapedPixmapWindow->hide();
}
#endif
}