summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorPovilas Kanapickas <povilas@radix.lt>2022-12-07 03:13:26 +0200
committerTomaž Vajngerl <quikee@gmail.com>2022-12-14 13:44:32 +0000
commit9807fbfb56edd9998d3e8757b11f50cfa6887535 (patch)
tree9e58f77218b33d22a52471233fc084124e64754d /sw
parent0280538af13617145987663ad6407190939794f2 (diff)
sw: React to touchpad zoom gestures in SwView
Change-Id: I337e5d6873f9cf6d78cb53b2ffdb59a33a9465f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143753 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/view.hxx3
-rw-r--r--sw/source/uibase/uiview/viewport.cxx30
2 files changed, 33 insertions, 0 deletions
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index caaa808b6a24..c3ed0f5808d7 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -235,6 +235,8 @@ class SW_DLLPUBLIC SwView: public SfxViewShell
SvxSearchCmd m_eLastSearchCommand;
bool m_bWheelScrollInProgress;
+ double m_fLastZoomScale = 0;
+ double m_fAccumulatedZoom = 0;
bool m_bCenterCursor : 1,
m_bTopCursor : 1,
@@ -470,6 +472,7 @@ public:
static void SetActMark(sal_Int32 nSet);
bool HandleWheelCommands( const CommandEvent& );
+ bool HandleGestureZoomCommand(const CommandEvent&);
// insert frames
void InsFrameMode(sal_uInt16 nCols);
diff --git a/sw/source/uibase/uiview/viewport.cxx b/sw/source/uibase/uiview/viewport.cxx
index ff4c918c9619..2c66c52a0c96 100644
--- a/sw/source/uibase/uiview/viewport.cxx
+++ b/sw/source/uibase/uiview/viewport.cxx
@@ -1230,4 +1230,34 @@ bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
return bOk;
}
+bool SwView::HandleGestureZoomCommand(const CommandEvent& rCEvt)
+{
+ const CommandGestureZoomData* pData = rCEvt.GetGestureZoomData();
+
+ if (pData->meEventType == GestureEventZoomType::Begin)
+ {
+ m_fLastZoomScale = pData->mfScaleDelta;
+ return true;
+ }
+
+ if (pData->meEventType == GestureEventZoomType::Update)
+ {
+ double deltaBetweenEvents = (pData->mfScaleDelta - m_fLastZoomScale) / m_fLastZoomScale;
+ m_fLastZoomScale = pData->mfScaleDelta;
+
+ // Accumulate fractional zoom to avoid small zoom changes from being ignored
+ m_fAccumulatedZoom += deltaBetweenEvents;
+ int nZoomChangePercent = m_fAccumulatedZoom * 100;
+ m_fAccumulatedZoom -= nZoomChangePercent / 100.0;
+
+ sal_uInt16 nFact = m_pWrtShell->GetViewOptions()->GetZoom();
+ nFact += nZoomChangePercent;
+ nFact = std::clamp<sal_uInt16>(nFact, MIN_ZOOM_PERCENT, MAX_ZOOM_PERCENT);
+ SetZoom(SvxZoomType::PERCENT, nFact);
+
+ return true;
+ }
+ return true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */