diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-07-11 20:25:23 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-07-13 09:15:30 +0200 |
commit | 8e4fb36a69d517bc5111d64d12b2c7df4f9791de (patch) | |
tree | bc28266cb145e53b4dc4d25e866290d50a2a68fd /sc | |
parent | e40f69419e86fb9d189032410686c5c06efbdbbb (diff) |
sc: add test for changing theme colors and undo/redo
Change-Id: Ieaae64cd6cfd96b8c1627cf1c3935bc546a36617
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154306
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/CppunitTest_sc_ucalc_document_themes.mk | 3 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_DocumentThemes.cxx | 126 | ||||
-rw-r--r-- | sc/source/ui/inc/ThemeColorChanger.hxx | 3 |
3 files changed, 129 insertions, 3 deletions
diff --git a/sc/CppunitTest_sc_ucalc_document_themes.mk b/sc/CppunitTest_sc_ucalc_document_themes.mk index b779a643ba19..c2e5bee7f8ef 100644 --- a/sc/CppunitTest_sc_ucalc_document_themes.mk +++ b/sc/CppunitTest_sc_ucalc_document_themes.mk @@ -28,10 +28,13 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_ucalc_document_themes, \ comphelper \ cppu \ cppuhelper \ + docmodel \ + editeng \ sal \ salhelper \ sax \ sc \ + svl \ scqahelper \ sfx \ svxcore \ diff --git a/sc/qa/unit/ucalc_DocumentThemes.cxx b/sc/qa/unit/ucalc_DocumentThemes.cxx index 5c568b9f5ca0..fdd601e09d78 100644 --- a/sc/qa/unit/ucalc_DocumentThemes.cxx +++ b/sc/qa/unit/ucalc_DocumentThemes.cxx @@ -8,8 +8,19 @@ */ #include "helper/qahelper.hxx" -#include <docsh.hxx> + +#include <docmodel/theme/Theme.hxx> #include <svx/svdpage.hxx> +#include <editeng/brushitem.hxx> +#include <editeng/colritem.hxx> + +#include <docsh.hxx> +#include <patattr.hxx> +#include <attrib.hxx> +#include <docpool.hxx> +#include <scitems.hxx> +#include <undomanager.hxx> +#include <ThemeColorChanger.hxx> using namespace css; @@ -19,16 +30,127 @@ class DocumentThemesTest : public ScUcalcTestBase namespace { -CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testThemes) +CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testGetTheme) { m_pDoc->InitDrawLayer(); m_pDoc->InsertTab(0, "Test"); + + ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer(); + CPPUNIT_ASSERT(pDrawLayer); + const SdrPage* pPage(pDrawLayer->GetPage(0)); + CPPUNIT_ASSERT(pPage); + auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); + CPPUNIT_ASSERT(pTheme); +} + +CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme) +{ + m_pDoc->InitDrawLayer(); + m_pDoc->InsertTab(0, "Test"); + ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer(); CPPUNIT_ASSERT(pDrawLayer); const SdrPage* pPage(pDrawLayer->GetPage(0)); CPPUNIT_ASSERT(pPage); auto const& pTheme = pPage->getSdrPageProperties().GetTheme(); CPPUNIT_ASSERT(pTheme); + + Color aBackgroundThemeColor(0xc99c00); + Color aCellTextThemeColor(0x0369a3); + + auto eBackgroundThemeType = model::ThemeColorType::Accent5; + auto eCellTextThemeType = model::ThemeColorType::Accent2; + + ScPatternAttr aNewPattern(m_pDoc->GetPool()); + { + model::ComplexColor aComplexColor; + aComplexColor.setSchemeColor(eBackgroundThemeType); + Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor); + aNewPattern.GetItemSet().Put(SvxBrushItem(aColor, aComplexColor, ATTR_BACKGROUND)); + } + { + model::ComplexColor aComplexColor; + aComplexColor.setSchemeColor(eCellTextThemeType); + Color aColor = pTheme->getColorSet()->resolveColor(aComplexColor); + aNewPattern.GetItemSet().Put(SvxColorItem(aColor, aComplexColor, ATTR_FONT_COLOR)); + } + + m_pDoc->ApplyPatternAreaTab(2, 2, 4, 4, 0, aNewPattern); + + { + const SfxPoolItem* pItem = nullptr; + auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0)); + CPPUNIT_ASSERT(pPattern); + + pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + auto pBrushItem = static_cast<const SvxBrushItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor()); + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + auto pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor()); + } + + auto pColorSet = std::make_shared<model::ColorSet>("TestColorScheme"); + pColorSet->add(model::ThemeColorType::Dark1, 0x000000); + pColorSet->add(model::ThemeColorType::Light1, 0x111111); + pColorSet->add(model::ThemeColorType::Dark2, 0x222222); + pColorSet->add(model::ThemeColorType::Light2, 0x333333); + pColorSet->add(model::ThemeColorType::Accent1, 0x444444); + pColorSet->add(model::ThemeColorType::Accent2, 0x555555); + pColorSet->add(model::ThemeColorType::Accent3, 0x666666); + pColorSet->add(model::ThemeColorType::Accent4, 0x777777); + pColorSet->add(model::ThemeColorType::Accent5, 0x888888); + pColorSet->add(model::ThemeColorType::Accent6, 0x999999); + pColorSet->add(model::ThemeColorType::Hyperlink, 0xaaaaaa); + pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xbbbbbb); + + sc::ThemeColorChanger aChanger(*m_xDocShell); + aChanger.apply(pColorSet); + + { + const SfxPoolItem* pItem = nullptr; + auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0)); + CPPUNIT_ASSERT(pPattern); + + pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + auto pBrushItem = static_cast<const SvxBrushItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor()); + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + auto pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor()); + } + + // Undo / Redo + + m_pDoc->GetUndoManager()->Undo(); + + { + const SfxPoolItem* pItem = nullptr; + auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0)); + CPPUNIT_ASSERT(pPattern); + + pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + auto pBrushItem = static_cast<const SvxBrushItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(aBackgroundThemeColor, pBrushItem->GetColor()); + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + auto pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(aCellTextThemeColor, pColorItem->getColor()); + } + + m_pDoc->GetUndoManager()->Redo(); + + { + const SfxPoolItem* pItem = nullptr; + auto* pPattern = m_pDoc->GetPattern(ScAddress(3, 3, 0)); + CPPUNIT_ASSERT(pPattern); + + pPattern->GetItemSet().HasItem(ATTR_BACKGROUND, &pItem); + auto pBrushItem = static_cast<const SvxBrushItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eBackgroundThemeType), pBrushItem->GetColor()); + pPattern->GetItemSet().HasItem(ATTR_FONT_COLOR, &pItem); + auto pColorItem = static_cast<const SvxColorItem*>(pItem); + CPPUNIT_ASSERT_EQUAL(pColorSet->getColor(eCellTextThemeType), pColorItem->getColor()); + } } } // end anonymous namespace diff --git a/sc/source/ui/inc/ThemeColorChanger.hxx b/sc/source/ui/inc/ThemeColorChanger.hxx index 888cf34f11ba..f3f3b7379671 100644 --- a/sc/source/ui/inc/ThemeColorChanger.hxx +++ b/sc/source/ui/inc/ThemeColorChanger.hxx @@ -10,12 +10,13 @@ #pragma once +#include <scdllapi.h> #include <svx/theme/ThemeColorChanger.hxx> #include "docsh.hxx" namespace sc { -class ThemeColorChanger : public svx::IThemeColorChanger +class SC_DLLPUBLIC ThemeColorChanger : public svx::IThemeColorChanger { ScDocShell& m_rDocShell; |