From 5cae6597b35519b69ae9aca05feda73845269b60 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Fri, 16 Sep 2022 18:17:51 -0400 Subject: [PATCH] [TD]position view within clip group --- src/Mod/TechDraw/App/DrawView.cpp | 8 ++++++++ src/Mod/TechDraw/App/DrawView.h | 1 + src/Mod/TechDraw/App/DrawViewClip.cpp | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 33d066912d..bdfef28822 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -224,6 +224,14 @@ QRectF DrawView::getRect() const return result; } +//get the rectangle centered on the position +QRectF DrawView::getRectAligned() const +{ + double top = Y.getValue() + 0.5 * getRect().height(); + double left = X.getValue() - 0.5 * getRect().width(); + return {left, top, getRect().width(), - getRect().height()}; +} + void DrawView::onDocumentRestored() { handleXYLock(); diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 3d24d03548..74567071da 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -89,6 +89,7 @@ public: virtual std::vector findAllParentPages() const; virtual int countParentPages() const; virtual QRectF getRect() const; //must be overridden by derived class + QRectF getRectAligned() const; virtual double autoScale() const; virtual double autoScale(double w, double h) const; virtual bool checkFit() const; diff --git a/src/Mod/TechDraw/App/DrawViewClip.cpp b/src/Mod/TechDraw/App/DrawViewClip.cpp index dbe70f735b..d395f57ef7 100644 --- a/src/Mod/TechDraw/App/DrawViewClip.cpp +++ b/src/Mod/TechDraw/App/DrawViewClip.cpp @@ -80,9 +80,23 @@ void DrawViewClip::addView(DrawView *view) std::vector newViews(currViews); newViews.push_back(view); Views.setValues(newViews); - view->X.setValue(0.0); //position in centre of clip group frame - view->Y.setValue(0.0); - auto page = findParentPage(); //get Page to release child relationship in tree + QRectF viewRect = view->getRectAligned(); + QPointF clipPoint(X.getValue(), Y.getValue()); + if (viewRect.contains(clipPoint)) { + //position so the part of view that is overlapped by clip frame + //stays in the clip frame + double deltaX = view->X.getValue() - X.getValue(); + double deltaY = view->Y.getValue() - Y.getValue(); + view->X.setValue(deltaX); + view->Y.setValue(deltaY); + } else { + //position in centre of clip group frame + view->X.setValue(0.0); + view->Y.setValue(0.0); + } + + //reparent view to clip in tree + auto page = findParentPage(); page->Views.touch(); }