diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2023-06-02 14:07:03 +0200 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-06-03 17:43:56 +0200 |
commit | 5ad502af9cf3d49457082a12d36f8159b6c4ca11 (patch) | |
tree | 87ce0181bdcb03829954bf6f934bf199530aaaa8 /svx/source/tbxctrls | |
parent | c50e4b25b2eb278685698182e2a4b541739f2d42 (diff) |
Styles preview widget should cache images
Change-Id: I3ee370e5d3ef4227681c4a973ac6f24f9aa241e1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152556
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152575
Diffstat (limited to 'svx/source/tbxctrls')
-rw-r--r-- | svx/source/tbxctrls/StylesPreviewWindow.cxx | 28 |
1 files changed, 22 insertions, 6 deletions
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 <vcl/commandevent.hxx> +std::map<OUString, VclPtr<VirtualDevice>> StylesPreviewWindow_Base::aPreviewCache; + StyleStatusListener::StyleStatusListener( StylesPreviewWindow_Base* pPreviewControl, const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) @@ -460,6 +462,25 @@ void StylesListUpdateTask::Invoke() m_rStylesList.UpdateSelection(); } +VclPtr<VirtualDevice> +StylesPreviewWindow_Base::GetCachedPreview(const std::pair<OUString, OUString>& rStyle) +{ + if (aPreviewCache.find(rStyle.second) != aPreviewCache.end()) + return aPreviewCache[rStyle.second]; + else + { + VclPtr<VirtualDevice> pImg = VclPtr<VirtualDevice>::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<VirtualDevice> pImg = VclPtr<VirtualDevice>::Create(); - const Size aSize(100, 30); - pImg->SetOutputSizePixel(aSize); - - StyleItemController aStyleController(rStyle); - aStyleController.Paint(*pImg); + VclPtr<VirtualDevice> pImg = GetCachedPreview(rStyle); m_xStylesView->append(rStyle.first, rStyle.second, pImg); } |