From 8ebe8ae35ee7556de0749bc27737ced7c61f5153 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 5 Aug 2016 16:12:00 -0700 Subject: HiDPI Drag and Drop: Properly render the default image on Mac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoadrag.mm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') 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 +#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(drag->source())) { + dpr = sourceWindow->devicePixelRatio(); + } +#ifndef QT_NO_WIDGETS + else if (const QWidget *sourceWidget = qobject_cast(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); -- cgit v1.2.3