summaryrefslogtreecommitdiff
path: root/docmodel
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-02-11 11:24:05 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-03-01 12:57:21 +0000
commit855f7c08d1feab7669670bfbc4ed2b3b3225db16 (patch)
tree0d8f8cd014bb74cfd88aea2283e1d30ad7b2b547 /docmodel
parent79434c321597790de6cb8db18f4b9fb6dc8c60bb (diff)
send theme info when changing color (in the picker) via UNO command
Change-Id: I288f8fb3375e152b5ee746fab2c05d08150d6c99 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146817 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'docmodel')
-rw-r--r--docmodel/Library_docmodel.mk4
-rw-r--r--docmodel/source/theme/ThemeColorJSON.cxx103
2 files changed, 106 insertions, 1 deletions
diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk
index 8db7d0fa6f93..8a07e6532dad 100644
--- a/docmodel/Library_docmodel.mk
+++ b/docmodel/Library_docmodel.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_Library_add_exception_objects,docmodel,\
docmodel/source/uno/UnoTheme \
docmodel/source/theme/ColorSet \
docmodel/source/theme/Theme \
+ docmodel/source/theme/ThemeColorJSON \
))
$(eval $(call gb_Library_set_include,docmodel,\
@@ -22,7 +23,8 @@ $(eval $(call gb_Library_set_include,docmodel,\
))
$(eval $(call gb_Library_use_externals,docmodel,\
- libxml2 \
+ libxml2 \
+ boost_headers \
))
$(eval $(call gb_Library_add_defs,docmodel,\
diff --git a/docmodel/source/theme/ThemeColorJSON.cxx b/docmodel/source/theme/ThemeColorJSON.cxx
new file mode 100644
index 000000000000..6b2293ca1f64
--- /dev/null
+++ b/docmodel/source/theme/ThemeColorJSON.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 <docmodel/theme/ThemeColorJSON.hxx>
+#include <sstream>
+#include <utility>
+#include <sal/log.hxx>
+#include <boost/property_tree/json_parser.hpp>
+
+namespace model::theme
+{
+bool convertFromJSON(OString const& rJsonString, model::ThemeColor& rThemeColor)
+{
+ model::ThemeColor aThemeColor;
+ std::stringstream aStream(rJsonString.getStr());
+ boost::property_tree::ptree aRootTree;
+ try
+ {
+ boost::property_tree::read_json(aStream, aRootTree);
+ }
+ catch (const boost::property_tree::json_parser_error& /*exception*/)
+ {
+ return false;
+ }
+
+ sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1);
+ aThemeColor.setType(model::convertToThemeColorType(nThemeType));
+ boost::property_tree::ptree aTransformTree = aRootTree.get_child("Transformations");
+ for (const auto& rEachTransformationNode :
+ boost::make_iterator_range(aTransformTree.equal_range("")))
+ {
+ auto const& rTransformationTree = rEachTransformationNode.second;
+ std::string sType = rTransformationTree.get<std::string>("Type", "");
+ sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0);
+
+ auto eType = model::TransformationType::Undefined;
+ if (sType == "LumOff")
+ eType = model::TransformationType::LumOff;
+ else if (sType == "LumMod")
+ eType = model::TransformationType::LumMod;
+ else if (sType == "Tint")
+ eType = model::TransformationType::Tint;
+ else if (sType == "Shade")
+ eType = model::TransformationType::Shade;
+
+ if (eType != model::TransformationType::Undefined)
+ aThemeColor.addTransformation({ eType, nValue });
+ }
+ rThemeColor = aThemeColor;
+ return true;
+}
+
+OString convertToJSON(model::ThemeColor const& rThemeColor)
+{
+ boost::property_tree::ptree aTree;
+ aTree.put("ThemeIndex", sal_Int16(rThemeColor.getType()));
+
+ boost::property_tree::ptree aTransformationsList;
+ for (auto const& rTransformation : rThemeColor.getTransformations())
+ {
+ std::string aType;
+ switch (rTransformation.meType)
+ {
+ case model::TransformationType::LumMod:
+ aType = "LumMod";
+ break;
+ case model::TransformationType::LumOff:
+ aType = "LumOff";
+ break;
+ case model::TransformationType::Tint:
+ aType = "Tint";
+ break;
+ case model::TransformationType::Shade:
+ aType = "Shade";
+ break;
+ default:
+ break;
+ }
+ if (!aType.empty())
+ {
+ boost::property_tree::ptree aChild;
+ aChild.put("Type", aType);
+ aChild.put("Value", rTransformation.mnValue);
+ aTransformationsList.push_back(std::make_pair("", aChild));
+ }
+ }
+ aTree.add_child("Transformations", aTransformationsList);
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+
+ return OString(aStream.str().c_str());
+}
+
+} // end model::theme
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */