From 12d9fb459f3363f09bd5f4a20372086e6fcee299 Mon Sep 17 00:00:00 2001 From: Vanuan Date: Tue, 21 Jul 2020 22:53:02 +0300 Subject: [PATCH] Add SVG icon for Sketcher Slot pointer --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 49 +--- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 64 ++++- src/Mod/Sketcher/Gui/DrawSketchHandler.h | 5 +- src/Mod/Sketcher/Gui/Resources/Sketcher.qrc | 1 + .../Resources/icons/Sketcher_Pointer_Slot.svg | 253 ++++++++++++++++++ 5 files changed, 315 insertions(+), 57 deletions(-) create mode 100644 src/Mod/Sketcher/Gui/Resources/icons/Sketcher_Pointer_Slot.svg diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 02ed035a276d2..30dd1ed109305 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -6836,47 +6836,9 @@ static const char *cursor_carboncopy[]={ } -/* Create Slot =======================================================*/ - -/* XPM */ -static const char *cursor_creatslot[]={ -"32 32 3 1", -cursor_crosshair_color, -"# c red", -". c None", -"......+.........................", -"......+.........................", -"......+.........................", -"......+.........................", -"......+.........................", -"................................", -"+++++...+++++...................", -"................................", -"......+.........................", -"......+.........................", -"......+.........................", -"......+.........................", -"......+.........................", -"................................", -"................................", -"..........................###...", -"........###################.##..", -".......#..................###.#.", -"......#........................#", -".....#.........................#", -"....#.....###..................#", -"....#.....#.#..................#", -".....#....###.................#.", -"......#.......................#.", -".......#.....................#..", -"........#####################...", -"................................", -"................................", -"................................", -"................................", -"................................", -"................................"}; - +/** + * Create Slot + */ class DrawSketchHandlerSlot: public DrawSketchHandler { public: @@ -6896,8 +6858,9 @@ class DrawSketchHandlerSlot: public DrawSketchHandler virtual void activated(ViewProviderSketch *) { - setCrosshairColor(); - setCursor(QPixmap(cursor_creatslot),7,7); + setCrosshairColor(); // TODO handle when rendering SVG + QString cursorName = QString::fromLatin1("Sketcher_Pointer_Slot"); + setSvgCursor(cursorName,7,7); } virtual void mouseMove(Base::Vector2d onSketchPos) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 9728aa20b453f..4c404da2ee938 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -91,23 +91,57 @@ int DrawSketchHandler::getHighestCurveIndex(void) return sketchgui->getSketchObject()->getHighestCurveIndex(); } -void DrawSketchHandler::setCursor(const QPixmap &p,int x,int y) + +void DrawSketchHandler::setSvgCursor(const QString & cursorName, int x, int y) { + qreal pRatio = 1; +#if QT_VERSION >= 0x050000 Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { Gui::View3DInventorViewer* viewer = static_cast(view)->getViewer(); + pRatio = viewer->devicePixelRatio(); + } +#endif + qreal defaultCursorSize = 32; + qreal hotX = x * pRatio; + qreal hotY = y * pRatio; + qreal cursorSize = defaultCursorSize * pRatio; - oldCursor = viewer->getWidget()->cursor(); - QPixmap p1(p); + QPixmap pointer = Gui::BitmapFactory().pixmapFromSvg(cursorName.toStdString().c_str(), QSize(cursorSize, cursorSize)); +#if QT_VERSION >= 0x050000 + pointer.setDevicePixelRatio(pRatio); +#endif - qreal pRatio = viewer->devicePixelRatio(); + setCursor(pointer, hotX, hotY, false); - int newWidth = p.width()*pRatio; - int newHeight = p.height()*pRatio; - p1 = p1.scaled(newWidth, newHeight,Qt::KeepAspectRatio,Qt::SmoothTransformation); - p1.setDevicePixelRatio(pRatio); +} + +void DrawSketchHandler::setCursor(const QPixmap &p,int x,int y, bool autoScale) +{ + Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); + if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { + Gui::View3DInventorViewer* viewer = static_cast(view)->getViewer(); + + oldCursor = viewer->getWidget()->cursor(); + + QCursor cursor; + if (autoScale) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + QPixmap p1(p); + qreal pRatio = viewer->devicePixelRatio(); + int newWidth = p.width()*pRatio; + int newHeight = p.height()*pRatio; + p1 = p1.scaled(newWidth, newHeight,Qt::KeepAspectRatio,Qt::SmoothTransformation); + p1.setDevicePixelRatio(pRatio); + + cursor = QCursor(p1, x * pRatio, y * pRatio); +#else + cursor = QCursor(p, x, y); +#endif + } else { + cursor = QCursor(p, x, y); + } - QCursor cursor(p1, x * pRatio, y * pRatio); actCursor = cursor; viewer->getWidget()->setCursor(cursor); @@ -118,14 +152,16 @@ void DrawSketchHandler::addCursorTail( std::vector &pixmaps ) { // Create a pixmap that will contain icon and each autoconstraint icon Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { - Gui::View3DInventorViewer* viewer = static_cast(view)->getViewer(); QPixmap baseIcon = QPixmap(actCursor.pixmap()); +#if QT_VERSION >= 0x050000 + qreal pixelRatio = baseIcon.devicePixelRatio(); +#else + qreal pixelRatio = 1; +#endif // cursor size in device independent pixels - qreal pixelRatio = viewer->devicePixelRatio(); qreal baseCursorWidth = baseIcon.width() / pixelRatio; qreal baseCursorHeight = baseIcon.width() / pixelRatio; - int iconWidth = 16; int tailWidth = pixmaps.size() * iconWidth; @@ -162,7 +198,9 @@ void DrawSketchHandler::addCursorTail( std::vector &pixmaps ) { qreal newWidth = newIcon.width()*pixelRatio; qreal newHeight = newIcon.height()*pixelRatio; newIcon = newIcon.scaled(newWidth, newHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) newIcon.setDevicePixelRatio(pixelRatio); +#endif QCursor newCursor(newIcon, p.x(), p.y()); applyCursor(newCursor); @@ -222,7 +260,7 @@ std::vector DrawSketchHandler::suggestedConstraintsPixmaps( } if (!iconType.isEmpty()) { QPixmap icon = Gui::BitmapFactory() - .pixmap(iconType.toLatin1()); + .pixmap(iconType.toStdString().c_str()); pixmaps.push_back(icon); } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index c7412d676f7fb..60dff7d93506d 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -97,8 +97,11 @@ class SketcherGuiExport DrawSketchHandler /** * Sets a cursor for 3D inventor view. * pixmap as a cursor image in device independent pixels. + * + * \param autoScale - set this to false if pixmap already scaled for HiDPI **/ - void setCursor( const QPixmap &pixmap, int x,int y ); + void setCursor( const QPixmap &pixmap, int x,int y, bool autoScale=true ); + void setSvgCursor( const QString &svgName, int x, int y); void addCursorTail(std::vector &pixmaps); void unsetCursor(void); void applyCursor(void); diff --git a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc index 6d3d65165f2c7..cfd62cb492444 100644 --- a/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc +++ b/src/Mod/Sketcher/Gui/Resources/Sketcher.qrc @@ -159,6 +159,7 @@ icons/Sketcher_Move.svg icons/Sketcher_NewSketch.svg icons/Sketcher_NewSketch.svg + icons/Sketcher_Pointer_Slot.svg icons/Sketcher_Parabolic_Arc.svg icons/Sketcher_Parabolic_Arc_Constr.svg icons/Sketcher_ProfilesHexagon1.svg diff --git a/src/Mod/Sketcher/Gui/Resources/icons/Sketcher_Pointer_Slot.svg b/src/Mod/Sketcher/Gui/Resources/icons/Sketcher_Pointer_Slot.svg new file mode 100644 index 0000000000000..f65c9f587a7ce --- /dev/null +++ b/src/Mod/Sketcher/Gui/Resources/icons/Sketcher_Pointer_Slot.svg @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [bitacovir] + + + Sketcher_CreateSlot + + + + + FreeCAD + + + + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + + + + + + + + + + + + + + + + + + + +