Skip to content

Commit

Permalink
window maximized when zoomed in
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharindam committed Dec 6, 2019
1 parent 6fd6e7b commit 761f52b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ void
Canvas:: showScaled()
{
QPixmap pm = QPixmap::fromImage(image);
if (scale != 1.0)
pm = pm.scaledToHeight(scale*pm.height(), Qt::SmoothTransformation);
if (scale != 1.0) {
Qt::TransformationMode mode = floorf(scale) == ceilf(scale)? // integer scale
Qt::FastTransformation : Qt::SmoothTransformation;
pm = pm.scaledToHeight(scale*pm.height(), mode);
}
setPixmap(pm);
emit imageUpdated();
}
Expand All @@ -71,13 +74,6 @@ Canvas:: rotate(int degree, Qt::Axis axis)
showScaled();
}

void
Canvas:: zoomBy(float factor)
{
scale *= factor;
showScaled();
}

void
Canvas:: mousePressEvent(QMouseEvent *ev)
{
Expand Down
1 change: 0 additions & 1 deletion src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Canvas : public QLabel
void setImage(QImage img);
void showScaled();
void rotate(int degree, Qt::Axis axis=Qt::ZAxis);
void zoomBy(float factor);
// Variables
QImage image;
bool animation;
Expand Down
19 changes: 17 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,15 @@ Window:: zoomInImage()
bool wasVisibleH = horizontal->isVisible();
if (not wasVisibleV) relPosV=0.5;
if (not wasVisibleH) relPosH=0.5;
canvas->zoomBy(6.0/5);
// Integer scale to view small icons
if (canvas->image.width() < 200 and canvas->image.height() < 200 and canvas->scale>=1)
canvas->scale += 1;
else
canvas->scale *= (6.0/5);
canvas->showScaled();
if ((canvas->pixmap()->width()>scrollArea->width() or
canvas->pixmap()->height()>scrollArea->height()) && not this->isMaximized())
this->showMaximized();
waitFor(30);
vertical->setValue(vertical->maximum()*relPosV);
horizontal->setValue(horizontal->maximum()*relPosH);
Expand All @@ -418,7 +426,11 @@ Window:: zoomOutImage()
QScrollBar *horizontal = scrollArea->horizontalScrollBar();
float relPosV = vertical->value()/(float)vertical->maximum();
float relPosH = horizontal->value()/(float)horizontal->maximum();
canvas->zoomBy(5.0/6);
if (canvas->image.width() < 200 and canvas->image.height() < 200 and canvas->scale>1)
canvas->scale -= 1;
else
canvas->scale *= (5.0/6);
canvas->showScaled();
waitFor(30);
vertical->setValue(vertical->maximum()*relPosV);
horizontal->setValue(horizontal->maximum()*relPosH);
Expand All @@ -437,6 +449,9 @@ Window:: origSizeImage()
canvas->scale = 1.0;
canvas->showScaled();
origSizeBtn->setIcon(QIcon(":/images/fit-to-screen.png"));
if ((canvas->pixmap()->width()>scrollArea->width() or
canvas->pixmap()->height()>scrollArea->height()) && not this->isMaximized())
this->showMaximized();
}

void
Expand Down

0 comments on commit 761f52b

Please sign in to comment.