diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-12-21 08:51:56 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-29 14:56:12 +0200 |
commit | 286b586f633966a0530d4e74dc304701ee9d769f (patch) | |
tree | 2691bf035780c45daa803691d1124aed1ab7c3fc /svx | |
parent | 349fccc2840a84520054bbbbb6864fdd8f2b8112 (diff) |
sd theme: allow setting color effects in the chardlg
Which means not only the 12 colors from the theme are offered (which
comes from the current master page), but also lighter/darker variants.
And once these are selected, their theme index and luminance modulation
/ offset is also remembered. This means if you pick light blue and later
change accent1 from blue to orange, you get light orange out of the box.
(cherry picked from commit 4f140ebac1f971d72f5bb59ee23a3fe248c4d16e)
Change-Id: Ia83b8971ad894d02ed4ec5ca914684fc9cf9a677
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136609
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 52 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 4 |
2 files changed, 52 insertions, 4 deletions
diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 4ed6d3059187..c9ca2a3f70ab 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -43,6 +43,17 @@ #include <palettes.hxx> +namespace +{ +// Luminance modulation for the 6 effect presets. +// 10000 is the default. +sal_Int16 g_aLumMods[] = { 10000, 2000, 4000, 6000, 7500, 5000 }; + +// Luminance offset for the 6 effect presets. +// 0 is the default. +sal_Int16 g_aLumOffs[] = { 0, 8000, 6000, 4000, 0, 0 }; +} + PaletteManager::PaletteManager() : mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()), mnNumOfPalettes(3), @@ -131,6 +142,17 @@ bool PaletteManager::IsThemePaletteSelected() const return mnCurrentPalette == mnNumOfPalettes - 2; } +void PaletteManager::GetThemeIndexLumModOff(sal_uInt16 nItemId, sal_Int16& rThemeIndex, + sal_Int16& rLumMod, sal_Int16& rLumOff) +{ + // Each column is the same color with different effects. + rThemeIndex = nItemId % 12; + + // Each row is the same effect with different colors. + rLumMod = g_aLumMods[nItemId / 12]; + rLumOff = g_aLumOffs[nItemId / 12]; +} + void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) { if( mnCurrentPalette == 0) @@ -156,7 +178,13 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) rColorSet.Clear(); if (aColors.size() >= 12) { - std::vector<OUString> aNames = { + std::vector<OUString> aEffectNames = { + SvxResId(RID_SVXSTR_THEME_EFFECT1), SvxResId(RID_SVXSTR_THEME_EFFECT2), + SvxResId(RID_SVXSTR_THEME_EFFECT3), SvxResId(RID_SVXSTR_THEME_EFFECT4), + SvxResId(RID_SVXSTR_THEME_EFFECT5), + }; + + std::vector<OUString> 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), @@ -164,9 +192,27 @@ void PaletteManager::ReloadColorSet(SvxColorValueSet &rColorSet) SvxResId(RID_SVXSTR_THEME_COLOR9), SvxResId(RID_SVXSTR_THEME_COLOR10), SvxResId(RID_SVXSTR_THEME_COLOR11), SvxResId(RID_SVXSTR_THEME_COLOR12), }; - for (int i = 0; i < 12; ++i) + + sal_uInt16 nItemId = 0; + // Each row is one effect type (no effect + each type). + for (size_t nEffect = 0; nEffect < aEffectNames.size() + 1; ++nEffect) { - rColorSet.InsertItem(i, aColors[i], aNames[i]); + // Each column is one color type. + for (size_t nColor = 0; nColor < aColorNames.size(); ++nColor) + { + Color aColor = aColors[nColor]; + aColor.ApplyLumModOff(g_aLumMods[nEffect], g_aLumOffs[nEffect]); + OUString aColorName; + if (nEffect == 0) + { + aColorName = aColorNames[nColor]; + } + else + { + aColorName = aEffectNames[nEffect - 1].replaceAll("%1", aColorNames[nColor]); + } + rColorSet.InsertItem(nItemId++, aColor, aColorName); + } } } } diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index eb16366d55d2..a649578e0e51 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1972,7 +1972,9 @@ IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void) auto aNamedThemedColor = svx::NamedThemedColor::FromNamedColor(aNamedColor); if (mxPaletteManager->IsThemePaletteSelected()) { - aNamedThemedColor.m_nThemeIndex = pColorSet->GetSelectedItemId(); + PaletteManager::GetThemeIndexLumModOff( + pColorSet->GetSelectedItemId(), aNamedThemedColor.m_nThemeIndex, + aNamedThemedColor.m_nLumMod, aNamedThemedColor.m_nLumOff); } aColorSelectFunction(sCommand, aNamedThemedColor); } |