From b80cd6a41736036e0946fd9065499fc9986f8efc Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 7 Mar 2022 15:04:18 +0100 Subject: [PATCH] DrawSketchHandler: refactor crosshairCursor ====================================================== -DrawSketchHandler manages both cursor bitmap setting and unsetting --- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 20 +++++++++++++++++--- src/Mod/Sketcher/Gui/DrawSketchHandler.h | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 95f640cd7f..46bf583c39 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -221,10 +221,20 @@ DrawSketchHandler::DrawSketchHandler() : sketchgui(nullptr) {} DrawSketchHandler::~DrawSketchHandler() {} +QString DrawSketchHandler::getCrosshairCursorString() const +{ + return QString::fromLatin1("None"); +} + void DrawSketchHandler::activate(ViewProviderSketch * vp) { sketchgui = vp; + auto cursorstring = getCrosshairCursorString(); + + if(cursorstring != QString::fromLatin1("None")) + setCrosshairCursor(cursorstring); + this->preActivated(); this->activated(); } @@ -280,8 +290,7 @@ unsigned long DrawSketchHandler::getCrosshairColor() return color; } -void DrawSketchHandler::setCrosshairCursor(const char* svgName) { - QString cursorName = QString::fromLatin1(svgName); +void DrawSketchHandler::setCrosshairCursor(const QString & svgName) { const unsigned long defaultCrosshairColor = 0xFFFFFF; unsigned long color = getCrosshairColor(); auto colorMapping = std::map(); @@ -289,7 +298,12 @@ void DrawSketchHandler::setCrosshairCursor(const char* svgName) { // hot spot of all SVG icons should be 8,8 for 32x32 size (16x16 for 64x64) int hotX = 8; int hotY = 8; - setSvgCursor(cursorName, hotX, hotY, colorMapping); + setSvgCursor(svgName, hotX, hotY, colorMapping); +} + +void DrawSketchHandler::setCrosshairCursor(const char* svgName) { + QString cursorName = QString::fromLatin1(svgName); + setCrosshairCursor(cursorName); } void DrawSketchHandler::setSvgCursor(const QString & cursorName, int x, int y, const std::map& colorMapping) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index 3bbc0f19c9..2357f4f5d4 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -148,6 +148,7 @@ private: virtual void activated(){} virtual void deactivated(){} virtual void postDeactivated(){} + virtual void onWidgetChanged(){} protected: // helpers @@ -166,6 +167,7 @@ protected: void applyCursor(QCursor &newCursor); unsigned long getCrosshairColor(); qreal devicePixelRatio(); + void setCrosshairCursor(const QString & svgName); void setCrosshairCursor(const char* svgName); void drawEdit(const std::vector &EditCurve); @@ -178,6 +180,7 @@ protected: int getPreselectCurve(void) const; int getPreselectCross(void) const; + virtual QString getCrosshairCursorString() const; /** * Returns constraints icons scaled to width.