diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-02-07 12:18:31 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-02-12 20:08:52 +0000 |
commit | 30efd7cfdaa7d3faa85a775e2e4af17e74fccb78 (patch) | |
tree | d38e8efeab078d35e612e226e678c23c19583c03 | |
parent | 934e2d83e2628131a3b6ca9fdbc99848ccda655f (diff) |
chart2: simple button (view) to add to a chart
Change-Id: I2001efe1e7eb9e92edb8f5e78535cea0e78935ad
Reviewed-on: https://gerrit.libreoffice.org/34003
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | chart2/Library_chartcore.mk | 1 | ||||
-rw-r--r-- | chart2/source/view/main/VButton.cxx | 86 | ||||
-rw-r--r-- | chart2/source/view/main/VButton.hxx | 54 |
3 files changed, 141 insertions, 0 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk index 5653331764c4..2acc34ff8469 100644 --- a/chart2/Library_chartcore.mk +++ b/chart2/Library_chartcore.mk @@ -118,6 +118,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\ chart2/source/view/main/VLineProperties \ chart2/source/view/main/VPolarTransformation \ chart2/source/view/main/VTitle \ + chart2/source/view/main/VButton \ )) ifeq ($(ENABLE_HEADLESS),) $(eval $(call gb_Library_add_exception_objects,chartcore,\ diff --git a/chart2/source/view/main/VButton.cxx b/chart2/source/view/main/VButton.cxx new file mode 100644 index 000000000000..b89fdd158ff1 --- /dev/null +++ b/chart2/source/view/main/VButton.cxx @@ -0,0 +1,86 @@ +/* -*- 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 "VButton.hxx" + +#include "AbstractShapeFactory.hxx" +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/style/ParagraphAdjust.hpp> +#include <com/sun/star/drawing/TextVerticalAdjust.hpp> +#include <com/sun/star/drawing/TextHorizontalAdjust.hpp> + +#include <memory> + +namespace chart +{ + +using namespace css; + +VButton::VButton() + : m_xShapeFactory(nullptr) + , m_xTarget(nullptr) + , m_xShape(nullptr) + , m_rPosition(0, 0) +{ +} + +void VButton::init(const uno::Reference<drawing::XShapes>& xTargetPage, + const uno::Reference<lang::XMultiServiceFactory>& xFactory) +{ + m_xTarget = xTargetPage; + m_xShapeFactory = xFactory; +} + +void VButton::createShapes(const awt::Point& rPosition, + const awt::Size& rReferenceSize, + const uno::Reference<beans::XPropertySet>& xTextProp) +{ + AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory); + + std::unique_ptr<tNameSequence> pPropNames(new tNameSequence); + std::unique_ptr<tAnySequence> pPropValues(new tAnySequence); + + PropertyMapper::getTextLabelMultiPropertyLists(xTextProp, *pPropNames, *pPropValues); + + tPropertyNameValueMap aTextValueMap; + aTextValueMap["CharHeight"] = uno::makeAny<float>(10.0f); + aTextValueMap["FillColor"] = uno::makeAny<sal_Int32>(0xe6e6e6); + aTextValueMap["FillStyle"] = uno::makeAny(drawing::FillStyle_SOLID); + aTextValueMap["LineColor"] = uno::makeAny<sal_Int32>(0xcccccc); + aTextValueMap["LineStyle"] = uno::makeAny(drawing::LineStyle_SOLID); + aTextValueMap["ParaAdjust"] = uno::makeAny(style::ParagraphAdjust_CENTER); + aTextValueMap["TextHorizontalAdjust"] = uno::makeAny(drawing::TextHorizontalAdjust_CENTER); + aTextValueMap["TextVerticalAdjust"] = uno::makeAny(drawing::TextVerticalAdjust_CENTER); + + aTextValueMap["Name"] = uno::makeAny(OUString(m_sCID)); //CID OUString + + PropertyMapper::getMultiPropertyListsFromValueMap(*pPropNames, *pPropValues, aTextValueMap); + + uno::Reference<drawing::XShape> xEntry = pShapeFactory->createText( + m_xTarget, m_sLabel, *pPropNames, *pPropValues, uno::Any()); + + if (xEntry.is()) + { + m_xShape = xEntry; + m_xShape->setPosition(rPosition); + m_xShape->setSize(rReferenceSize); + } +} + +void VButton::setWidth(sal_Int32 nWidth) +{ + awt::Size aSize = m_xShape->getSize(); + aSize.Width = nWidth; + m_xShape->setSize(aSize); +} + +} //namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/main/VButton.hxx b/chart2/source/view/main/VButton.hxx new file mode 100644 index 000000000000..4a024e14347a --- /dev/null +++ b/chart2/source/view/main/VButton.hxx @@ -0,0 +1,54 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_CHART2_SOURCE_VIEW_MAIN_VBUTTON_HXX +#define INCLUDED_CHART2_SOURCE_VIEW_MAIN_VBUTTON_HXX + +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +namespace chart +{ + +class VButton final +{ +private: + css::uno::Reference<css::lang::XMultiServiceFactory> m_xShapeFactory; + css::uno::Reference<css::drawing::XShapes> m_xTarget; + css::uno::Reference<css::drawing::XShape> m_xShape; + css::awt::Point m_rPosition; + OUString m_sLabel; + OUString m_sCID; + +public: + VButton(); + + void init(const css::uno::Reference<css::drawing::XShapes>& xTargetPage, + const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory); + + void createShapes(const css::awt::Point& rPosition, + const css::awt::Size& rReferenceSize, + const css::uno::Reference<css::beans::XPropertySet>& xTextProp); + + void setWidth(sal_Int32 nWidth); + void setLabel(OUString const & sLabel) + { + m_sLabel = sLabel; + } + void setCID(OUString const & sCID) + { + m_sCID = sCID; + } +}; + +} //namespace chart +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |