Skip to content

Commit

Permalink
Sketcher: DrawSketchHandler - add getViewer function to drawsketchHan…
Browse files Browse the repository at this point in the history
…dler to simplify code.
  • Loading branch information
PaddleStroke authored and abdullahtahiriyo committed Oct 15, 2023
1 parent c62f5f3 commit 9538aaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Expand Up @@ -423,10 +423,8 @@ void DrawSketchHandler::setSvgCursor(const QString& cursorName,

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();

Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
QCursor cursor;
QPixmap p1(p);
// TODO remove autoScale after all cursors are SVG-based
Expand Down Expand Up @@ -529,28 +527,25 @@ void DrawSketchHandler::applyCursor()

void DrawSketchHandler::applyCursor(QCursor& newCursor)
{
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
viewer->getWidget()->setCursor(newCursor);
}
}

void DrawSketchHandler::unsetCursor()
{
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
viewer->getWidget()->setCursor(oldCursor);
}
}

qreal DrawSketchHandler::devicePixelRatio()
{
qreal pixelRatio = 1;
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
pixelRatio = viewer->devicePixelRatio();
}
return pixelRatio;
Expand Down Expand Up @@ -586,10 +581,8 @@ DrawSketchHandler::suggestedConstraintsPixmaps(std::vector<AutoConstraint>& sugg
}
if (!iconType.isEmpty()) {
qreal pixelRatio = 1;
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer =
static_cast<Gui::View3DInventor*>(view)->getViewer();
Gui::View3DInventorViewer* viewer = getViewer();
if (viewer) {
pixelRatio = viewer->devicePixelRatio();
}
int iconWidth = 16 * pixelRatio;
Expand Down Expand Up @@ -1171,3 +1164,12 @@ void DrawSketchHandler::signalToolChanged() const
{
ViewProviderSketchDrawSketchHandlerAttorney::signalToolChanged(*sketchgui, this->getToolName());
}

Gui::View3DInventorViewer* DrawSketchHandler::getViewer()
{
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
return static_cast<Gui::View3DInventor*>(view)->getViewer();
}
return nullptr;
}
8 changes: 8 additions & 0 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.h
Expand Up @@ -41,6 +41,11 @@ class Sketch;
class SketchObject;
} // namespace Sketcher

namespace Gui
{
class View3DInventorViewer;
}

namespace SketcherGui
{

Expand Down Expand Up @@ -246,6 +251,8 @@ class SketcherGuiExport DrawSketchHandler

void signalToolChanged() const;

Gui::View3DInventorViewer* getViewer();

private:
void setSvgCursor(const QString& svgName,
int x,
Expand All @@ -260,6 +267,7 @@ class SketcherGuiExport DrawSketchHandler
void setCrosshairCursor(const QString& svgName);
void setCrosshairCursor(const char* svgName);


protected:
/**
* Returns constraints icons scaled to width.
Expand Down

0 comments on commit 9538aaf

Please sign in to comment.