From 07bbc4da320c7f4710af0139516b9c8bafe33c52 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 6 Aug 2014 09:02:13 +0200 Subject: Windows: Refactor QWindowsDragCursorWindow(). QWindowsDragCursorWindow is a helper window used to display the drag cursor when doing DnD by touch, in which case Windows hides the mouse cursor. Base it on QRasterWindow and fix the size calculation for device pixel ratio scaling. Task-number: QTBUG-38858 Task-number: QTBUG-38993 Change-Id: I462ece3e5c8fe8be914e039ba391a28a77e0d771 Reviewed-by: Laszlo Agocs --- src/plugins/platforms/windows/qwindowsdrag.cpp | 42 ++++++++------------------ 1 file changed, 13 insertions(+), 29 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsdrag.cpp b/src/plugins/platforms/windows/qwindowsdrag.cpp index 861ddbe5b6..716d892472 100644 --- a/src/plugins/platforms/windows/qwindowsdrag.cpp +++ b/src/plugins/platforms/windows/qwindowsdrag.cpp @@ -54,9 +54,7 @@ #include #include #include -#include -#include -#include +#include #include #include #include @@ -78,7 +76,7 @@ QT_BEGIN_NAMESPACE \ingroup qt-lighthouse-win */ -class QWindowsDragCursorWindow : public QWindow +class QWindowsDragCursorWindow : public QRasterWindow { public: explicit QWindowsDragCursorWindow(QWindow *parent = 0); @@ -86,18 +84,18 @@ public: void setPixmap(const QPixmap &p); protected: - void exposeEvent(QExposeEvent *); + void paintEvent(QPaintEvent *) + { + QPainter painter(this); + painter.drawPixmap(0, 0, m_pixmap); + } private: - void render(); - - QBackingStore m_backingStore; QPixmap m_pixmap; }; QWindowsDragCursorWindow::QWindowsDragCursorWindow(QWindow *parent) - : QWindow(parent) - , m_backingStore(this) + : QRasterWindow(parent) { QSurfaceFormat windowFormat = format(); windowFormat.setAlphaBufferSize(8); @@ -113,31 +111,17 @@ void QWindowsDragCursorWindow::setPixmap(const QPixmap &p) if (p.cacheKey() == m_pixmap.cacheKey()) return; const QSize oldSize = m_pixmap.size(); - const QSize newSize = p.size(); + QSize newSize = p.size(); qCDebug(lcQpaMime) << __FUNCTION__ << p.cacheKey() << newSize; m_pixmap = p; if (oldSize != newSize) { + const qreal pixDevicePixelRatio = p.devicePixelRatio(); + if (pixDevicePixelRatio > 1.0 && qFuzzyCompare(pixDevicePixelRatio, devicePixelRatio())) + newSize /= qRound(pixDevicePixelRatio); resize(newSize); - m_backingStore.resize(newSize); } if (isVisible()) - render(); -} - -void QWindowsDragCursorWindow::exposeEvent(QExposeEvent *) -{ - Q_ASSERT(!m_pixmap.isNull()); - render(); -} - -void QWindowsDragCursorWindow::render() -{ - const QRect rect(QPoint(0, 0), m_pixmap.size()); - m_backingStore.beginPaint(rect); - QPainter painter(m_backingStore.paintDevice()); - painter.drawPixmap(0, 0, m_pixmap); - m_backingStore.endPaint(); - m_backingStore.flush(rect); + update(); } /*! -- cgit v1.2.3