diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2023-07-02 17:31:38 +0300 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-09-06 09:37:18 +0200 |
commit | 1345619e0b3c2825c2ae50ada2c209d4ad8461ad (patch) | |
tree | 6c3c5166ed8e8912e79b6a39d1fae3b228fbe68a /include | |
parent | e233f4616d6a6b7ca54e3028f77bdee4061bbfab (diff) |
tdf#154270 Sync toolbar button recent colors
As the last used color is stored per button instance, these
will go out of sync with several buttons being visible (e.g.
a toolbar and a sidebar, or a toolbar overflow popup), and
will reset whenever the toolbar resets (e.g. change in
selection, switch from print preview, or customization).
Fix that by storing the last colors per-document, and
notifying other buttons on changes. Keep the last color also
stored per-button for now, as a fallback for reportdesign
(which isn't sfx2 based).
Change-Id: I866f1de5c8ff6f56c47dc4b6b5acf52957d4e6c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153943
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156519
Diffstat (limited to 'include')
-rw-r--r-- | include/sfx2/namedcolor.hxx | 57 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 4 | ||||
-rw-r--r-- | include/svx/Palette.hxx | 50 | ||||
-rw-r--r-- | include/svx/PaletteManager.hxx | 1 | ||||
-rw-r--r-- | include/svx/colorwindow.hxx | 3 | ||||
-rw-r--r-- | include/svx/tbcontrl.hxx | 1 |
6 files changed, 63 insertions, 53 deletions
diff --git a/include/sfx2/namedcolor.hxx b/include/sfx2/namedcolor.hxx new file mode 100644 index 000000000000..fc7941686fbd --- /dev/null +++ b/include/sfx2/namedcolor.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sal/config.h> +#include <sfx2/dllapi.h> + +#include <docmodel/color/ComplexColor.hxx> +#include <docmodel/theme/ThemeColorType.hxx> + +struct SFX2_DLLPUBLIC NamedColor +{ + Color m_aColor; + OUString m_aName; + sal_Int16 m_nThemeIndex = -1; + sal_Int16 m_nLumMod = 10000; + sal_Int16 m_nLumOff = 0; + + NamedColor() = default; + + NamedColor(Color const& rColor, OUString const& rName) + : m_aColor(rColor) + , m_aName(rName) + { + } + + model::ComplexColor getComplexColor() + { + model::ComplexColor aComplexColor; + + auto eThemeColorType = model::convertToThemeColorType(m_nThemeIndex); + + if (eThemeColorType != model::ThemeColorType::Unknown) + { + aComplexColor.setSchemeColor(eThemeColorType); + + if (m_nLumMod != 10000) + aComplexColor.addTransformation({ model::TransformationType::LumMod, m_nLumMod }); + + if (m_nLumMod != 0) + aComplexColor.addTransformation({ model::TransformationType::LumOff, m_nLumOff }); + } + + aComplexColor.setFinalColor(m_aColor); + + return aComplexColor; + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index b29fb43d77e4..9b7db5347597 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -47,6 +47,7 @@ namespace weld {class Button; } namespace model {class ColorSet; } +struct NamedColor; class SbxValue; class SbxArray; class BasicManager; @@ -558,6 +559,9 @@ public: GetDialogContainer(); StarBASIC* GetBasic() const; + std::optional<NamedColor> GetRecentColor(sal_uInt16 nSlotId); + void SetRecentColor(sal_uInt16 nSlotId, const NamedColor& rColor); + virtual std::set<Color> GetDocColors(); virtual std::shared_ptr<model::ColorSet> GetThemeColors(); diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index c108a1679d98..5bf63762b75c 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -20,60 +20,12 @@ #pragma once #include <sal/config.h> +#include <sfx2/namedcolor.hxx> #include <functional> -#include <rtl/ustring.hxx> -#include <tools/color.hxx> -#include <svx/svxdllapi.h> - -#include <docmodel/color/ComplexColor.hxx> -#include <docmodel/theme/ThemeColorType.hxx> - class SvxColorValueSet; -struct SVXCORE_DLLPUBLIC NamedColor -{ - Color m_aColor; - OUString m_aName; - sal_Int16 m_nThemeIndex = -1; - sal_Int16 m_nLumMod = 10000; - sal_Int16 m_nLumOff = 0; - - NamedColor() = default; - - NamedColor(Color const& rColor, OUString const& rName) - : m_aColor(rColor) - , m_aName(rName) - {} - - model::ComplexColor getComplexColor() - { - model::ComplexColor aComplexColor; - - auto eThemeColorType = model::convertToThemeColorType(m_nThemeIndex); - - if (eThemeColorType != model::ThemeColorType::Unknown) - { - aComplexColor.setSchemeColor(eThemeColorType); - - if (m_nLumMod != 10000) - aComplexColor.addTransformation({model::TransformationType::LumMod, m_nLumMod}); - - if (m_nLumOff != 0) - aComplexColor.addTransformation({model::TransformationType::LumOff, m_nLumOff}); - } - else - { - aComplexColor.setColor(m_aColor); - } - - aComplexColor.setFinalColor(m_aColor); - - return aComplexColor; - } -}; - typedef std::function<void(const OUString&, const NamedColor&)> ColorSelectFunction; class Palette diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index 5a5000bc0076..f2711b2e022a 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -71,6 +71,7 @@ public: tools::Long GetColorCount() const; tools::Long GetRecentColorCount() const; void AddRecentColor(const Color& rRecentColor, const OUString& rColorName, bool bFront = true); + void SetSplitButtonColor(const NamedColor& rColor); void SetBtnUpdater(svx::ToolboxButtonColorUpdaterBase* pBtnUpdater); void PopupColorPicker(weld::Window* pParent, const OUString& aCommand, const Color& rInitialColor); diff --git a/include/svx/colorwindow.hxx b/include/svx/colorwindow.hxx index 0a2e0a5ffeb8..c0feb10f1f61 100644 --- a/include/svx/colorwindow.hxx +++ b/include/svx/colorwindow.hxx @@ -99,7 +99,6 @@ private: std::unique_ptr<weld::CustomWeld> mxRecentColorSetWin; weld::Button* mpDefaultButton; - Link<const NamedColor&, void> maSelectedLink; DECL_DLLPRIVATE_LINK(SelectHdl, ValueSet*, void); DECL_DLLPRIVATE_LINK(SelectPaletteHdl, weld::ComboBox&, void); DECL_DLLPRIVATE_LINK(AutoColorClickHdl, weld::Button&, void); @@ -128,8 +127,6 @@ public: virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; - void SetSelectedHdl( const Link<const NamedColor&, void>& rLink ) { maSelectedLink = rLink; } - virtual void GrabFocus() override; }; diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx index 6eafd38d87b9..11d41ee4ddde 100644 --- a/include/svx/tbcontrl.hxx +++ b/include/svx/tbcontrl.hxx @@ -210,7 +210,6 @@ class SVXCORE_DLLPUBLIC SvxColorToolBoxControl final : public cppu::ImplInherita bool m_bSplitButton; sal_uInt16 m_nSlotId; ColorSelectFunction m_aColorSelectFunction; - DECL_DLLPRIVATE_LINK(SelectedHdl, const NamedColor&, void); weld::Window* GetParentFrame() const; |