From 45d28c2367f5714cf5463b3373979c2a6f2779bf Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 19 Aug 2020 19:58:36 +0200 Subject: [PATCH] Sketcher: workaround for cursor pixmaps created from SVG icons --- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index bb538de686..365677c2de 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -102,13 +102,21 @@ void DrawSketchHandler::setCrosshairCursor(const char* svgName) { void DrawSketchHandler::setSvgCursor(const QString & cursorName, int x, int y, const std::map& colorMapping) { + // The Sketcher_Pointer_*.svg icons have a default size of 64x64. When directly creating + // them with a size of 32x32 they look very bad. + // As a workaround the icons are created with 64x64 and afterwards the pixmap is scaled to + // 32x32. This workaround is only needed if pRatio is equal to 1.0 + // qreal pRatio = devicePixelRatio(); - qreal defaultCursorSize = 32; - qreal hotX = x * pRatio; - qreal hotY = y * pRatio; + bool isRatioOne = (pRatio == 1.0); + qreal defaultCursorSize = isRatioOne ? 64 : 32; + qreal hotX = x * pRatio; + qreal hotY = y * pRatio; qreal cursorSize = defaultCursorSize * pRatio; QPixmap pointer = Gui::BitmapFactory().pixmapFromSvg(cursorName.toStdString().c_str(), QSizeF(cursorSize, cursorSize), colorMapping); + if (isRatioOne) + pointer = pointer.scaled(32, 32); #if QT_VERSION >= 0x050000 pointer.setDevicePixelRatio(pRatio); #endif @@ -135,7 +143,7 @@ void DrawSketchHandler::setCursor(const QPixmap &p,int x,int y, bool autoScale) #endif int newWidth = p.width()*pRatio; int newHeight = p.height()*pRatio; - p1 = p1.scaled(newWidth, newHeight,Qt::KeepAspectRatio,Qt::SmoothTransformation); + p1 = p1.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) p1.setDevicePixelRatio(pRatio); #endif