From 232181eef7980e46175c97542612b6f4278ab590 Mon Sep 17 00:00:00 2001 From: Felix Kauselmann Date: Wed, 2 Sep 2020 09:15:29 +0200 Subject: [PATCH] Reader: Add option to stop enlarging images in fit to width and height --- CHANGELOG.md | 3 +++ YACReader/configuration.cpp | 8 -------- YACReader/configuration.h | 10 ---------- YACReader/main_window_viewer.cpp | 1 + YACReader/options_dialog.cpp | 33 +++++++++++++++----------------- YACReader/options_dialog.h | 1 + YACReader/viewer.cpp | 13 ++++++++----- common/yacreader_global_gui.h | 2 ++ 8 files changed, 30 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d1dca92..96a27f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ spanish only. Sorry for the mess. Version counting is based on semantic versioning (Major.Feature.Patch) ## 9.7.0 (unreleased) +### YACReader +* Image enlargement/stretching can now be disabled for fit + to width and height ### YACReaderLibrary * update QsLog logger to version 2.1, snapshot 46b643d5bcbc diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp index a5208e87..7fa04ca9 100644 --- a/YACReader/configuration.cpp +++ b/YACReader/configuration.cpp @@ -47,14 +47,6 @@ void Configuration::load(QSettings *settings) settings->setValue(SHOW_TOOLBARS, true); if (!settings->contains(QUICK_NAVI_MODE)) settings->setValue(QUICK_NAVI_MODE, false); - //old fit stuff - /*if(!settings->contains(FIT)) - settings->setValue(FIT,false); - if(!settings->contains(FIT_TO_WIDTH_RATIO)) - settings->setValue(FIT_TO_WIDTH_RATIO,1); - if(!settings->contains(ADJUST_TO_FULL_SIZE)) - settings->setValue(ADJUST_TO_FULL_SIZE,false); - */ } void Configuration::updateOpenRecentList(QString path) { diff --git a/YACReader/configuration.h b/YACReader/configuration.h index 652aff40..0c35dbc1 100644 --- a/YACReader/configuration.h +++ b/YACReader/configuration.h @@ -51,16 +51,6 @@ public: void updateOpenRecentList(QString path); void clearOpenRecentList() { settings->remove("recentFiles"); } - //Old fitmodes - /* - bool getAdjustToWidth() {return settings->value(FIT).toBool();} - void setAdjustToWidth(bool atw=true) {settings->setValue(FIT,atw);} - float getFitToWidthRatio(){return settings->value(FIT_TO_WIDTH_RATIO).toFloat();} - void setFitToWidthRatio(float r){settings->setValue(FIT_TO_WIDTH_RATIO,r);} - bool getAdjustToFullSize(){return settings->value(ADJUST_TO_FULL_SIZE).toBool();} - void setAdjustToFullSize(bool b){settings->setValue(ADJUST_TO_FULL_SIZE,b);} - */ - FlowType getFlowType() { return (FlowType)settings->value(FLOW_TYPE_SW).toInt(); } void setFlowType(FlowType type) { settings->setValue(FLOW_TYPE_SW, type); } bool getFullScreen() { return settings->value(FULLSCREEN).toBool(); } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 004756a2..3d7de60f 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -156,6 +156,7 @@ void MainWindowViewer::setupUI() connect(optionsDialog, SIGNAL(accepted()), viewer, SLOT(updateOptions())); connect(optionsDialog, SIGNAL(optionsChanged()), this, SLOT(reloadOptions())); connect(optionsDialog, SIGNAL(changedFilters(int, int, int)), viewer, SLOT(updateFilters(int, int, int))); + connect(optionsDialog, &OptionsDialog::changedImageOptions, viewer, &Viewer::updatePage); optionsDialog->restoreOptions(settings); //shortcutsDialog = new ShortcutsDialog(this); diff --git a/YACReader/options_dialog.cpp b/YACReader/options_dialog.cpp index 14340876..5bc07407 100644 --- a/YACReader/options_dialog.cpp +++ b/YACReader/options_dialog.cpp @@ -55,18 +55,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(pathFindButton, SIGNAL(clicked()), this, SLOT(findFolder())); - //fitToWidthRatioLabel = new QLabel(tr("Page width stretch"),this); - /*QGroupBox *fitBox = new QGroupBox(tr("Page width stretch")); - fitToWidthRatioS = new QSlider(this); - fitToWidthRatioS->setMinimum(50); - fitToWidthRatioS->setMaximum(100); - fitToWidthRatioS->setPageStep(5); - fitToWidthRatioS->setOrientation(Qt::Horizontal); - //connect(fitToWidthRatioS,SIGNAL(valueChanged(int)),this,SLOT(fitToWidthRatio(int))); - QHBoxLayout * fitLayout = new QHBoxLayout; - fitLayout->addWidget(fitToWidthRatioS); - fitBox->setLayout(fitLayout);*/ - auto colorSelection = new QHBoxLayout; backgroundColor = new QLabel(); QPalette pal = backgroundColor->palette(); @@ -145,6 +133,19 @@ OptionsDialog::OptionsDialog(QWidget *parent) QGroupBox *imageBox = new QGroupBox(tr("Image options")); imageBox->setLayout(layoutImage); layoutImageV->addWidget(imageBox); + + auto scaleBox = new QGroupBox(tr("Fit options")); + auto scaleLayout = new QVBoxLayout(); + scaleCheckbox = new QCheckBox(tr("Enlarge images to fit width/height")); + connect(scaleCheckbox, &QCheckBox::clicked, + [=](bool checked) { + settings->setValue(ENLARGE_IMAGES, checked); + emit(changedImageOptions()); + }); + + scaleLayout->addWidget(scaleCheckbox); + scaleBox->setLayout(scaleLayout); + layoutImageV->addWidget(scaleBox); layoutImageV->addStretch(); pageGeneral->setLayout(layoutGeneral); @@ -233,6 +234,8 @@ void OptionsDialog::restoreOptions(QSettings *settings) brightnessS->setValue(settings->value(BRIGHTNESS, 0).toInt()); contrastS->setValue(settings->value(CONTRAST, 100).toInt()); gammaS->setValue(settings->value(GAMMA, 100).toInt()); + + scaleCheckbox->setChecked(settings->value(ENLARGE_IMAGES, true).toBool()); } void OptionsDialog::updateColor(const QColor &color) @@ -248,12 +251,6 @@ void OptionsDialog::updateColor(const QColor &color) emit(changedOptions()); } -/*void OptionsDialog::fitToWidthRatio(int value) -{ - Configuration::getConfiguration().setFitToWidthRatio(value/100.0); - emit(fitToWidthRatioChanged(value/100.0)); -}*/ - void OptionsDialog::brightnessChanged(int value) { QSettings settings(YACReader::getSettingsPath() + "/YACReader.ini", QSettings::IniFormat); diff --git a/YACReader/options_dialog.h b/YACReader/options_dialog.h index 32404a50..56935a8e 100644 --- a/YACReader/options_dialog.h +++ b/YACReader/options_dialog.h @@ -25,6 +25,7 @@ private: QPushButton *pathFindButton; QCheckBox *quickNavi; QCheckBox *disableShowOnMouseOver; + QCheckBox *scaleCheckbox; QLabel *magGlassSizeLabel; diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index dbd93abf..50dc0971 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -316,24 +316,27 @@ void Viewer::updateContentSize() { //there is an image to resize if (currentPage != nullptr && !currentPage->isNull()) { - QSize pagefit; + QSize pagefit = currentPage->size(); + bool stretchImages = Configuration::getConfiguration().getSettings()->value(ENLARGE_IMAGES).toBool(); YACReader::FitMode fitmode = Configuration::getConfiguration().getFitMode(); switch (fitmode) { case YACReader::FitMode::FullRes: - pagefit = currentPage->size(); break; case YACReader::FitMode::ToWidth: - pagefit = currentPage->size(); + if (!stretchImages && width() > pagefit.width()) { + break; + } pagefit.scale(width(), 0, Qt::KeepAspectRatioByExpanding); break; case YACReader::FitMode::ToHeight: - pagefit = currentPage->size(); + if (!stretchImages && height() > pagefit.height()) { + break; + } pagefit.scale(0, height(), Qt::KeepAspectRatioByExpanding); break; //if everything fails showing the full page is a good idea case YACReader::FitMode::FullPage: default: - pagefit = currentPage->size(); pagefit.scale(size(), Qt::KeepAspectRatio); break; } diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h index 94a876ea..8280c28e 100644 --- a/common/yacreader_global_gui.h +++ b/common/yacreader_global_gui.h @@ -69,6 +69,8 @@ #define USE_SELECTED_COMIC_COVER_AS_BACKGROUND_IMAGE_IN_GRID_VIEW "USE_SELECTED_COMIC_COVER_AS_BACKGROUND_IMAGE_IN_GRID_VIEW" #define DISPLAY_CONTINUE_READING_IN_GRID_VIEW "DISPLAY_CONTINUE_READING_IN_GRID_VIEW" +#define ENLARGE_IMAGES "ENLARGE_IMAGES" + namespace YACReader { static const QString YACReaderLibrarComiscSelectionMimeDataFormat = "application/yacreaderlibrary-comics-ids";