Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zergud committed Oct 19, 2023
1 parent 1f33f78 commit 2c7ea4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
47 changes: 30 additions & 17 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Schematic::Schematic(QucsApp *App_, const QString& Name_)
ViewX2=ViewY2=800;
UsedX1 = UsedY1 = INT_MAX;
UsedX2 = UsedY2 = INT_MIN;
zx1 = zx2 = zy1 = zy2 = 0;

tmpPosX = tmpPosY = -100;
tmpUsedX1 = tmpUsedY1 = tmpViewX1 = tmpViewY1 = -200;
Expand Down Expand Up @@ -797,25 +798,37 @@ void Schematic::showAll()
// ------------------------------------------------------
void Schematic::zoomToSelection()
{
sizeOfSelection(UsedX1, UsedY1, UsedX2, UsedY2);
if(UsedX1 == 0)
if(UsedX2 == 0)
if(UsedY1 == 0)
if(UsedY2 == 0) {
showAll();
return;
}
int x1, x2, y1, y2 = 0;
sizeOfSelection(x1, y1, x2, y2);
if (x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0) {
showAll();
return;
}

if (x1 == zx1 && x2 == zx2 && y1 == zy1 && y2 == zy2) {
return;
}

zx1 = x1;
zy1 = y1;
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 xScale = float(visibleWidth()) / float(UsedX2-UsedX1+80);
float yScale = float(visibleHeight()) / float(UsedY2-UsedY1+80);
if(xScale > yScale) xScale = yScale;
xScale /= Scale;
scale = zoom(scale / Scale);

ViewX1 = UsedX1 - 40;
ViewY1 = UsedY1 - 40;
ViewX2 = UsedX2 + 40;
ViewY2 = UsedY2 + 40;
zoom(xScale);
// 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);
}

// ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions qucs/schematic.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Schematic : public Q3ScrollView, public QucsDoc {
int GridX, GridY;
int ViewX1, ViewY1, ViewX2, ViewY2; // size of the document area
int UsedX1, UsedY1, UsedX2, UsedY2; // document area used by elements
int zx1, zy1, zx2, zy2; // cache for zoom to selection

int showFrame;
QString Frame_Text0, Frame_Text1, Frame_Text2, Frame_Text3;
Expand Down

0 comments on commit 2c7ea4e

Please sign in to comment.