From 34a97838137f6e54405722d607b7f414084f526e Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 8 Apr 2022 13:12:50 +0900 Subject: sc: add an overlay to show sparklines in a sparkline group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds an overlay that shows/selects all sparklines in a sparkline group for the cursor cell sparkline, if the cursor cell has an associated sparkline. Change-Id: I60a5873ebdf8606f262d217caf6011c4a003801a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132692 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sc/source/ui/inc/gridwin.hxx | 3 ++ sc/source/ui/view/gridwin.cxx | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index b4117736484e..93d7abd095a3 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -106,6 +106,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, public DropTargetHel std::unique_ptr mpOODragRect; std::unique_ptr mpOOHeader; std::unique_ptr mpOOShrink; + std::unique_ptr mpOOSparklineGroup; std::optional mpAutoFillRect; @@ -462,6 +463,8 @@ public: const std::vector* GetAutoSpellData( SCCOL nPosX, SCROW nPosY ); bool InsideVisibleRange( SCCOL nPosX, SCROW nPosY ); + void UpdateSparklineGroupOverlay(); + void DeleteSparklineGroupOverlay(); void DeleteCopySourceOverlay(); void UpdateCopySourceOverlay(); void DeleteCursorOverlay(); diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 6ce6a6d6c421..516c9ef16d50 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -128,6 +128,7 @@ #include #include #include +#include #include @@ -6034,6 +6035,7 @@ void ScGridWindow::CursorChanged() // now, just re-create them UpdateCursorOverlay(); + UpdateSparklineGroupOverlay(); } void ScGridWindow::ImpCreateOverlayObjects() @@ -6045,6 +6047,7 @@ void ScGridWindow::ImpCreateOverlayObjects() UpdateDragRectOverlay(); UpdateHeaderOverlay(); UpdateShrinkOverlay(); + UpdateSparklineGroupOverlay(); } void ScGridWindow::ImpDestroyOverlayObjects() @@ -6056,6 +6059,7 @@ void ScGridWindow::ImpDestroyOverlayObjects() DeleteDragRectOverlay(); DeleteHeaderOverlay(); DeleteShrinkOverlay(); + DeleteSparklineGroupOverlay(); } void ScGridWindow::UpdateAllOverlays() @@ -6973,6 +6977,69 @@ void ScGridWindow::UpdateShrinkOverlay() SetMapMode( aOldMode ); } +void ScGridWindow::DeleteSparklineGroupOverlay() +{ + mpOOSparklineGroup.reset(); +} + +void ScGridWindow::UpdateSparklineGroupOverlay() +{ + MapMode aDrawMode = GetDrawMapMode(); + + MapMode aOldMode = GetMapMode(); + if (aOldMode != aDrawMode) + SetMapMode(aDrawMode); + + DeleteSparklineGroupOverlay(); + + ScAddress aCurrentAddress = mrViewData.GetCurPos(); + + ScDocument& rDocument = mrViewData.GetDocument(); + if (auto pSparkline = rDocument.GetSparkline(aCurrentAddress)) + { + mpOOSparklineGroup.reset(new sdr::overlay::OverlayObjectList); + + rtl::Reference xOverlayManager = getOverlayManager(); + if (xOverlayManager.is()) + { + auto* pList = rDocument.GetSparklineList(aCurrentAddress.Tab()); + if (pList) + { + auto const& pSparklines = pList->getSparklinesFor(pSparkline->getSparklineGroup()); + + Color aColor = SvtOptionsDrawinglayer::getHilightColor(); + + std::vector aRanges; + const basegfx::B2DHomMatrix aTransform(GetOutDev()->GetInverseViewTransformation()); + + for (auto const& pCurrentSparkline : pSparklines) + { + SCCOL nColumn = pCurrentSparkline->getColumn(); + SCROW nRow = pCurrentSparkline->getRow(); + + Point aStart = mrViewData.GetScrPos(nColumn, nRow, eWhich); + Point aEnd = mrViewData.GetScrPos(nColumn + 1, nRow + 1, eWhich); + + basegfx::B2DRange aRange(aStart.X(), aStart.Y(), aEnd.X(), aEnd.Y()); + + aRange.transform(aTransform); + aRanges.push_back(aRange); + } + + std::unique_ptr pOverlay(new sdr::overlay::OverlaySelection( + sdr::overlay::OverlayType::Transparent, + aColor, std::move(aRanges), true)); + + xOverlayManager->add(*pOverlay); + mpOOSparklineGroup->append(std::move(pOverlay)); + } + } + } + + if (aOldMode != aDrawMode) + SetMapMode(aOldMode); +} + // #i70788# central method to get the OverlayManager safely rtl::Reference ScGridWindow::getOverlayManager() const { -- cgit