From 2aa8e10ae29d117f06b34188fc9ccf10bff0f957 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 30 Aug 2023 03:54:13 -0400 Subject: [PATCH] do not allow to zoom in beyond 80% of screen height or width --- tools/lammps-gui/slideshow.cpp | 19 +++++++++++++++++-- tools/lammps-gui/slideshow.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/lammps-gui/slideshow.cpp b/tools/lammps-gui/slideshow.cpp index d949907668..d93b6fd052 100644 --- a/tools/lammps-gui/slideshow.cpp +++ b/tools/lammps-gui/slideshow.cpp @@ -15,12 +15,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -108,6 +110,10 @@ SlideShow::SlideShow(const QString &fileName, QWidget *parent) : scaleFactor = 1.0; current = 0; + auto maxsize = QGuiApplication::primaryScreen()->availableSize() * 4 / 5; + maxheight = maxsize.height(); + maxwidth = maxsize.width(); + setLayout(mainLayout); } @@ -149,7 +155,10 @@ void SlideShow::loadImage(int idx) Qt::SmoothTransformation); imageLabel->setPixmap(QPixmap::fromImage(image)); imageLabel->setMinimumSize(newwidth, newheight); - imageName->setText(imagefiles[idx]); + imageName->setText(QString(" Image %1 / %2 : %3 ") + .arg(idx + 1) + .arg(imagefiles.size()) + .arg(imagefiles[idx])); adjustSize(); current = idx; break; @@ -242,9 +251,15 @@ void SlideShow::normalSize() void SlideShow::scaleImage(double factor) { + // compute maxfactor so the image is not scaled beyond 80 of width or height of screen + double maxfactor = 10.0; + maxfactor = qMin((double)maxheight / (double)image.height(), maxfactor); + maxfactor = qMin((double)maxwidth / (double)image.width(), maxfactor); + + if (factor > maxfactor) factor = maxfactor; scaleFactor *= factor; - if (scaleFactor > 2.0) scaleFactor = 2.0; if (scaleFactor < 0.25) scaleFactor = 0.25; + loadImage(current); } diff --git a/tools/lammps-gui/slideshow.h b/tools/lammps-gui/slideshow.h index 1bf62a99bb..fe357ec564 100644 --- a/tools/lammps-gui/slideshow.h +++ b/tools/lammps-gui/slideshow.h @@ -54,6 +54,7 @@ private: double scaleFactor = 1.0; int current; + int maxwidth, maxheight; bool do_loop; QStringList imagefiles; };