Skip to content

Commit

Permalink
Simplify scaling settings and add option to disable at high zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Dec 22, 2024
1 parent e0239b8 commit 1496c16
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 76 deletions.
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("qView");
QCoreApplication::setApplicationName("qView");
QCoreApplication::setApplicationVersion(QString::number(VERSION));

SettingsManager::migrateOldSettings();

QVApplication app(argc, argv);

QCommandLineParser parser;
Expand Down
73 changes: 39 additions & 34 deletions src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ QVGraphicsView::QVGraphicsView(QWidget *parent) : QGraphicsView(parent)
setScene(scene);

// Initialize configurable variables
isFilteringEnabled = true;
isScalingEnabled = true;
isScalingTwoEnabled = true;
smoothScalingMode = 2;
expensiveScalingAboveWindowSize = true;
smoothScalingLimit = 0;
isPastActualSizeEnabled = true;
isScrollZoomsEnabled = true;
isLoopFoldersEnabled = true;
Expand Down Expand Up @@ -261,8 +261,7 @@ void QVGraphicsView::postLoad()

zoomToFit();

if (isScalingEnabled)
expensiveScaleTimer->start();
expensiveScaleTimer->start();

qvApp->getActionManager().addFileToRecentsList(getCurrentFileDetails().fileInfo);

Expand Down Expand Up @@ -324,25 +323,16 @@ void QVGraphicsView::zoomAbsolute(const qreal absoluteLevel, const QPoint &pos)
centerImage();
}

if (isScalingEnabled)
expensiveScaleTimer->start();
handleSmoothScalingChange();

emit zoomLevelChanged();
}

void QVGraphicsView::applyExpensiveScaling()
{
if (!isScalingEnabled || !getCurrentFileDetails().isPixmapLoaded)
if (!isExpensiveScalingRequested())
return;

// If we are above maximum scaling size
if (getContentToViewportRatio() > (isScalingTwoEnabled ? 3.0 : 1.00001))
{
// Return to original size
removeExpensiveScaling();
return;
}

// Calculate scaled resolution
const qreal dpiAdjustment = getDpiAdjustment();
const QSizeF mappedSize = QSizeF(getCurrentFileDetails().loadedPixmapSize) * zoomLevel * dpiAdjustment * devicePixelRatioF();
Expand Down Expand Up @@ -377,7 +367,7 @@ void QVGraphicsView::animatedFrameChanged(QRect rect)
{
Q_UNUSED(rect)

if (isScalingEnabled)
if (isExpensiveScalingRequested())
{
applyExpensiveScaling();
}
Expand Down Expand Up @@ -567,6 +557,20 @@ void QVGraphicsView::goToFile(const GoToFileMode &mode, int index)
loadFile(nextImageFilePath);
}

bool QVGraphicsView::isSmoothScalingRequested() const
{
return smoothScalingMode != 0 && (smoothScalingLimit == 0 || zoomLevel < smoothScalingLimit);
}

bool QVGraphicsView::isExpensiveScalingRequested() const
{
if (!isSmoothScalingRequested() || smoothScalingMode != 2 || !getCurrentFileDetails().isPixmapLoaded)
return false;

// Make sure we aren't over the maximum scaling size
return getContentToViewportRatio() <= (expensiveScalingAboveWindowSize ? 3.0 : 1.00001);
}

QSizeF QVGraphicsView::getEffectiveOriginalSize() const
{
return getTransformWithNoScaling().mapRect(QRectF(QPoint(), getCurrentFileDetails().loadedPixmapSize)).size() * getDpiAdjustment();
Expand Down Expand Up @@ -636,32 +640,31 @@ void QVGraphicsView::handleDpiAdjustmentChange()

zoomToFit();

if (isScalingEnabled)
expensiveScaleTimer->start();
}

void QVGraphicsView::handleSmoothScalingChange()
{
loadedPixmapItem->setTransformationMode(isSmoothScalingRequested() ? Qt::SmoothTransformation : Qt::FastTransformation);

if (isExpensiveScalingRequested())
expensiveScaleTimer->start();
else if (appliedExpensiveScaleZoomLevel != 0.0)
removeExpensiveScaling();
}

void QVGraphicsView::settingsUpdated()
{
auto &settingsManager = qvApp->getSettingsManager();

//filtering
if (settingsManager.getBoolean("filteringenabled"))
loadedPixmapItem->setTransformationMode(Qt::SmoothTransformation);
else
loadedPixmapItem->setTransformationMode(Qt::FastTransformation);
//smooth scaling
smoothScalingMode = settingsManager.getInteger("smoothscalingmode");

//scaling
isScalingEnabled = settingsManager.getBoolean("scalingenabled");
if (isScalingEnabled)
expensiveScaleTimer->start();
else
removeExpensiveScaling();
//scaling two
expensiveScalingAboveWindowSize = settingsManager.getBoolean("scalingtwoenabled");

//scaling2
if (!isScalingEnabled)
isScalingTwoEnabled = false;
else
isScalingTwoEnabled = settingsManager.getBoolean("scalingtwoenabled");
//smooth scaling limit
smoothScalingLimit = settingsManager.getBoolean("smoothscalinglimitenabled") ? (settingsManager.getInteger("smoothscalinglimitpercent") / 100.0) : 0;

//cropmode
cropMode = settingsManager.getInteger("cropmode");
Expand All @@ -686,6 +689,8 @@ void QVGraphicsView::settingsUpdated()

// End of settings variables

handleSmoothScalingChange();

handleDpiAdjustmentChange();

zoomToFit();
Expand Down
12 changes: 9 additions & 3 deletions src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class QVGraphicsView : public QGraphicsView

bool event(QEvent *event) override;

bool isSmoothScalingRequested() const;

bool isExpensiveScalingRequested() const;

QRectF getContentRect() const;

QRect getUsableViewportRect(const bool addOverscan = false) const;
Expand All @@ -116,6 +120,8 @@ class QVGraphicsView : public QGraphicsView

void handleDpiAdjustmentChange();

void handleSmoothScalingChange();

private slots:
void animatedFrameChanged(QRect rect);

Expand All @@ -126,9 +132,9 @@ private slots:

QGraphicsPixmapItem *loadedPixmapItem;

bool isFilteringEnabled;
bool isScalingEnabled;
bool isScalingTwoEnabled;
int smoothScalingMode;
bool expensiveScalingAboveWindowSize;
qreal smoothScalingLimit;
bool isPastActualSizeEnabled;
bool isScrollZoomsEnabled;
bool isLoopFoldersEnabled;
Expand Down
23 changes: 9 additions & 14 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &QVOptionsDialog::buttonBoxClicked);
connect(ui->shortcutsTable, &QTableWidget::cellDoubleClicked, this, &QVOptionsDialog::shortcutCellDoubleClicked);
connect(ui->bgColorCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::bgColorCheckboxStateChanged);
connect(ui->scalingCheckbox, &QCheckBox::stateChanged, this, &QVOptionsDialog::scalingCheckboxStateChanged);

populateLanguages();

Expand Down Expand Up @@ -68,6 +67,7 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) :
#endif

syncSettings(false, true);
connect(ui->smoothScalingComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::smoothScalingComboBoxCurrentIndexChanged);
connect(ui->windowResizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged);
connect(ui->langComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &QVOptionsDialog::languageComboBoxCurrentIndexChanged);
syncShortcuts();
Expand Down Expand Up @@ -154,16 +154,13 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections)
syncCheckbox(ui->menubarCheckbox, "menubarenabled", defaults, makeConnections);
// fullscreendetails
syncCheckbox(ui->detailsInFullscreen, "fullscreendetails", defaults, makeConnections);
// filteringenabled
syncCheckbox(ui->filteringCheckbox, "filteringenabled", defaults, makeConnections);
// scalingenabled
syncCheckbox(ui->scalingCheckbox, "scalingenabled", defaults, makeConnections);
if (ui->scalingCheckbox->isChecked())
ui->scalingTwoCheckbox->setEnabled(true);
else
ui->scalingTwoCheckbox->setEnabled(false);
// smoothscalingmode
syncComboBox(ui->smoothScalingComboBox, "smoothscalingmode", defaults, makeConnections);
smoothScalingComboBoxCurrentIndexChanged(ui->smoothScalingComboBox->currentIndex());
// scalingtwoenabled
syncCheckbox(ui->scalingTwoCheckbox, "scalingtwoenabled", defaults, makeConnections);
// smoothscalinglimitenabled
syncCheckbox(ui->smoothScalingLimitCheckbox, "smoothscalinglimitenabled", defaults, makeConnections);
// scalefactor
syncSpinBox(ui->scaleFactorSpinBox, "scalefactor", defaults, makeConnections);
// scrollzoomsenabled
Expand Down Expand Up @@ -437,12 +434,10 @@ void QVOptionsDialog::bgColorCheckboxStateChanged(int arg1)
updateBgColorButton();
}

void QVOptionsDialog::scalingCheckboxStateChanged(int arg1)
void QVOptionsDialog::smoothScalingComboBoxCurrentIndexChanged(int index)
{
if (arg1 > 0)
ui->scalingTwoCheckbox->setEnabled(true);
else
ui->scalingTwoCheckbox->setEnabled(false);
ui->scalingTwoCheckbox->setEnabled(index == 2);
ui->smoothScalingLimitCheckbox->setEnabled(index != 0);
}

void QVOptionsDialog::windowResizeComboBoxCurrentIndexChanged(int index)
Expand Down
2 changes: 1 addition & 1 deletion src/qvoptionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private slots:

void bgColorCheckboxStateChanged(int arg1);

void scalingCheckboxStateChanged(int arg1);
void smoothScalingComboBoxCurrentIndexChanged(int index);

void windowResizeComboBoxCurrentIndexChanged(int index);

Expand Down
44 changes: 22 additions & 22 deletions src/qvoptionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -260,46 +260,46 @@
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Scaling:</string>
<string>Smooth scaling:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="filteringCheckbox">
<property name="toolTip">
<string>Turn this off to see individual pixels</string>
</property>
<property name="text">
<string>&amp;Bilinear filtering</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<widget class="QComboBox" name="smoothScalingComboBox">
<item>
<property name="text">
<string>Disabled</string>
</property>
</item>
<item>
<property name="text">
<string>Bilinear</string>
</property>
</item>
<item>
<property name="text">
<string>Expensive</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="scalingCheckbox">
<widget class="QCheckBox" name="scalingTwoCheckbox">
<property name="toolTip">
<string>Images appear aliased (having jagged edges) without this, but it is faster</string>
<string>Use expensive scaling when zooming above the window size (can be laggier with large images)</string>
</property>
<property name="text">
<string>&amp;Image scaling</string>
<string>Expensive scaling above window size</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="scalingTwoCheckbox">
<property name="toolTip">
<string>Choose whether or not the image continues to be scaled when zooming above the window size (can be laggier with large images)</string>
</property>
<widget class="QCheckBox" name="smoothScalingLimitCheckbox">
<property name="text">
<string>&amp;Scaling above window size</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Disable smooth scaling at high zoom</string>
</property>
</widget>
</item>
Expand Down
19 changes: 17 additions & 2 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ bool SettingsManager::isDefault(const QString &key) const
return getSetting(key) == getSetting(key, true);
}

void SettingsManager::migrateOldSettings()
{
QSettings settings;
settings.beginGroup("options");
if (!settings.contains("smoothscalingmode") && settings.contains("filteringenabled"))
{
const int value =
settings.value("scalingenabled").toBool() ? 2 :
settings.value("filteringenabled").toBool() ? 1 :
0;
settings.setValue("smoothscalingmode", value);
}
}

void SettingsManager::initializeSettingsLibrary()
{
// Window
Expand All @@ -158,9 +172,10 @@ void SettingsManager::initializeSettingsLibrary()
settingsLibrary.insert("menubarenabled", {false, {}});
settingsLibrary.insert("fullscreendetails", {false, {}});
// Image
settingsLibrary.insert("filteringenabled", {true, {}});
settingsLibrary.insert("scalingenabled", {true, {}});
settingsLibrary.insert("smoothscalingmode", {2, {}});
settingsLibrary.insert("scalingtwoenabled", {true, {}});
settingsLibrary.insert("smoothscalinglimitenabled", {false, {}});
settingsLibrary.insert("smoothscalinglimitpercent", {400, {}});
settingsLibrary.insert("scalefactor", {25, {}});
settingsLibrary.insert("scrollzoomsenabled", {true, {}});
settingsLibrary.insert("cursorzoom", {true, {}});
Expand Down
2 changes: 2 additions & 0 deletions src/settingsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class SettingsManager : public QObject

bool isDefault(const QString &key) const;

static void migrateOldSettings();

signals:
void settingsUpdated();

Expand Down

0 comments on commit 1496c16

Please sign in to comment.