diff options
author | Povilas Kanapickas <povilas@radix.lt> | 2022-12-07 03:13:29 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-12-14 13:48:41 +0000 |
commit | 90f5ecbbdb202ec4fbee9e1416f9268aa1dc56ba (patch) | |
tree | 448d4a3df5a0ceb555aa6aa4c2551c7eb92fe44a /sc | |
parent | f87a0480af5b15d673490a5b1736133148ec7333 (diff) |
sc: React to touchpad zoom gestures in ScTabView
Change-Id: I9a946c0caf3aab03a2055740a4f467210dc07b6a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143756
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/tabview.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/view/tabview.cxx | 42 |
2 files changed, 46 insertions, 0 deletions
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index f62b2c4f9cba..7fdb0cc3c2c2 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -214,6 +214,9 @@ private: bool bBlockRows:1; // are whole rows selected? bool mbInlineWithScrollbar:1; // should inline with scrollbar? + double mfLastZoomScale = 0; + double mfAccumulatedZoom = 0; + void Init(); void DoAddWin( ScGridWindow* pWin ); @@ -458,6 +461,7 @@ public: SC_DLLPUBLIC void ScrollLines( tools::Long nDeltaX, tools::Long nDeltaY ); // active bool ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos ); + bool GestureZoomCommand(const CommandEvent& rCEvt); void ScrollToObject( const SdrObject* pDrawObj ); void MakeVisible( const tools::Rectangle& rHMMRect ); diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx index f12327b04a5d..5b2c44ee4875 100644 --- a/sc/source/ui/view/tabview.cxx +++ b/sc/source/ui/view/tabview.cxx @@ -992,6 +992,48 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos ) return bDone; } +bool ScTabView::GestureZoomCommand(const CommandEvent& rCEvt) +{ + HideNoteMarker(); + + const CommandGestureZoomData* pData = rCEvt.GetGestureZoomData(); + if (!pData) + return false; + + if (aViewData.GetViewShell()->GetViewFrame()->GetFrame().IsInPlace()) + return false; + + if (pData->meEventType == GestureEventZoomType::Begin) + { + mfLastZoomScale = pData->mfScaleDelta; + return true; + } + + if (pData->meEventType == GestureEventZoomType::Update) + { + double deltaBetweenEvents = (pData->mfScaleDelta - mfLastZoomScale) / mfLastZoomScale; + mfLastZoomScale = pData->mfScaleDelta; + + // Accumulate fractional zoom to avoid small zoom changes from being ignored + mfAccumulatedZoom += deltaBetweenEvents; + int nZoomChangePercent = mfAccumulatedZoom * 100; + mfAccumulatedZoom -= nZoomChangePercent / 100.0; + + const Fraction& rOldY = aViewData.GetZoomY(); + sal_uInt16 nOld = static_cast<tools::Long>(rOldY * 100); + sal_uInt16 nNew = nOld + nZoomChangePercent; + nNew = std::clamp<sal_uInt16>(nNew, MINZOOM, MAXZOOM); + + if (nNew != nOld) + { + SetZoomPercentFromCommand(nNew); + } + + return true; + } + return true; +} + IMPL_LINK_NOARG(ScTabView, HScrollLeftHdl, weld::Scrollbar&, void) { ScrollHdl(aHScrollLeft.get()); |