cui/qa/uitest/tabpages/tpcolor.py |   69 +++++++++++++++++++++++++++++++
 cui/source/inc/cuitabarea.hxx     |    4 -
 cui/source/tabpages/tpcolor.cxx   |   84 +++++++++++++++++++++++---------------
 3 files changed, 124 insertions(+), 33 deletions(-)

New commits:
commit 5dd4802c73dac4c3bd5c609562ce994d3b51e6a9
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed Mar 30 19:57:10 2022 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Mar 31 11:43:41 2022 +0200

    sd theme: add UI (area dialog) for shape fill color
    
    SvxColorTabPage::FillItemSet() has to produce a color item that has the
    theme index, which means SvxColorTabPage::SelectValSetHdl_Impl() has to
    change the current color to an svx::NamedThemedColor.
    
    The rest is just fallout from this, now that the current color has
    theming metadata.
    
    Change-Id: If0018c651239ba74f45745e69e41ff7040ac9b97
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132327
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/cui/qa/uitest/tabpages/tpcolor.py 
b/cui/qa/uitest/tabpages/tpcolor.py
new file mode 100644
index 000000000000..e6ae91adaac3
--- /dev/null
+++ b/cui/qa/uitest/tabpages/tpcolor.py
@@ -0,0 +1,69 @@
+#
+# 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/.
+#
+
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.framework import UITestCase
+from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import select_by_text
+
+
+# Test for cui/source/tabpages/tpcolor.cxx.
+class Test(UITestCase):
+
+    def testSvxColorTabPageTheme(self):
+        # Given an Impress document with a theme:
+        with self.ui_test.create_doc_in_start_center("impress") as component:
+            template = self.xUITest.getTopFocusWindow()
+            
self.ui_test.close_dialog_through_button(template.getChild("close"))
+            doc = self.xUITest.getTopFocusWindow()
+            editWin = doc.getChild("impress_win")
+            # Set theme colors.
+            drawPage = component.getDrawPages().getByIndex(0)
+            master = drawPage.MasterPage
+            theme = mkPropertyValues({
+                "Name": "nameA",
+                "ColorSchemeName": "colorSetA",
+                "ColorScheme": tuple([
+                    0x000000,  # dk1
+                    0x000000,  # lt1
+                    0x000000,  # dk2
+                    0x000000,  # lt2
+                    0x0000ff,  # accent1
+                    0x000000,  # accent2
+                    0x000000,  # accent3
+                    0x000000,  # accent4
+                    0x000000,  # accent5
+                    0x000000,  # accent6
+                    0x000000,  # hlink
+                    0x000000,  # folHlink
+                ])
+            })
+            master.Theme = theme
+            # Select the title shape.
+            editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
+
+            # When using right click -> Area to refer to a theme for shape 
fill:
+            with 
self.ui_test.execute_dialog_through_command(".uno:FormatArea") as xDialog:
+                tabControl = xDialog.getChild("tabcontrol")
+                # Area
+                select_pos(tabControl, "0")
+                # Color
+                btnColor = xDialog.getChild("btncolor")
+                btnColor.executeAction("CLICK", tuple())
+                paletteSelector = xDialog.getChild("paletteselector")
+                select_by_text(paletteSelector, "Theme colors")
+                colorSelector = xDialog.getChild("colorset")
+                colorSelector.executeAction("CHOOSE", mkPropertyValues({"POS": 
"4"}))
+
+            # Then make sure the doc model is updated accordingly:
+            shape = drawPage.getByIndex(0)
+            # Without the accompanying fix in place, this test would have 
failed with:
+            # AssertionError: -1 != 4
+            # i.e. the theme metadata of the selected fill color was lost.
+            self.assertEqual(shape.FillColorTheme, 4)
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx
index 943e3298bc44..aa4e07343bd2 100644
--- a/cui/source/inc/cuitabarea.hxx
+++ b/cui/source/inc/cuitabarea.hxx
@@ -640,7 +640,7 @@ private:
     ColorModel          eCM;
 
     Color               aPreviousColor;
-    Color               aCurrentColor;
+    svx::NamedThemedColor aCurrentColor;
 
     PaletteManager maPaletteManager;
     SvxXRectPreview m_aCtlPreviewOld;
@@ -696,7 +696,7 @@ private:
     DECL_LINK(SelectPaletteLBHdl, weld::ComboBox&, void);
     DECL_LINK( SelectValSetHdl_Impl, ValueSet*, void );
     DECL_LINK( SelectColorModeHdl_Impl, weld::Toggleable&, void );
-    void ChangeColor(const Color &rNewColor, bool bUpdatePreset = true);
+    void ChangeColor(const svx::NamedThemedColor &rNewColor, bool 
bUpdatePreset = true);
     void SetColorModel(ColorModel eModel);
     void ChangeColorModel();
     void UpdateColorValues( bool bUpdatePreset = true );
diff --git a/cui/source/tabpages/tpcolor.cxx b/cui/source/tabpages/tpcolor.cxx
index 6c8d6386bb56..507f93f58ef6 100644
--- a/cui/source/tabpages/tpcolor.cxx
+++ b/cui/source/tabpages/tpcolor.cxx
@@ -203,7 +203,9 @@ void SvxColorTabPage::ActivatePage( const SfxItemSet& )
         ChangeColorModel();
 
         const Color aColor = pFillColorItem->GetColorValue();
-        ChangeColor( aColor );
+        svx::NamedThemedColor aThemedColor;
+        aThemedColor.m_aColor = aColor;
+        ChangeColor( aThemedColor );
         sal_Int32 nPos = FindInPalette( aColor );
 
         if ( nPos != -1 )
@@ -230,12 +232,17 @@ bool SvxColorTabPage::FillItemSet( SfxItemSet* rSet )
 {
     Color aColor = m_xValSetColorList->GetItemColor( 
m_xValSetColorList->GetSelectedItemId() );
     OUString sColorName;
-    if ( aCurrentColor == aColor )
+    if ( aCurrentColor.m_aColor == aColor )
        sColorName = m_xValSetColorList->GetItemText( 
m_xValSetColorList->GetSelectedItemId() );
     else
-       sColorName = "#" + aCurrentColor.AsRGBHexString().toAsciiUpperCase();
-    maPaletteManager.AddRecentColor( aCurrentColor, sColorName );
-    rSet->Put( XFillColorItem( sColorName, aCurrentColor ) );
+       sColorName = "#" + 
aCurrentColor.m_aColor.AsRGBHexString().toAsciiUpperCase();
+    maPaletteManager.AddRecentColor( aCurrentColor.m_aColor, sColorName );
+    XFillColorItem aColorItem( sColorName, aCurrentColor.m_aColor );
+    if (aCurrentColor.m_nThemeIndex != -1)
+    {
+        aColorItem.GetThemeColor().SetThemeIndex(aCurrentColor.m_nThemeIndex);
+    }
+    rSet->Put( aColorItem );
     rSet->Put( XFillStyleItem( drawing::FillStyle_SOLID ) );
     return true;
 }
@@ -265,7 +272,9 @@ void SvxColorTabPage::Reset( const SfxItemSet* rSet )
     SetColorModel( eCM );
     ChangeColorModel();
 
-    ChangeColor(aNewColor);
+    svx::NamedThemedColor aThemedColor;
+    aThemedColor.m_aColor = aNewColor;
+    ChangeColor(aThemedColor);
 
     UpdateModified();
 }
@@ -279,12 +288,12 @@ std::unique_ptr<SfxTabPage> 
SvxColorTabPage::Create(weld::Container* pPage, weld
 IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, weld::SpinButton&, void)
 {
     // read current MtrFields, if cmyk, then k-value as transparency
-    aCurrentColor = 
Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
+    aCurrentColor.m_aColor = 
Color(static_cast<sal_uInt8>(PercentToColor_Impl(m_xRcustom->get_value())),
                           
static_cast<sal_uInt8>(PercentToColor_Impl(m_xGcustom->get_value())),
                           
static_cast<sal_uInt8>(PercentToColor_Impl(m_xBcustom->get_value())));
     UpdateColorValues();
 
-    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
+    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
     m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
 
     m_aCtlPreviewNew.Invalidate();
@@ -293,13 +302,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, SpinValueHdl_Impl, 
weld::SpinButton&, void)
 IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, 
weld::MetricSpinButton&, void)
 {
     // read current MtrFields, if cmyk, then k-value as transparency
-    aCurrentColor = Color(ColorTransparency, 
static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
+    aCurrentColor.m_aColor = Color(ColorTransparency, 
static_cast<sal_uInt8>(PercentToColor_Impl(m_xKcustom->get_value(FieldUnit::NONE))),
                           
static_cast<sal_uInt8>(PercentToColor_Impl(m_xCcustom->get_value(FieldUnit::NONE))),
                           
static_cast<sal_uInt8>(PercentToColor_Impl(m_xYcustom->get_value(FieldUnit::NONE))),
                           
static_cast<sal_uInt8>(PercentToColor_Impl(m_xMcustom->get_value(FieldUnit::NONE))));
-    ConvertColorValues (aCurrentColor, ColorModel::RGB);
+    ConvertColorValues (aCurrentColor.m_aColor, ColorModel::RGB);
 
-    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
+    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
     m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
 
     m_aCtlPreviewNew.Invalidate();
@@ -307,10 +316,10 @@ IMPL_LINK_NOARG(SvxColorTabPage, MetricSpinValueHdl_Impl, 
weld::MetricSpinButton
 
 IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl, weld::Entry&, void)
 {
-    aCurrentColor = m_xHexcustom->GetColor();
+    aCurrentColor.m_aColor = m_xHexcustom->GetColor();
     UpdateColorValues();
 
-    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
+    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
     m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
 
     m_aCtlPreviewNew.Invalidate();
@@ -364,13 +373,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl, 
weld::Button&, void)
         sal_Int32 nSize = aCustomColorList.getLength();
         aCustomColorList.realloc( nSize + 1 );
         aCustomColorNameList.realloc( nSize + 1 );
-        aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor);
+        aCustomColorList.getArray()[nSize] = sal_Int32(aCurrentColor.m_aColor);
         aCustomColorNameList.getArray()[nSize] = aName;
         
officecfg::Office::Common::UserColors::CustomColor::set(aCustomColorList, 
batch);
         
officecfg::Office::Common::UserColors::CustomColorName::set(aCustomColorNameList,
 batch);
         batch->commit();
         sal_uInt16 nId = m_xValSetColorList->GetItemId(nSize - 1);
-        m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor, aName );
+        m_xValSetColorList->InsertItem( nId + 1 , aCurrentColor.m_aColor, 
aName );
         m_xValSetColorList->SelectItem( nId + 1 );
         m_xBtnDelete->set_sensitive(false);
         m_xBtnDelete->set_tooltip_text( CuiResId(RID_CUISTR_DELETEUSERCOLOR2) 
);
@@ -384,13 +393,13 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl, 
weld::Button&, void)
 {
     SvColorDialog aColorDlg;
 
-    aColorDlg.SetColor (aCurrentColor);
+    aColorDlg.SetColor (aCurrentColor.m_aColor);
     aColorDlg.SetMode( svtools::ColorPickerMode::Modify );
 
     if (aColorDlg.Execute(GetFrameWeld()) == RET_OK)
     {
         Color aPreviewColor = aColorDlg.GetColor();
-        aCurrentColor = aPreviewColor;
+        aCurrentColor.m_aColor = aPreviewColor;
         UpdateColorValues( false );
         // fill ItemSet and pass it on to XOut
         rXFSet.Put( XFillColorItem( OUString(), aPreviewColor ) );
@@ -487,7 +496,20 @@ IMPL_LINK(SvxColorTabPage, SelectValSetHdl_Impl, 
ValueSet*, pValSet, void)
     rXFSet.Put( XFillColorItem( OUString(), aColor ) );
     m_aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     m_aCtlPreviewNew.Invalidate();
-    ChangeColor(aColor, false);
+
+    bool bThemePaletteSelected = false;
+    if (pValSet == m_xValSetColorList.get())
+    {
+        bThemePaletteSelected = maPaletteManager.IsThemePaletteSelected();
+    }
+    svx::NamedThemedColor aThemedColor;
+    aThemedColor.m_aColor = aColor;
+    if (bThemePaletteSelected)
+    {
+        PaletteManager::GetThemeIndexLumModOff(nPos, 
aThemedColor.m_nThemeIndex, aThemedColor.m_nLumMod, aThemedColor.m_nLumOff);
+    }
+
+    ChangeColor(aThemedColor, false);
 
     if (pValSet == m_xValSetColorList.get())
     {
@@ -550,13 +572,13 @@ IMPL_STATIC_LINK_NOARG(SvxColorTabPage, 
OnMoreColorsClick, weld::Button&, void)
     comphelper::dispatchCommand(".uno:AdditionsDialog", aArgs);
 }
 
-void SvxColorTabPage::ChangeColor(const Color &rNewColor, bool bUpdatePreset )
+void SvxColorTabPage::ChangeColor(const svx::NamedThemedColor &rNewColor, bool 
bUpdatePreset )
 {
-    aPreviousColor = rNewColor;
+    aPreviousColor = rNewColor.m_aColor;
     aCurrentColor = rNewColor;
     UpdateColorValues( bUpdatePreset );
     // fill ItemSet and pass it on to XOut
-    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor ) );
+    rXFSet.Put( XFillColorItem( OUString(), aCurrentColor.m_aColor ) );
     m_aCtlPreviewNew.SetAttributes(aXFillAttr.GetItemSet());
     m_aCtlPreviewNew.Invalidate();
 }
@@ -598,12 +620,12 @@ void SvxColorTabPage::UpdateColorValues( bool 
bUpdatePreset )
     if (eCM != ColorModel::RGB)
     {
         ConvertColorValues (aPreviousColor, eCM );
-        ConvertColorValues (aCurrentColor, eCM);
+        ConvertColorValues (aCurrentColor.m_aColor, eCM);
 
-        m_xCcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ), 
FieldUnit::PERCENT );
-        m_xMcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ), 
FieldUnit::PERCENT );
-        m_xYcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() 
), FieldUnit::PERCENT );
-        m_xKcustom->set_value( ColorToPercent_Impl( 255 - 
aCurrentColor.GetAlpha() ), FieldUnit::PERCENT );
+        m_xCcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetRed() ), FieldUnit::PERCENT );
+        m_xMcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetBlue() ), FieldUnit::PERCENT );
+        m_xYcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetGreen() ), FieldUnit::PERCENT );
+        m_xKcustom->set_value( ColorToPercent_Impl( 255 - 
aCurrentColor.m_aColor.GetAlpha() ), FieldUnit::PERCENT );
 
         if( bUpdatePreset )
         {
@@ -618,14 +640,14 @@ void SvxColorTabPage::UpdateColorValues( bool 
bUpdatePreset )
         }
 
         ConvertColorValues (aPreviousColor, ColorModel::RGB);
-        ConvertColorValues (aCurrentColor, ColorModel::RGB);
+        ConvertColorValues (aCurrentColor.m_aColor, ColorModel::RGB);
     }
     else
     {
-        m_xRcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetRed() ) );
-        m_xGcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetGreen() ) 
);
-        m_xBcustom->set_value( ColorToPercent_Impl( aCurrentColor.GetBlue() ) 
);
-        m_xHexcustom->SetColor( aCurrentColor );
+        m_xRcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetRed() ) );
+        m_xGcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetGreen() ) );
+        m_xBcustom->set_value( ColorToPercent_Impl( 
aCurrentColor.m_aColor.GetBlue() ) );
+        m_xHexcustom->SetColor( aCurrentColor.m_aColor );
 
         if( bUpdatePreset )
         {

Reply via email to