do not allow to zoom in beyond 80% of screen height or width

This commit is contained in:
Axel Kohlmeyer
2023-08-30 03:54:13 -04:00
parent 07efb5b015
commit 2aa8e10ae2
2 changed files with 18 additions and 2 deletions

View File

@ -15,12 +15,14 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFileInfo> #include <QFileInfo>
#include <QGuiApplication>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QImage> #include <QImage>
#include <QImageReader> #include <QImageReader>
#include <QLabel> #include <QLabel>
#include <QPalette> #include <QPalette>
#include <QPushButton> #include <QPushButton>
#include <QScreen>
#include <QSettings> #include <QSettings>
#include <QShortcut> #include <QShortcut>
#include <QSpacerItem> #include <QSpacerItem>
@ -108,6 +110,10 @@ SlideShow::SlideShow(const QString &fileName, QWidget *parent) :
scaleFactor = 1.0; scaleFactor = 1.0;
current = 0; current = 0;
auto maxsize = QGuiApplication::primaryScreen()->availableSize() * 4 / 5;
maxheight = maxsize.height();
maxwidth = maxsize.width();
setLayout(mainLayout); setLayout(mainLayout);
} }
@ -149,7 +155,10 @@ void SlideShow::loadImage(int idx)
Qt::SmoothTransformation); Qt::SmoothTransformation);
imageLabel->setPixmap(QPixmap::fromImage(image)); imageLabel->setPixmap(QPixmap::fromImage(image));
imageLabel->setMinimumSize(newwidth, newheight); 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(); adjustSize();
current = idx; current = idx;
break; break;
@ -242,9 +251,15 @@ void SlideShow::normalSize()
void SlideShow::scaleImage(double factor) 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; scaleFactor *= factor;
if (scaleFactor > 2.0) scaleFactor = 2.0;
if (scaleFactor < 0.25) scaleFactor = 0.25; if (scaleFactor < 0.25) scaleFactor = 0.25;
loadImage(current); loadImage(current);
} }

View File

@ -54,6 +54,7 @@ private:
double scaleFactor = 1.0; double scaleFactor = 1.0;
int current; int current;
int maxwidth, maxheight;
bool do_loop; bool do_loop;
QStringList imagefiles; QStringList imagefiles;
}; };