Skip to content

Commit

Permalink
Add SVG icon for Sketcher Slot pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanuan committed Jul 23, 2020
1 parent fdfda05 commit 12d9fb4
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 57 deletions.
49 changes: 6 additions & 43 deletions src/Mod/Sketcher/Gui/CommandCreateGeo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
64 changes: 51 additions & 13 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gui::View3DInventor*>(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<Gui::View3DInventor*>(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);
Expand All @@ -118,14 +152,16 @@ void DrawSketchHandler::addCursorTail( std::vector<QPixmap> &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<Gui::View3DInventor*>(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;

Expand Down Expand Up @@ -162,7 +198,9 @@ void DrawSketchHandler::addCursorTail( std::vector<QPixmap> &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);
Expand Down Expand Up @@ -222,7 +260,7 @@ std::vector<QPixmap> DrawSketchHandler::suggestedConstraintsPixmaps(
}
if (!iconType.isEmpty()) {
QPixmap icon = Gui::BitmapFactory()
.pixmap(iconType.toLatin1());
.pixmap(iconType.toStdString().c_str());
pixmaps.push_back(icon);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Sketcher/Gui/DrawSketchHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPixmap> &pixmaps);
void unsetCursor(void);
void applyCursor(void);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Sketcher/Gui/Resources/Sketcher.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<file>icons/Sketcher_Move.svg</file>
<file>icons/Sketcher_NewSketch.svg</file>
<file alias="icons/preferences-sketcher.svg">icons/Sketcher_NewSketch.svg</file>
<file>icons/Sketcher_Pointer_Slot.svg</file>
<file>icons/Sketcher_Parabolic_Arc.svg</file>
<file>icons/Sketcher_Parabolic_Arc_Constr.svg</file>
<file>icons/Sketcher_ProfilesHexagon1.svg</file>
Expand Down

0 comments on commit 12d9fb4

Please sign in to comment.