chart2/source/controller/inc/ChartController.hxx        |    1 
 chart2/source/controller/main/ChartController.cxx       |    4 +
 chart2/source/controller/main/ChartController_Tools.cxx |   38 ++++++++++++++++
 include/svx/xgrad.hxx                                   |    2 
 svx/source/xoutdev/xattr.cxx                            |   18 +++++++
 5 files changed, 63 insertions(+)

New commits:
commit 80ba3eda8cd3c8ebbf2e49b215e2f2eb6d4b1837
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Sep 29 15:11:41 2020 +0200
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Mon Oct 5 21:55:29 2020 +0200

    lok: Add posibility to change chart fill gradient
    
    Change-Id: I942d478cd870036710390d2c03413b6fc0454038
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103619
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/chart2/source/controller/inc/ChartController.hxx 
b/chart2/source/controller/inc/ChartController.hxx
index 270f5743e0c7..50568da2e998 100644
--- a/chart2/source/controller/inc/ChartController.hxx
+++ b/chart2/source/controller/inc/ChartController.hxx
@@ -502,6 +502,7 @@ private:
     void executeDispatch_LOKSetTextSelection(int nType, int nX, int nY);
     void executeDispatch_LOKPieSegmentDragging(int nOffset);
     void executeDispatch_FillColor(sal_uInt32 nColor);
+    void executeDispatch_FillGradient(OUString sJSONGradient);
 
     void sendPopupRequest(OUString const & rCID, tools::Rectangle aRectangle);
 
diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index 5ee520362c0b..3d88f3aadd1a 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -1122,6 +1122,10 @@ void SAL_CALL ChartController::dispatch(
             this->executeDispatch_FillColor(nColor);
         }
     }
+    else if(aCommand.startsWith("FillGradient"))
+    {
+        this->executeDispatch_FillGradient(aCommand.copy(aCommand.indexOf('=') 
+ 1));
+    }
     else if(aCommand == "Paste")
         this->executeDispatch_Paste();
     else if(aCommand == "Copy" )
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx 
b/chart2/source/controller/main/ChartController_Tools.cxx
index ff1c83ae7e7f..94bafa620bce 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -73,6 +73,9 @@
 #include <svx/unoapi.hxx>
 #include <svx/unopage.hxx>
 #include <o3tl/make_unique.hxx>
+#include <svx/xgrad.hxx>
+#include <svx/xflgrit.hxx>
+#include <PropertyHelper.hxx>
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <tools/diagnose_ex.h>
@@ -957,6 +960,41 @@ void ChartController::executeDispatch_FillColor(sal_uInt32 
nColor)
     }
 }
 
+void ChartController::executeDispatch_FillGradient(OUString sJSONGradient)
+{
+    XGradient aXGradient = XGradient::fromJSON(sJSONGradient);
+    css::awt::Gradient aGradient = aXGradient.toGradientUNO();
+
+    try
+    {
+        OUString aCID( m_aSelection.getSelectedCID() );
+        const uno::Reference< frame::XModel >& xChartModel = getModel();
+
+        if( xChartModel.is() )
+        {
+            Reference< beans::XPropertySet > xPropSet(
+                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+
+            if( xPropSet.is() )
+            {
+                OUString aPrefferedName = 
OUString::number(static_cast<sal_Int32>(aXGradient.GetStartColor()))
+                                + 
OUString::number(static_cast<sal_Int32>(aXGradient.GetEndColor()))
+                                + 
OUString::number(static_cast<sal_Int32>(aXGradient.GetAngle()));
+
+                OUString aNewName = 
PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient),
+                                        
css::uno::Reference<css::lang::XMultiServiceFactory>(xChartModel, 
css::uno::UNO_QUERY_THROW),
+                                        aPrefferedName);
+
+                xPropSet->setPropertyValue("FillGradientName", 
css::uno::Any(aNewName));
+            }
+        }
+    }
+    catch( const uno::Exception & ex )
+    {
+        SAL_WARN( "chart2", "Exception caught. " << ex );
+    }
+}
+
 void ChartController::executeDispatch_LOKSetTextSelection(int nType, int nX, 
int nY)
 {
     if (m_pDrawViewWrapper)
diff --git a/include/svx/xgrad.hxx b/include/svx/xgrad.hxx
index a5f60f831896..9c19fa785435 100644
--- a/include/svx/xgrad.hxx
+++ b/include/svx/xgrad.hxx
@@ -25,6 +25,7 @@
 #include <svx/svxdllapi.h>
 #include <com/sun/star/awt/GradientStyle.hpp>
 #include <boost/property_tree/json_parser.hpp>
+#include <com/sun/star/awt/Gradient.hpp>
 
 class Gradient;
 
@@ -77,6 +78,7 @@ public:
 
     boost::property_tree::ptree dumpAsJSON() const;
     static XGradient fromJSON(const OUString& rJSON);
+    css::awt::Gradient toGradientUNO();
 };
 
 #endif
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index 3651205de848..797867949b22 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -2050,6 +2050,24 @@ XGradient XGradient::fromJSON(const OUString& rJSON)
     return lcl_buildGradientFromStringMap(aMap);
 }
 
+css::awt::Gradient XGradient::toGradientUNO()
+{
+    css::awt::Gradient aGradient;
+
+    aGradient.Style = this->GetGradientStyle();
+    aGradient.StartColor = static_cast<sal_Int32>(this->GetStartColor());
+    aGradient.EndColor = static_cast<sal_Int32>(this->GetEndColor());
+    aGradient.Angle = static_cast<short>(this->GetAngle());
+    aGradient.Border = this->GetBorder();
+    aGradient.XOffset = this->GetXOffset();
+    aGradient.YOffset = this->GetYOffset();
+    aGradient.StartIntensity = this->GetStartIntens();
+    aGradient.EndIntensity = this->GetEndIntens();
+    aGradient.StepCount = this->GetSteps();
+
+    return aGradient;
+}
+
 XGradient::XGradient() :
     eStyle( css::awt::GradientStyle_LINEAR ),
     aStartColor( COL_BLACK ),
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to