summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-06-03 10:44:51 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-06-05 12:06:23 +0200
commit6c4c040d2ebc4371a706c762e7e6707875c43535 (patch)
tree940377966332042da96563af68e8efe8100a8e96 /svx
parentadce63eb131f0b20a1d72797d92f07efcee75ec4 (diff)
svx: extract theme color generation into ThemeColorPaletteManager
The generation of theme colors generation code is moved to the ThemeColorPaletteManager class, so it can be reused. Also change the GetThemeColors return type from std::vector<Color> to std::shared_ptr<theme::ColorSet> as we can now safely do that and simplifies things. Change-Id: I4a54bff889a1f97cb1e30467188dc69e07e8c518 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152588 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/source/tbxctrls/PaletteManager.cxx151
-rw-r--r--svx/source/theme/ThemeColorPaletteManager.cxx130
3 files changed, 149 insertions, 133 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index b0ce4a15165f..ed2298e526c4 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -424,6 +424,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/table/tableundo \
svx/source/table/viewcontactoftableobj \
svx/source/theme/ThemeColorChanger \
+ svx/source/theme/ThemeColorPaletteManager \
svx/source/tbxctrls/extrusioncontrols \
svx/source/tbxctrls/fontworkgallery \
svx/source/tbxctrls/linectrl \
diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx
index 1f3ab3345359..b56248825600 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -29,6 +29,7 @@
#include <svx/strings.hrc>
#include <svx/svxids.hrc>
#include <svx/dialmgr.hxx>
+
#include <tbxcolorupdate.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
@@ -51,29 +52,6 @@
#include <stack>
#include <set>
-namespace
-{
-constexpr const std::array<sal_Int16, 6> g_aPercentBlack = { 0, 50, 35, 25, 15, 5 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsBlack = { 10'000, 5'000, 6'500, 7'500, 8'500, 9'500 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsBlack = { 0, 5'000, 3'500, 2'500, 1'500, 0'500 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentLow = { 0, 90, 75, 50, 25, 10 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsLow = { 10'000, 1'000, 2'500, 5'000, 7'500, 9'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsLow = { 0, 9'000, 7'500, 5'000, 2'500, 1'000 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercent = { 0, 80, 60, 40, -25, -50 };
-constexpr const std::array<sal_Int16, 6> g_aLumMods = { 10'000, 2'000, 4'000, 6'000, 7'500, 5'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffs = { 0, 8'000, 6'000, 4'000, 0, 0 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentHigh = { 0, -10, -25, -50, -75, -90 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsHigh = { 10'000, 9'000, 7'500, 5'000, 2'500, 1'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsHigh = { 0, 0, 0, 0, 0, 0 };
-
-constexpr const std::array<sal_Int16, 6> g_aPercentWhite = { 0, -5, -15, -25, -35, -50 };
-constexpr const std::array<sal_Int16, 6> g_aLumModsWhite = { 10'000, 9'500, 8'500, 7'500, 6'500, 5'000 };
-constexpr const std::array<sal_Int16, 6> g_aLumOffsWhite = { 0, 0, 0, 0, 0, 0 };
-}
-
PaletteManager::PaletteManager() :
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
mnNumOfPalettes(3),
@@ -197,31 +175,11 @@ bool PaletteManager::GetLumModOff(sal_uInt16 nThemeIndex, sal_uInt16 nEffect, sa
if (!moThemePaletteCollection)
return false;
- auto const& aThemeColorData = moThemePaletteCollection->maData[nThemeIndex];
+ auto const& aThemeColorData = moThemePaletteCollection->maColors[nThemeIndex];
+
+ rLumMod = aThemeColorData.getLumMod(nEffect);
+ rLumOff = aThemeColorData.getLumOff(nEffect);
- switch (aThemeColorData.meType)
- {
- case ThemePaletteColorType::Black:
- rLumMod = g_aLumModsBlack[nEffect];
- rLumOff = g_aLumOffsBlack[nEffect];
- break;
- case ThemePaletteColorType::White:
- rLumMod = g_aLumModsWhite[nEffect];
- rLumOff = g_aLumOffsWhite[nEffect];
- break;
- case ThemePaletteColorType::Low:
- rLumMod = g_aLumModsLow[nEffect];
- rLumOff = g_aLumOffsLow[nEffect];
- break;
- case ThemePaletteColorType::High:
- rLumMod = g_aLumModsHigh[nEffect];
- rLumOff = g_aLumOffsHigh[nEffect];
- break;
- case ThemePaletteColorType::Normal:
- rLumMod = g_aLumMods[nEffect];
- rLumOff = g_aLumOffs[nEffect];
- break;
- }
return true;
}
@@ -246,95 +204,22 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet)
SfxObjectShell* pObjectShell = SfxObjectShell::Current();
if (pObjectShell)
{
- std::vector<Color> aColors = pObjectShell->GetThemeColors();
- mnColorCount = aColors.size();
+ auto pColorSet = pObjectShell->GetThemeColors();
+ mnColorCount = 12;
rColorSet.Clear();
- if (aColors.size() >= 12)
- {
- const std::array<OUString, 12> aColorNames = {
- SvxResId(RID_SVXSTR_THEME_COLOR1), SvxResId(RID_SVXSTR_THEME_COLOR2),
- SvxResId(RID_SVXSTR_THEME_COLOR3), SvxResId(RID_SVXSTR_THEME_COLOR4),
- SvxResId(RID_SVXSTR_THEME_COLOR5), SvxResId(RID_SVXSTR_THEME_COLOR6),
- SvxResId(RID_SVXSTR_THEME_COLOR7), SvxResId(RID_SVXSTR_THEME_COLOR8),
- SvxResId(RID_SVXSTR_THEME_COLOR9), SvxResId(RID_SVXSTR_THEME_COLOR10),
- SvxResId(RID_SVXSTR_THEME_COLOR11), SvxResId(RID_SVXSTR_THEME_COLOR12),
- };
-
- sal_uInt16 nItemId = 0;
-
- moThemePaletteCollection = ThemePaletteCollection();
- for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor)
- {
- Color aColor = aColors[nColor];
- basegfx::BColor aBColor = basegfx::utils::rgb2hsl(aColor.getBColor());
- double aLuminanceValue = aBColor.getBlue() * 255.0;
- moThemePaletteCollection->maData[nColor].maColor = aColor;
-
- if (aLuminanceValue < 0.5)
- moThemePaletteCollection->maData[nColor].meType = ThemePaletteColorType::Black;
- else if (aLuminanceValue > 254.5)
- moThemePaletteCollection->maData[nColor].meType = ThemePaletteColorType::White;
- else if (aLuminanceValue < 50.5)
- moThemePaletteCollection->maData[nColor].meType = ThemePaletteColorType::Low;
- else if (aLuminanceValue > 203.5)
- moThemePaletteCollection->maData[nColor].meType = ThemePaletteColorType::High;
- else
- moThemePaletteCollection->maData[nColor].meType = ThemePaletteColorType::Normal;
- }
+ sal_uInt16 nItemId = 0;
- // Each row is one effect type (no effect + each type).
- for (size_t nEffect : {0, 1, 2, 3, 4, 5})
+ svx::ThemeColorPaletteManager aThemeColorManager(pColorSet);
+ moThemePaletteCollection = aThemeColorManager.generate();
+
+ // Each row is one effect type (no effect + each type).
+ for (size_t nEffect : {0, 1, 2, 3, 4, 5})
+ {
+ // Each column is one color type.
+ for (auto const& rColorData : moThemePaletteCollection->maColors)
{
- // Each column is one color type.
- for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor)
- {
- auto const& aThemeColorData = moThemePaletteCollection->maData[nColor];
- Color aColor = aThemeColorData.maColor;
- sal_Int16 nColorTemplateValue = 0;
- switch (aThemeColorData.meType)
- {
- case ThemePaletteColorType::Black:
- nColorTemplateValue = g_aPercentBlack[nEffect];
- break;
- case ThemePaletteColorType::White:
- nColorTemplateValue = g_aPercentWhite[nEffect];
- break;
- case ThemePaletteColorType::Low:
- nColorTemplateValue = g_aPercentLow[nEffect];
- break;
- case ThemePaletteColorType::High:
- nColorTemplateValue = g_aPercentHigh[nEffect];
- break;
- case ThemePaletteColorType::Normal:
- nColorTemplateValue = g_aPercent[nEffect];
- break;
- }
-
- sal_Int16 nLumMod = 10'000;
- sal_Int16 nLumOff = 0;
- GetLumModOff(nColor, nEffect, nLumMod, nLumOff);
- aColor.ApplyLumModOff(nLumMod, nLumOff);
-
- OUString aColorName;
- if (nColorTemplateValue > 0)
- {
- OUString aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_LIGHTER);
- aColorName = aTemplate.replaceAll("$THEME_NAME", aColorNames[nColor]);
- aColorName = aColorName.replaceAll("$PERCENTAGE", OUString::number(std::abs(nColorTemplateValue)));
-
- }
- else if (nColorTemplateValue < 0)
- {
- OUString aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_DARKER);
- aColorName = aTemplate.replaceAll("$THEME_NAME", aColorNames[nColor]);
- aColorName = aColorName.replaceAll("$PERCENTAGE", OUString::number(std::abs(nColorTemplateValue)));
- }
- else
- {
- aColorName = aColorNames[nColor];
- }
- rColorSet.InsertItem(nItemId++, aColor, aColorName);
- }
+ auto const& rEffect = rColorData.maEffects[nEffect];
+ rColorSet.InsertItem(nItemId++, rEffect.maColor, rEffect.maColorName);
}
}
}
diff --git a/svx/source/theme/ThemeColorPaletteManager.cxx b/svx/source/theme/ThemeColorPaletteManager.cxx
new file mode 100644
index 000000000000..82ebb38fb69a
--- /dev/null
+++ b/svx/source/theme/ThemeColorPaletteManager.cxx
@@ -0,0 +1,130 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+#include <svx/theme/ThemeColorPaletteManager.hxx>
+
+#include <basegfx/color/bcolortools.hxx>
+#include <tools/color.hxx>
+#include <unotools/resmgr.hxx>
+#include <svx/dialmgr.hxx>
+#include <svx/strings.hrc>
+#include <docmodel/theme/ColorSet.hxx>
+
+#include <array>
+
+namespace
+{
+constexpr const std::array<const std::array<sal_Int16, 6>, 5> g_aLumMods = {
+ std::array<sal_Int16, 6>{ 10'000, 5'000, 6'500, 7'500, 8'500, 9'500 },
+ std::array<sal_Int16, 6>{ 10'000, 1'000, 2'500, 5'000, 7'500, 9'000 },
+ std::array<sal_Int16, 6>{ 10'000, 2'000, 4'000, 6'000, 7'500, 5'000 },
+ std::array<sal_Int16, 6>{ 10'000, 9'000, 7'500, 5'000, 2'500, 1'000 },
+ std::array<sal_Int16, 6>{ 10'000, 9'500, 8'500, 7'500, 6'500, 5'000 },
+};
+
+constexpr const std::array<const std::array<sal_Int16, 6>, 5> g_aLumOffs = {
+ std::array<sal_Int16, 6>{ 0, 5'000, 3'500, 2'500, 1'500, 0'500 },
+ std::array<sal_Int16, 6>{ 0, 9'000, 7'500, 5'000, 2'500, 1'000 },
+ std::array<sal_Int16, 6>{ 0, 8'000, 6'000, 4'000, 0, 0 },
+ std::array<sal_Int16, 6>{ 0, 0, 0, 0, 0, 0 },
+ std::array<sal_Int16, 6>{ 0, 0, 0, 0, 0, 0 },
+};
+
+} // end anonymous namespace
+
+namespace svx
+{
+ThemeColorPaletteManager::ThemeColorPaletteManager(
+ std::shared_ptr<model::ColorSet> const& pColorSet)
+ : m_pColorSet(pColorSet)
+{
+}
+
+svx::ThemePaletteCollection ThemeColorPaletteManager::generate()
+{
+ svx::ThemePaletteCollection aThemePaletteCollection;
+
+ const std::array<OUString, 12> aColorNames = {
+ SvxResId(RID_SVXSTR_THEME_COLOR1), SvxResId(RID_SVXSTR_THEME_COLOR2),
+ SvxResId(RID_SVXSTR_THEME_COLOR3), SvxResId(RID_SVXSTR_THEME_COLOR4),
+ SvxResId(RID_SVXSTR_THEME_COLOR5), SvxResId(RID_SVXSTR_THEME_COLOR6),
+ SvxResId(RID_SVXSTR_THEME_COLOR7), SvxResId(RID_SVXSTR_THEME_COLOR8),
+ SvxResId(RID_SVXSTR_THEME_COLOR9), SvxResId(RID_SVXSTR_THEME_COLOR10),
+ SvxResId(RID_SVXSTR_THEME_COLOR11), SvxResId(RID_SVXSTR_THEME_COLOR12),
+ };
+
+ for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor)
+ {
+ auto eThemeType = model::convertToThemeColorType(nColor);
+ if (eThemeType == model::ThemeColorType::Unknown)
+ continue;
+
+ auto& aThemeColorData = aThemePaletteCollection.maColors[nColor];
+ aThemeColorData.meThemeColorType = eThemeType;
+
+ Color aThemeColor = m_pColorSet->getColor(eThemeType);
+ aThemeColorData.maBaseColor = aThemeColor;
+
+ basegfx::BColor aHSLColor = basegfx::utils::rgb2hsl(aThemeColor.getBColor());
+ double aLuminanceValue = aHSLColor.getBlue() * 255.0;
+
+ for (size_t nEffect : { 0, 1, 2, 3, 4, 5 })
+ {
+ auto& rEffect = aThemeColorData.maEffects[nEffect];
+ size_t nIndex = 0;
+
+ if (aLuminanceValue < 0.5)
+ nIndex = 0; // Black
+ else if (aLuminanceValue > 254.5)
+ nIndex = 4; // White
+ else if (aLuminanceValue < 50.5)
+ nIndex = 1; // Low
+ else if (aLuminanceValue > 203.5)
+ nIndex = 3; // High
+ else
+ nIndex = 2; // Middle
+
+ rEffect.mnLumOff = g_aLumOffs[nIndex][nEffect];
+ rEffect.mnLumMod = g_aLumMods[nIndex][nEffect];
+
+ rEffect.maColor = aThemeColor;
+ rEffect.maColor.ApplyLumModOff(rEffect.mnLumMod, rEffect.mnLumOff);
+
+ OUString aColorName;
+ sal_Int16 nPercent = rEffect.getPercentage();
+
+ OUString aTemplate;
+ if (nPercent > 0)
+ {
+ aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_LIGHTER);
+ }
+ else if (nPercent < 0)
+ {
+ aTemplate = SvxResId(RID_SVXSTR_THEME_EFFECT_DARKER);
+ }
+
+ if (!aTemplate.isEmpty())
+ {
+ aColorName = aTemplate.replaceAll("$THEME_NAME", aColorNames[nColor]);
+ aColorName
+ = aColorName.replaceAll("$PERCENTAGE", OUString::number(std::abs(nPercent)));
+ }
+ else
+ {
+ aColorName = aColorNames[nColor];
+ }
+ rEffect.maColorName = aColorName;
+ }
+ }
+ return aThemePaletteCollection;
+}
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */