From 4af6c5a13eb3f00a223abd672c33b2a1ee514fb7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Jan 2021 19:19:30 +0100 Subject: [PATCH] Gui: [skip ci] update standard cursors of 3d view when device pixel ratio changes (e.g. by moving between standard and high DPI monitor) --- src/Gui/View3DInventorViewer.cpp | 57 ++++++++++++++++++-------------- src/Gui/View3DInventorViewer.h | 1 + 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 9c6de05ef1..5e4262e757 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -600,32 +600,12 @@ void View3DInventorViewer::init() } //create the cursors -#if defined(Q_OS_WIN32) - qreal dpr = qApp->devicePixelRatio(); + createStandardCursors(devicePixelRatio()); +#if (QT_VERSION >= 0x050000) + connect(this, &View3DInventorViewer::devicePixelRatioChanged, + this, &View3DInventorViewer::createStandardCursors); #endif - QBitmap cursor = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_bitmap); - QBitmap mask = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_mask_bitmap); -#if defined(Q_OS_WIN32) - cursor.setDevicePixelRatio(dpr); - mask.setDevicePixelRatio(dpr); -#endif - spinCursor = QCursor(cursor, mask, ROTATE_HOT_X, ROTATE_HOT_Y); - cursor = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_bitmap); - mask = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_mask_bitmap); -#if defined(Q_OS_WIN32) - cursor.setDevicePixelRatio(dpr); - mask.setDevicePixelRatio(dpr); -#endif - zoomCursor = QCursor(cursor, mask, ZOOM_HOT_X, ZOOM_HOT_Y); - - cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap); - mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap); -#if defined(Q_OS_WIN32) - cursor.setDevicePixelRatio(dpr); - mask.setDevicePixelRatio(dpr); -#endif - panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y); naviCube = new NaviCube(this); naviCubeEnabled = true; } @@ -699,6 +679,35 @@ View3DInventorViewer::~View3DInventorViewer() delete glAction; } +void View3DInventorViewer::createStandardCursors(double dpr) +{ + QBitmap cursor = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_bitmap); + QBitmap mask = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_mask_bitmap); +#if defined(Q_OS_WIN32) + cursor.setDevicePixelRatio(dpr); + mask.setDevicePixelRatio(dpr); +#else + Q_UNUSED(dpr) +#endif + spinCursor = QCursor(cursor, mask, ROTATE_HOT_X, ROTATE_HOT_Y); + + cursor = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_bitmap); + mask = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_mask_bitmap); +#if defined(Q_OS_WIN32) + cursor.setDevicePixelRatio(dpr); + mask.setDevicePixelRatio(dpr); +#endif + zoomCursor = QCursor(cursor, mask, ZOOM_HOT_X, ZOOM_HOT_Y); + + cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap); + mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap); +#if defined(Q_OS_WIN32) + cursor.setDevicePixelRatio(dpr); + mask.setDevicePixelRatio(dpr); +#endif + panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y); +} + void View3DInventorViewer::aboutToDestroyGLContext() { if (naviCube) { diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index c690b54346..97908837c8 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -426,6 +426,7 @@ private: static void drawArrow(void); void setCursorRepresentation(int mode); void aboutToDestroyGLContext(); + void createStandardCursors(double); private: NaviCube* naviCube;