From 3f14c4198dd29b3428e37befe5aec5fa8c5bcf68 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 2 Jul 2022 21:14:23 +0200 Subject: Set fixed size for viewer.cpp While adding new pictures to my collection, I realized that the simple viewer didn't obey it's size restrictions and grew out of proportions. So make the maximum size configurable. --- viewer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'viewer.cpp') diff --git a/viewer.cpp b/viewer.cpp index cba6314..e11a02f 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "helper.h" #include "viewer.h" @@ -14,6 +15,10 @@ Viewer::Viewer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mCurInd setBackgroundRole(QPalette::AlternateBase); mLabel = new QLabel; mLabel->setAlignment(Qt::AlignCenter); + QSettings s; + int maxHeight = s.value("ui/maxheight").toInt(); + int maxWidth = s.value("ui/maxwidth").toInt(); + mMaxSize = QSize(maxWidth, maxHeight); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(mLabel); setLayout(mainLayout); @@ -92,8 +97,8 @@ void Viewer::displayFile(int index){ setBackgroundRole(QPalette::AlternateBase); } QPixmap pm(mFiles.at(mCurIndex)); - if((pm.height() > height()) || (pm.width() > width())){ - pm = pm.scaled(QSize(width() - 20, height() - 20), Qt::KeepAspectRatio, Qt::SmoothTransformation); + if(pm.height() > mMaxSize.height() || pm.width() > mMaxSize.width()){ + pm = pm.scaled(mMaxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } mLabel->setPixmap(pm); QString winTitle = QString(tr("%1 Viewer [%2]")).arg(qApp->applicationName(), mFiles.at(mCurIndex)); -- cgit v1.2.3-70-g09d2