diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-08-12 04:03:57 +0900 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-08-28 12:43:11 +0200 |
commit | c0ba7ba97ce440eff77526e48e3dfbafacc1cdad (patch) | |
tree | def0753d418bed7f839540ed0d1e36d391734d3e /sd | |
parent | 6c8df0fe62ffc62fbe0c228e0928179a0fd2a4e4 (diff) |
sd: add ThemeDialog to Impress/Draw, refactor ThemeColorChanger
Add "Theme" menu action, which starts the common ThemeDialog.
Add Impress/Draw specific ThemeColorChanger and remove the one in
svx, so that only the interface and common function remain.
Rename the svx ThemeColorChanger files to THemeColorChangerCommon.
Change-Id: Ibf07a443cadf0452747ab6685f65df37b145c984
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155682
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit ad873064b0135e4e00389cd38c7de688286c1fa1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156159
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/Library_sd.mk | 1 | ||||
-rw-r--r-- | sd/inc/theme/ThemeColorChanger.hxx | 33 | ||||
-rw-r--r-- | sd/qa/unit/ThemeTest.cxx | 22 | ||||
-rw-r--r-- | sd/sdi/_drvwsh.sdi | 6 | ||||
-rw-r--r-- | sd/source/core/ThemeColorChanger.cxx | 75 | ||||
-rw-r--r-- | sd/source/ui/view/drviews2.cxx | 35 | ||||
-rw-r--r-- | sd/uiconfig/sdraw/menubar/menubar.xml | 1 | ||||
-rw-r--r-- | sd/uiconfig/simpress/menubar/menubar.xml | 1 |
8 files changed, 167 insertions, 7 deletions
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index 3c60a60b3a3d..24e3c985a4ee 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\ sd/source/core/EffectMigration \ sd/source/core/PageListWatcher \ sd/source/core/TransitionPreset \ + sd/source/core/ThemeColorChanger \ sd/source/core/anminfo \ sd/source/core/annotations/Annotation \ sd/source/core/annotations/AnnotationEnumeration \ diff --git a/sd/inc/theme/ThemeColorChanger.hxx b/sd/inc/theme/ThemeColorChanger.hxx new file mode 100644 index 000000000000..8c8179460dd8 --- /dev/null +++ b/sd/inc/theme/ThemeColorChanger.hxx @@ -0,0 +1,33 @@ +/* -*- 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/. + */ + +#pragma once + +#include <sddllapi.h> +#include <svx/theme/IThemeColorChanger.hxx> +#include <docmodel/theme/ColorSet.hxx> +#include <svx/svdpage.hxx> + +namespace sd +{ +class SD_DLLPUBLIC ThemeColorChanger : public svx::IThemeColorChanger +{ +private: + SdrPage* mpMasterPage; + +public: + ThemeColorChanger(SdrPage* pMasterPage); + virtual ~ThemeColorChanger() override; + + void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override; +}; + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/ThemeTest.cxx b/sd/qa/unit/ThemeTest.cxx index c085be7721bc..71313b48a7e6 100644 --- a/sd/qa/unit/ThemeTest.cxx +++ b/sd/qa/unit/ThemeTest.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/drawing/XMasterPageTarget.hpp> #include <com/sun/star/text/XTextRange.hpp> #include <docmodel/uno/UnoComplexColor.hxx> +#include <docmodel/theme/Theme.hxx> #include <svx/unoapi.hxx> @@ -23,6 +24,7 @@ #include <unomodel.hxx> #include <sdpage.hxx> #include <ViewShell.hxx> +#include <theme/ThemeColorChanger.hxx> using namespace css; @@ -38,7 +40,7 @@ public: namespace { /// Get the character color of the first text portion in xShape. -sal_Int32 GetShapeTextColor(const uno::Reference<text::XTextRange>& xShape) +Color GetShapeTextColor(const uno::Reference<text::XTextRange>& xShape) { uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), uno::UNO_QUERY); uno::Reference<container::XEnumerationAccess> xPara(xText->createEnumeration()->nextElement(), @@ -47,15 +49,15 @@ sal_Int32 GetShapeTextColor(const uno::Reference<text::XTextRange>& xShape) uno::UNO_QUERY); sal_Int32 nColor{}; xPortion->getPropertyValue("CharColor") >>= nColor; - return nColor; + return Color(nColor); } /// Get the solid fill color of xShape. -sal_Int32 GetShapeFillColor(const uno::Reference<beans::XPropertySet>& xShape) +Color GetShapeFillColor(const uno::Reference<beans::XPropertySet>& xShape) { sal_Int32 nColor{}; xShape->getPropertyValue("FillColor") >>= nColor; - return nColor; + return Color(nColor); } } // end anonymous namespace @@ -86,7 +88,7 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange) // Shape fill: uno::Reference<beans::XPropertySet> xShape4(xDrawPageShapes->getByIndex(4), uno::UNO_QUERY); // Blue. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472c4), GetShapeFillColor(xShape4)); + CPPUNIT_ASSERT_EQUAL(Color(0x4472c4), GetShapeFillColor(xShape4)); // The theme color of this filled shape is set by the PPTX import: { @@ -99,7 +101,7 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange) uno::Reference<beans::XPropertySet> xShape5(xDrawPageShapes->getByIndex(5), uno::UNO_QUERY); // Blue, lighter. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xb4c7e7), GetShapeFillColor(xShape5)); + CPPUNIT_ASSERT_EQUAL(Color(0xb4c7e7), GetShapeFillColor(xShape5)); // The theme index, and effects (lum mod, lum off) are set by the PPTX import: { uno::Reference<util::XComplexColor> xComplexColor; @@ -124,6 +126,14 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange) uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); xMasterPage->setPropertyValue("Theme", aTheme); + css::uno::Reference<css::drawing::XDrawPage> xDrawPageMaster(xMasterPage, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDrawPageMaster.is()); + auto* pMasterPage = GetSdrPageFromXDrawPage(xDrawPageMaster); + auto pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + + sd::ThemeColorChanger aChanger(pMasterPage); + aChanger.apply(pTheme->getColorSet()); + // Then make sure the shape text color is now green: CPPUNIT_ASSERT_EQUAL(Color(0x90c226), GetShapeTextColor(xShape)); // Green, lighter: diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi index b9c52054b897..f28ccfb7e7bd 100644 --- a/sd/sdi/_drvwsh.sdi +++ b/sd/sdi/_drvwsh.sdi @@ -2942,5 +2942,9 @@ interface DrawView ExecMethod = FuTemporary; StateMethod = GetAttrState; ] - + SID_THEME_DIALOG + [ + ExecMethod = FuTemporary; + StateMethod = GetAttrState; + ] } diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx new file mode 100644 index 000000000000..7ca2b6478232 --- /dev/null +++ b/sd/source/core/ThemeColorChanger.cxx @@ -0,0 +1,75 @@ +/* -*- 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 <theme/ThemeColorChanger.hxx> +#include <svx/theme/ThemeColorChangerCommon.hxx> +#include <svx/svdmodel.hxx> +#include <svx/svditer.hxx> +#include <docmodel/theme/Theme.hxx> + +using namespace css; + +namespace sd +{ +ThemeColorChanger::ThemeColorChanger(SdrPage* pMasterPage) + : mpMasterPage(pMasterPage) +{ +} + +ThemeColorChanger::~ThemeColorChanger() = default; + +namespace +{ +void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const& pColorSet) +{ + auto pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + if (!pTheme) + { + pTheme = std::make_shared<model::Theme>("Office"); + pMasterPage->getSdrPageProperties().SetTheme(pTheme); + } + pTheme->setColorSet(pColorSet); +} + +} // end anonymous ns + +void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) +{ + SdrModel& rModel = mpMasterPage->getSdrModelFromSdrPage(); + for (sal_uInt16 nPage = 0; nPage < rModel.GetPageCount(); ++nPage) + { + SdrPage* pCurrentPage = rModel.GetPage(nPage); + if (!pCurrentPage->TRG_HasMasterPage() + || &pCurrentPage->TRG_GetMasterPage() != mpMasterPage) + continue; + + for (size_t nObject = 0; nObject < pCurrentPage->GetObjCount(); ++nObject) + { + SdrObject* pObject = pCurrentPage->GetObj(nObject); + svx::theme::updateSdrObject(*pColorSet, pObject); + + // update child objects + SdrObjList* pList = pObject->GetSubList(); + if (pList) + { + SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); + while (aIter.IsMore()) + { + svx::theme::updateSdrObject(*pColorSet, aIter.Next()); + } + } + } + } + + changeTheTheme(mpMasterPage, pColorSet); +} + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 9ff430918842..95efac1c5358 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -186,6 +186,12 @@ #include <controller/SlsPageSelector.hxx> #include <tools/GraphicSizeCheck.hxx> +#include <theme/ThemeColorChanger.hxx> +#include <svx/dialog/ThemeDialog.hxx> +#include <svx/theme/ThemeColorPaletteManager.hxx> +#include <sfx2/lokhelper.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + #include <ViewShellBase.hxx> #include <memory> @@ -3578,6 +3584,35 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) } break; + case SID_THEME_DIALOG: + { + SdrPage* pMasterPage = &GetActualPage()->TRG_GetMasterPage(); + auto pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + auto pDialog = std::make_shared<svx::ThemeDialog>(GetFrameWeld(), pTheme.get()); + weld::DialogController::runAsync(pDialog, [pDialog, pMasterPage](sal_uInt32 nResult) + { + if (RET_OK != nResult) + return; + + auto pColorSet = pDialog->getCurrentColorSet(); + if (pColorSet) + { + sd::ThemeColorChanger aChanger(pMasterPage); + aChanger.apply(pColorSet); + + if (comphelper::LibreOfficeKit::isActive()) + { + svx::ThemeColorPaletteManager aManager(pColorSet); + SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, aManager.generateJSON()); + } + } + }); + + Cancel(); + rReq.Ignore(); + } + break; + case SID_ADDITIONS_DIALOG: { OUString sAdditionsTag = ""; diff --git a/sd/uiconfig/sdraw/menubar/menubar.xml b/sd/uiconfig/sdraw/menubar/menubar.xml index 640a4446e322..b1eddcb79b5c 100644 --- a/sd/uiconfig/sdraw/menubar/menubar.xml +++ b/sd/uiconfig/sdraw/menubar/menubar.xml @@ -363,6 +363,7 @@ <menu:menuitem menu:id=".uno:FontDialog"/> <menu:menuitem menu:id=".uno:ParagraphDialog"/> <menu:menuitem menu:id=".uno:OutlineBullet"/> + <menu:menuitem menu:id=".uno:ThemeDialog"/> <menu:menuseparator/> <menu:menuitem menu:id=".uno:ModifyLayer"/> <menu:menu menu:id=".uno:TableMenu"> diff --git a/sd/uiconfig/simpress/menubar/menubar.xml b/sd/uiconfig/simpress/menubar/menubar.xml index 23f80c7276a5..010e764ce3d1 100644 --- a/sd/uiconfig/simpress/menubar/menubar.xml +++ b/sd/uiconfig/simpress/menubar/menubar.xml @@ -395,6 +395,7 @@ <menu:menuitem menu:id=".uno:FontDialog"/> <menu:menuitem menu:id=".uno:ParagraphDialog"/> <menu:menuitem menu:id=".uno:OutlineBullet"/> + <menu:menuitem menu:id=".uno:ThemeDialog"/> <menu:menuseparator/> <menu:menu menu:id=".uno:TableMenu"> <menu:menupopup> |