From 5ad502af9cf3d49457082a12d36f8159b6c4ca11 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Fri, 2 Jun 2023 14:07:03 +0200 Subject: Styles preview widget should cache images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I3ee370e5d3ef4227681c4a973ac6f24f9aa241e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152556 Tested-by: Caolán McNamara Reviewed-by: Caolán McNamara Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152575 --- svx/source/inc/StylesPreviewWindow.hxx | 3 +++ svx/source/tbxctrls/StylesPreviewWindow.cxx | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'svx') diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx index 0295a0eeea7c..47e21dcb4ca0 100644 --- a/svx/source/inc/StylesPreviewWindow.hxx +++ b/svx/source/inc/StylesPreviewWindow.hxx @@ -121,11 +121,14 @@ public: void Select(const OUString& rStyleName); void RequestStylesListUpdate(); + static VclPtr GetCachedPreview(const std::pair& rStyle); private: void UpdateStylesList(); void UpdateSelection(); bool Command(const CommandEvent& rEvent); + + static std::map> aPreviewCache; }; class StylesPreviewWindow_Impl final : public InterimItemWindow, public StylesPreviewWindow_Base diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx index ff2f959d3406..c1e3549fb54a 100644 --- a/svx/source/tbxctrls/StylesPreviewWindow.cxx +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -60,6 +60,8 @@ #include +std::map> StylesPreviewWindow_Base::aPreviewCache; + StyleStatusListener::StyleStatusListener( StylesPreviewWindow_Base* pPreviewControl, const css::uno::Reference& xDispatchProvider) @@ -460,6 +462,25 @@ void StylesListUpdateTask::Invoke() m_rStylesList.UpdateSelection(); } +VclPtr +StylesPreviewWindow_Base::GetCachedPreview(const std::pair& rStyle) +{ + if (aPreviewCache.find(rStyle.second) != aPreviewCache.end()) + return aPreviewCache[rStyle.second]; + else + { + VclPtr pImg = VclPtr::Create(); + const Size aSize(100, 30); + pImg->SetOutputSizePixel(aSize); + + StyleItemController aStyleController(rStyle); + aStyleController.Paint(*pImg); + aPreviewCache[rStyle.second] = pImg; + + return pImg; + } +} + void StylesPreviewWindow_Base::UpdateStylesList() { m_aAllStyles = m_aDefaultStyles; @@ -487,12 +508,7 @@ void StylesPreviewWindow_Base::UpdateStylesList() m_xStylesView->clear(); for (const auto& rStyle : m_aAllStyles) { - ScopedVclPtr pImg = VclPtr::Create(); - const Size aSize(100, 30); - pImg->SetOutputSizePixel(aSize); - - StyleItemController aStyleController(rStyle); - aStyleController.Paint(*pImg); + VclPtr pImg = GetCachedPreview(rStyle); m_xStylesView->append(rStyle.first, rStyle.second, pImg); } -- cgit