[TD]position view within clip group

This commit is contained in:
wandererfan
2022-09-16 18:17:51 -04:00
committed by WandererFan
parent 3600a6806d
commit 5cae6597b3
3 changed files with 26 additions and 3 deletions

View File

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

View File

@@ -89,6 +89,7 @@ public:
virtual std::vector<DrawPage*> 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;

View File

@@ -80,9 +80,23 @@ void DrawViewClip::addView(DrawView *view)
std::vector<App::DocumentObject *> 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();
}