LCOV - code coverage report
Current view: top level - chart2/source/controller/main - PositionAndSizeHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 62 40.3 %
Date: 2015-06-13 12:38:46 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "PositionAndSizeHelper.hxx"
      21             : #include "macros.hxx"
      22             : #include "ChartModelHelper.hxx"
      23             : #include "ControllerLockGuard.hxx"
      24             : #include <com/sun/star/chart2/LegendPosition.hpp>
      25             : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      26             : #include <com/sun/star/chart2/RelativePosition.hpp>
      27             : #include <com/sun/star/chart2/RelativeSize.hpp>
      28             : #include "chartview/ExplicitValueProvider.hxx"
      29             : 
      30             : #include <tools/gen.hxx>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : 
      33             : namespace chart
      34             : {
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::chart2;
      37             : 
      38           2 : bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
      39             :                 , const uno::Reference< beans::XPropertySet >& xObjectProp
      40             :                 , const awt::Rectangle& rNewPositionAndSize
      41             :                 , const awt::Rectangle& rPageRectangle
      42             :                 )
      43             : {
      44           2 :     if(!xObjectProp.is())
      45           0 :         return false;
      46           2 :     Rectangle aObjectRect( Point(rNewPositionAndSize.X,rNewPositionAndSize.Y), Size(rNewPositionAndSize.Width,rNewPositionAndSize.Height) );
      47           2 :     Rectangle aPageRect( Point(rPageRectangle.X,rPageRectangle.Y), Size(rPageRectangle.Width,rPageRectangle.Height) );
      48             : 
      49           2 :     if( OBJECTTYPE_TITLE==eObjectType )
      50             :     {
      51             :         //@todo decide whether x is primary or secondary
      52           0 :         chart2::RelativePosition aRelativePosition;
      53           0 :         aRelativePosition.Anchor = drawing::Alignment_CENTER;
      54             :         //the anchor point at the title object is top/middle
      55           0 :         Point aPos = aObjectRect.TopLeft();
      56           0 :         aRelativePosition.Primary = (double(aPos.X())+double(aObjectRect.getWidth())/2.0)/double(aPageRect.getWidth());
      57           0 :         aRelativePosition.Secondary = (double(aPos.Y())+double(aObjectRect.getHeight())/2.0)/double(aPageRect.getHeight());
      58           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      59             :     }
      60           2 :     else if( OBJECTTYPE_DATA_CURVE_EQUATION==eObjectType )
      61             :     {
      62             :         //@todo decide whether x is primary or secondary
      63           0 :         chart2::RelativePosition aRelativePosition;
      64           0 :         aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
      65             :         //the anchor point at the title object is top/middle
      66           0 :         Point aPos = aObjectRect.TopLeft();
      67           0 :         aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
      68           0 :         aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
      69           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      70             :     }
      71           2 :     else if(OBJECTTYPE_LEGEND==eObjectType)
      72             :     {
      73           2 :         xObjectProp->setPropertyValue( "AnchorPosition", uno::makeAny(LegendPosition(LegendPosition_CUSTOM)));
      74           2 :         xObjectProp->setPropertyValue( "Expansion", uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM));
      75           2 :         chart2::RelativePosition aRelativePosition;
      76           2 :         chart2::RelativeSize aRelativeSize;
      77           2 :         Point aAnchor = aObjectRect.TopLeft();
      78             : 
      79             :         aRelativePosition.Primary =
      80           4 :             static_cast< double >( aAnchor.X()) /
      81           4 :             static_cast< double >( aPageRect.getWidth() );
      82             :         aRelativePosition.Secondary =
      83           4 :             static_cast< double >( aAnchor.Y()) /
      84           4 :             static_cast< double >( aPageRect.getHeight());
      85             : 
      86           2 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
      87             : 
      88             :         aRelativeSize.Primary =
      89           4 :             static_cast< double >( aObjectRect.getWidth()) /
      90           4 :             static_cast< double >( aPageRect.getWidth() );
      91           2 :         if (aRelativeSize.Primary > 1.0)
      92           0 :             aRelativeSize.Primary = 1.0;
      93             :         aRelativeSize.Secondary =
      94           4 :             static_cast< double >( aObjectRect.getHeight()) /
      95           4 :             static_cast< double >( aPageRect.getHeight());
      96           2 :         if (aRelativeSize.Secondary > 1.0)
      97           0 :             aRelativeSize.Secondary = 1.0;
      98             : 
      99           2 :         xObjectProp->setPropertyValue( "RelativeSize", uno::makeAny(aRelativeSize) );
     100             :     }
     101           0 :     else if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
     102             :     {
     103             :         //@todo decide whether x is primary or secondary
     104             : 
     105             :         //set position:
     106           0 :         chart2::RelativePosition aRelativePosition;
     107           0 :         aRelativePosition.Anchor = drawing::Alignment_CENTER;
     108             : 
     109           0 :         Point aPos = aObjectRect.Center();
     110           0 :         aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
     111           0 :         aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
     112           0 :         xObjectProp->setPropertyValue( "RelativePosition", uno::makeAny(aRelativePosition) );
     113             : 
     114             :         //set size:
     115           0 :         RelativeSize aRelativeSize;
     116             :         //the anchor points for the diagram are in the middle of the diagram
     117             :         //and in the middle of the page
     118           0 :         aRelativeSize.Primary = double(aObjectRect.getWidth())/double(aPageRect.getWidth());
     119           0 :         aRelativeSize.Secondary = double(aObjectRect.getHeight())/double(aPageRect.getHeight());
     120           0 :         xObjectProp->setPropertyValue( "RelativeSize", uno::makeAny(aRelativeSize) );
     121             :     }
     122             :     else
     123           0 :         return false;
     124           2 :     return true;
     125             : }
     126             : 
     127           0 : bool PositionAndSizeHelper::moveObject( const OUString& rObjectCID
     128             :                 , const uno::Reference< frame::XModel >& xChartModel
     129             :                 , const awt::Rectangle& rNewPositionAndSize
     130             :                 , const awt::Rectangle& rPageRectangle
     131             :                 )
     132             : {
     133           0 :     ControllerLockGuardUNO aLockedControllers( xChartModel );
     134             : 
     135           0 :     awt::Rectangle aNewPositionAndSize( rNewPositionAndSize );
     136             : 
     137           0 :     uno::Reference< beans::XPropertySet > xObjectProp = ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartModel );
     138           0 :     ObjectType eObjectType( ObjectIdentifier::getObjectType( rObjectCID ) );
     139           0 :     if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
     140             :     {
     141           0 :         xObjectProp = uno::Reference< beans::XPropertySet >( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY );
     142           0 :         if(!xObjectProp.is())
     143           0 :             return false;
     144             :     }
     145           0 :     return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rPageRectangle );
     146             : }
     147             : 
     148             : } //namespace chart
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11