diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-12-20 08:46:40 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-12-20 11:31:53 +0100 |
commit | 7d5984d7aed2bafcb599882b66bb0dde2d22ff3f (patch) | |
tree | 6565464f4d754a7c45700ae9b63d28aafa59b8da /cui | |
parent | 24ea26f55ee4e8a3c69b6dc9911a8c42e56f1eb2 (diff) |
sd theme: allow setting the color's theme index in the chardlg
This routes not only the rgb color and a name, but also a theme index
from the color picker to the chardlg (only there as a start).
That way the picked color will be updated if the master page theme
changes.
Change-Id: I7a45d7cf63c7c36013e4656c66d9b2dbc3aa0b88
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127135
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'cui')
-rw-r--r-- | cui/qa/uitest/dialogs/chardlg.py | 66 | ||||
-rw-r--r-- | cui/source/tabpages/chardlg.cxx | 22 | ||||
-rw-r--r-- | cui/source/tabpages/themepage.cxx | 14 |
3 files changed, 95 insertions, 7 deletions
diff --git a/cui/qa/uitest/dialogs/chardlg.py b/cui/qa/uitest/dialogs/chardlg.py index 49adfe6d9980..c49c08dbc687 100644 --- a/cui/qa/uitest/dialogs/chardlg.py +++ b/cui/qa/uitest/dialogs/chardlg.py @@ -8,6 +8,7 @@ from libreoffice.uno.propertyvalue import mkPropertyValues from uitest.framework import UITestCase from uitest.uihelper.common import select_pos from uitest.uihelper.common import get_state_as_dict +from uitest.uihelper.common import select_by_text # Test for cui/source/tabpages/chardlg.cxx. class Test(UITestCase): @@ -43,6 +44,71 @@ class Test(UITestCase): # COL_AUTO. self.assertEqual(shape.CharTransparence, 5) + def testSvxCharEffectsPageTheme(self): + # Given a document with a document theme: + # Start Impress. + 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 + 0x000000, # 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"})) + editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"})) + self.xUITest.executeCommand(".uno:SelectAll") + + # Now use Format -> Character. + with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog: + xTabs = xDialog.getChild("tabcontrol") + # Select RID_SVXPAGE_CHAR_EFFECTS. + select_pos(xTabs, "1") + + # When setting the shape text color to accent 1: + accent1 = xDialog.getChild("fontcolorlb") + accent1.executeAction("OPENLIST", tuple()) + floatWindow = self.xUITest.getFloatWindow() + paletteSelector = floatWindow.getChild("palette_listbox") + select_by_text(paletteSelector, "Theme colors") + colorSet = floatWindow.getChild("colorset") + colorSet.executeAction("CHOOSE", mkPropertyValues({"POS": "4"})) + + # Then make sure the doc model has the correct color theme index: + drawPage = component.getDrawPages().getByIndex(0) + shape = drawPage.getByIndex(0) + paragraphs = shape.createEnumeration() + paragraph = paragraphs.nextElement() + portions = paragraph.createEnumeration() + portion = portions.nextElement() + + # Without the accompanying fix in place, this test would have failed with: + # AssertionError: -1 != 4 + # i.e. no theme index was set, instead of accent1 (index into the above color scheme). + self.assertEqual(portion.CharColorTheme, 4) + def testSvxCharEffectsPageWriter(self): # Start Writer. with self.ui_test.create_doc_in_start_center("writer") as component: diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx index 90caf0ca36b8..b9337008d1d9 100644 --- a/cui/source/tabpages/chardlg.cxx +++ b/cui/source/tabpages/chardlg.cxx @@ -1573,28 +1573,38 @@ bool SvxCharEffectsPage::FillItemSetColor_Impl( SfxItemSet& rSet ) sal_uInt16 nWhich = GetWhich( SID_ATTR_CHAR_COLOR ); const SfxItemSet& rOldSet = GetItemSet(); - Color aSelectedColor; + svx::NamedThemedColor aSelectedColor; bool bChanged = m_bNewFontColor; if (bChanged) { - aSelectedColor = m_xFontColorLB->GetSelectEntryColor(); + aSelectedColor = m_xFontColorLB->GetSelectedEntryThemedColor(); if (m_xFontTransparencyMtr->get_value_changed_from_saved()) { double fTransparency = m_xFontTransparencyMtr->get_value(FieldUnit::PERCENT) * 255.0 / 100; - aSelectedColor.SetAlpha(255 - static_cast<sal_uInt8>(basegfx::fround(fTransparency))); + aSelectedColor.m_aColor.SetAlpha(255 - static_cast<sal_uInt8>(basegfx::fround(fTransparency))); } if (m_bOrigFontColor) - bChanged = aSelectedColor != m_aOrigFontColor; - if (m_bEnableNoneFontColor && bChanged && aSelectedColor == COL_NONE_COLOR) + bChanged = aSelectedColor.m_aColor != m_aOrigFontColor; + if (m_bEnableNoneFontColor && bChanged && aSelectedColor.m_aColor == COL_NONE_COLOR) bChanged = false; } if (bChanged) - rSet.Put( SvxColorItem( aSelectedColor, nWhich ) ); + { + SvxColorItem aItem( aSelectedColor.m_aColor, nWhich ); + + if (aSelectedColor.m_nThemeIndex != -1) + { + // The color was picked from the theme palette, remember its index. + aItem.SetThemeIndex(aSelectedColor.m_nThemeIndex); + } + + rSet.Put(aItem); + } else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) ) rSet.InvalidateItem(nWhich); diff --git a/cui/source/tabpages/themepage.cxx b/cui/source/tabpages/themepage.cxx index c01d72def6cc..07d24649fb5d 100644 --- a/cui/source/tabpages/themepage.cxx +++ b/cui/source/tabpages/themepage.cxx @@ -73,7 +73,19 @@ void SvxThemePage::Reset(const SfxItemSet* pAttrs) auto itTheme = rGrabBagItem.GetGrabBag().find("Theme"); if (itTheme == rGrabBagItem.GetGrabBag().end()) { - SAL_WARN("cui.tabpages", "SvxThemePage::Reset: no Theme"); + // No theme was defined previously, allow specifying colors. + m_xDk1->set_sensitive(true); + m_xLt1->set_sensitive(true); + m_xDk2->set_sensitive(true); + m_xLt2->set_sensitive(true); + m_xAccent1->set_sensitive(true); + m_xAccent2->set_sensitive(true); + m_xAccent3->set_sensitive(true); + m_xAccent4->set_sensitive(true); + m_xAccent5->set_sensitive(true); + m_xAccent6->set_sensitive(true); + m_xHlink->set_sensitive(true); + m_xFolHlink->set_sensitive(true); return; } |