Skip to content

Commit

Permalink
working solution
Browse files Browse the repository at this point in the history
  • Loading branch information
zergud committed Oct 19, 2023
1 parent 2c7ea4e commit b54d54a
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,21 +814,36 @@ void Schematic::zoomToSelection()
zx2 = x2;
zy2 = y2;

float xScale = float(visibleWidth()) / float(x2 - x1 + 80);
float yScale = float(visibleHeight()) / float(y2 - y1 + 80);
float scale = qMin(xScale, yScale);

ViewX1 = x1 - 40;
ViewY1 = y1 - 40;
ViewX2 = x2 + 40;
ViewY2 = y2 + 40;
float initialScale = Scale;
float scale = 1;
float xShift = 0;
float yShift = 0;

float ax1 = (x2 - ViewX1) * initialScale;
float ay1 = (y2 - ViewY1) * initialScale;
float DX = float(x2 - x1);
float DY = float(y2 - y1);

if((Scale * DX) < 6.0) {
// a simple click zooms by constant factor
scale = zoom(1.5)/initialScale;

xShift = scale * x2;
yShift = scale * x2;
} else {
float xScale = float(visibleWidth()) / std::abs(DX);
float yScale = float(visibleHeight()) / std::abs(DY);
scale = qMin(xScale, yScale)/initialScale;
scale = zoom(scale)/initialScale;

scale = zoom(scale / Scale);
xShift = scale * (ax1 - 0.5*DX);
yShift = scale * (ay1 - 0.5*DY);
}
xShift -= (0.5*visibleWidth() + contentsX());
yShift -= (0.5*visibleHeight() + contentsY());
scrollBy(xShift, yShift);

// float xShift = scale * (x2 - 0.5 * (x2 - x1)) - (0.5 * visibleWidth() + contentsX());
// float yShift = scale * (y2 - 0.5 * (y2 - y1)) - (0.5 * visibleHeight() + contentsY());
//
// scrollBy(xShift, yShift);
releaseKeyboard(); // allow keyboard inputs again
}

// ---------------------------------------------------
Expand Down

0 comments on commit b54d54a

Please sign in to comment.