summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2016-08-05 16:12:00 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2016-08-09 18:22:03 +0000
commit8ebe8ae35ee7556de0749bc27737ced7c61f5153 (patch)
tree9ecbdf77099629acd09fe1d127da7f379999c0b9 /src/plugins/platforms/cocoa
parentdb79b89899e6537d540e290beaed263c46e3a885 (diff)
HiDPI Drag and Drop: Properly render the default image on Mac
This is only when the attached MIME data contains text, and we fall back to rendering that text into a pixmap. It requires getting the device pixel ratio from the source which, for now, may be a QWidget or a QWindow. Other cases may exist, but that would bring more dependencies than desired. Similarly, it fixes the draggabletext example. Other examples would require either to get updated pixmaps or change substantially in order to support HiDPI (e.g., the fridgemagnets example). Change-Id: I66198214233e3e06c87505744e2aaa9691fe1bb6 Reviewed-by: Filipe Azevedo <filipe.azevedo@kdab.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoadrag.mm16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm
index 80006ae9b8..1e9c355788 100644
--- a/src/plugins/platforms/cocoa/qcocoadrag.mm
+++ b/src/plugins/platforms/cocoa/qcocoadrag.mm
@@ -34,6 +34,9 @@
#include "qcocoadrag.h"
#include "qmacclipboard.h"
#include "qcocoahelpers.h"
+#ifndef QT_NO_WIDGETS
+#include <QtWidgets/qwidget.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -181,7 +184,18 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const
const int width = fm.width(s);
const int height = fm.height();
if (width > 0 && height > 0) {
- pm = QPixmap(width, height);
+ qreal dpr = 1.0;
+ if (const QWindow *sourceWindow = qobject_cast<QWindow *>(drag->source())) {
+ dpr = sourceWindow->devicePixelRatio();
+ }
+#ifndef QT_NO_WIDGETS
+ else if (const QWidget *sourceWidget = qobject_cast<QWidget *>(drag->source())) {
+ if (const QWindow *sourceWindow = sourceWidget->window()->windowHandle())
+ dpr = sourceWindow->devicePixelRatio();
+ }
+#endif
+ pm = QPixmap(width * dpr, height * dpr);
+ pm.setDevicePixelRatio(dpr);
QPainter p(&pm);
p.fillRect(0, 0, pm.width(), pm.height(), Qt::color0);
p.setPen(Qt::color1);