Skip to content

Commit

Permalink
Add scroll action cooldown option
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Oct 7, 2023
1 parent bb5fbe2 commit 91a4c3c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/qvgraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void QVGraphicsView::executeScrollAction(const Qv::ViewportScrollAction action,
else if (action == Qv::ViewportScrollAction::Navigate)
{
SwipeData swipeData = scrollAxisLocker.getCustomData().value<SwipeData>();
if (swipeData.triggeredAction)
if (swipeData.triggeredAction && scrollActionCooldown)
return;
swipeData.totalDelta += getUniAxisDelta();
if (qAbs(swipeData.totalDelta) >= deltaPerWheelStep)
Expand All @@ -369,6 +369,7 @@ void QVGraphicsView::executeScrollAction(const Qv::ViewportScrollAction action,
else
goToFile(GoToFileMode::previous);
swipeData.triggeredAction = true;
swipeData.totalDelta %= deltaPerWheelStep;
}
scrollAxisLocker.setCustomData(QVariant::fromValue(swipeData));
}
Expand Down Expand Up @@ -1001,6 +1002,7 @@ void QVGraphicsView::settingsUpdated()
horizontalScrollAction = settingsManager.getEnum<Qv::ViewportScrollAction>("viewporthorizontalscrollaction");
altVerticalScrollAction = settingsManager.getEnum<Qv::ViewportScrollAction>("viewportaltverticalscrollaction");
altHorizontalScrollAction = settingsManager.getEnum<Qv::ViewportScrollAction>("viewportalthorizontalscrollaction");
scrollActionCooldown = settingsManager.getBoolean("scrollactioncooldown");

// End of settings variables

Expand Down
1 change: 1 addition & 0 deletions src/qvgraphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private slots:
Qv::ViewportScrollAction horizontalScrollAction {Qv::ViewportScrollAction::None};
Qv::ViewportScrollAction altVerticalScrollAction {Qv::ViewportScrollAction::None};
Qv::ViewportScrollAction altHorizontalScrollAction {Qv::ViewportScrollAction::None};
bool scrollActionCooldown {false};

std::optional<Qv::CalculatedZoomMode> calculatedZoomMode {Qv::CalculatedZoomMode::ZoomToFit};
bool navigationResetsZoom {true};
Expand Down
1 change: 1 addition & 0 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ void QVOptionsDialog::syncSettings(bool defaults, bool makeConnections)
syncComboBox(ui->horizontalScrollComboBox, "viewporthorizontalscrollaction", defaults, makeConnections);
syncComboBox(ui->altVerticalScrollComboBox, "viewportaltverticalscrollaction", defaults, makeConnections);
syncComboBox(ui->altHorizontalScrollComboBox, "viewportalthorizontalscrollaction", defaults, makeConnections);
syncCheckbox(ui->scrollActionCooldownCheckbox, "scrollactioncooldown", defaults, makeConnections);
}

void QVOptionsDialog::syncCheckbox(QCheckBox *checkbox, const QString &key, bool defaults, bool makeConnection)
Expand Down
12 changes: 11 additions & 1 deletion src/qvoptionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>508</width>
<height>616</height>
<height>639</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -980,6 +980,16 @@
<item row="3" column="1">
<widget class="QComboBox" name="altHorizontalScrollComboBox"/>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="scrollActionCooldownCheckbox">
<property name="toolTip">
<string>Useful for touchpads, to prevent a single swipe from triggering multiple navigations, for example</string>
</property>
<property name="text">
<string>Cooldown for discrete actions</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
6 changes: 6 additions & 0 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,10 @@ void SettingsManager::initializeSettingsLibrary()
settingsLibrary.insert("viewporthorizontalscrollaction", {static_cast<int>(Qv::ViewportScrollAction::Navigate), {}});
settingsLibrary.insert("viewportaltverticalscrollaction", {static_cast<int>(Qv::ViewportScrollAction::Pan), {}});
settingsLibrary.insert("viewportalthorizontalscrollaction", {static_cast<int>(Qv::ViewportScrollAction::Pan), {}});
#ifdef Q_OS_MACOS
// Works best with touchpads that accurately report ScrollPhase (macOS only currently)
settingsLibrary.insert("scrollactioncooldown", {true, {}});
#else
settingsLibrary.insert("scrollactioncooldown", {false, {}});
#endif
}

0 comments on commit 91a4c3c

Please sign in to comment.