summaryrefslogtreecommitdiffstats
path: root/viewer.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2019-11-24 05:12:38 +0100
committerArno <arno@disconnect.de>2019-11-24 05:12:38 +0100
commit45f5a502c1344cba2a3b90954d55d4ed37b3a619 (patch)
tree4c54eb0fed0497175ef28e1f668825ec3dd81f2d /viewer.cpp
parentaba0fd0107830a354e94d0404dd0cfb538df6ecb (diff)
downloadSheMov-45f5a502c1344cba2a3b90954d55d4ed37b3a619.tar.gz
SheMov-45f5a502c1344cba2a3b90954d55d4ed37b3a619.tar.bz2
SheMov-45f5a502c1344cba2a3b90954d55d4ed37b3a619.zip
Fix scaling images in viewer
Don't resize the image unconditionally. When doing that while keeping the aspect ratio, it may grow wider than the window/widget size. So check if it fits. If it doesn't scale down, otherwise leave it.
Diffstat (limited to 'viewer.cpp')
-rw-r--r--viewer.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/viewer.cpp b/viewer.cpp
index d0077f7..6a4f634 100644
--- a/viewer.cpp
+++ b/viewer.cpp
@@ -1,6 +1,5 @@
#include <QLabel>
#include <QHBoxLayout>
-#include <QDesktopWidget>
#include <QApplication>
#include <QFileInfo>
#include <QMimeDatabase>
@@ -11,14 +10,10 @@
#include "viewer.h"
Viewer::Viewer(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), mCurIndex(-1) {
- QDesktopWidget *dw = qApp->desktop();
setAutoFillBackground(true);
setBackgroundRole(QPalette::AlternateBase);
mLabel = new QLabel;
mLabel->setAlignment(Qt::AlignCenter);
- mMaxSize = dw->size();
- //90 is an arbitrary value, but it works :)
- mMaxSize.setHeight(mMaxSize.height() - 90);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(mLabel);
setLayout(mainLayout);
@@ -97,7 +92,9 @@ void Viewer::displayFile(int index){
setBackgroundRole(QPalette::AlternateBase);
}
QPixmap pm(mFiles.at(mCurIndex));
- pm = pm.scaled(mMaxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ if((pm.height() > height()) || (pm.width() > width())){
+ pm = pm.scaled(QSize(width() - 20, height() - 20), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
mLabel->setPixmap(pm);
QString winTitle = QString(tr("%1 Viewer [%2]")).arg(qApp->applicationName()).arg(mFiles.at(mCurIndex));
setWindowTitle(winTitle);