LCOV - code coverage report
Current view: top level - chart2/source/controller/main - DragMethod_PieSegment.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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 "DragMethod_PieSegment.hxx"
      21             : 
      22             : #include "Strings.hrc"
      23             : #include "ResId.hxx"
      24             : #include "macros.hxx"
      25             : #include "ObjectIdentifier.hxx"
      26             : #include <rtl/math.hxx>
      27             : #include <svx/svdpagv.hxx>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <basegfx/matrix/b2dhommatrix.hxx>
      30             : 
      31             : namespace chart
      32             : {
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using ::com::sun::star::uno::Reference;
      36             : using ::basegfx::B2DVector;
      37             : 
      38           0 : DragMethod_PieSegment::DragMethod_PieSegment( DrawViewWrapper& rDrawViewWrapper
      39             :                                              , const OUString& rObjectCID
      40             :                                              , const Reference< frame::XModel >& xChartModel )
      41             :     : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel )
      42             :     , m_aStartVector(100.0,100.0)
      43             :     , m_fInitialOffset(0.0)
      44             :     , m_fAdditionalOffset(0.0)
      45             :     , m_aDragDirection(1000.0,1000.0)
      46           0 :     , m_fDragRange( 1.0 )
      47             : {
      48           0 :     OUString aParameter( ObjectIdentifier::getDragParameterString( m_aObjectCID ) );
      49             : 
      50           0 :     sal_Int32 nOffsetPercent(0);
      51           0 :     awt::Point aMinimumPosition(0,0);
      52           0 :     awt::Point aMaximumPosition(0,0);
      53             : 
      54             :     ObjectIdentifier::parsePieSegmentDragParameterString(
      55           0 :           aParameter, nOffsetPercent, aMinimumPosition, aMaximumPosition );
      56             : 
      57           0 :     m_fInitialOffset = nOffsetPercent / 100.0;
      58           0 :     if( m_fInitialOffset < 0.0 )
      59           0 :         m_fInitialOffset = 0.0;
      60           0 :     if( m_fInitialOffset > 1.0 )
      61           0 :         m_fInitialOffset = 1.0;
      62           0 :     B2DVector aMinVector( aMinimumPosition.X, aMinimumPosition.Y );
      63           0 :     B2DVector aMaxVector( aMaximumPosition.X, aMaximumPosition.Y );
      64           0 :     m_aDragDirection = aMaxVector - aMinVector;
      65           0 :     m_fDragRange = m_aDragDirection.scalar( m_aDragDirection );
      66           0 :     if( ::rtl::math::approxEqual( m_fDragRange, 0.0 ) )
      67           0 :         m_fDragRange = 1.0;
      68           0 : }
      69           0 : DragMethod_PieSegment::~DragMethod_PieSegment()
      70             : {
      71           0 : }
      72           0 : void DragMethod_PieSegment::TakeSdrDragComment(OUString& rStr) const
      73             : {
      74           0 :     rStr = SCH_RESSTR(STR_STATUS_PIE_SEGMENT_EXPLODED);
      75           0 :     rStr = rStr.replaceFirst( "%PERCENTVALUE", OUString::number( static_cast<sal_Int32>((m_fAdditionalOffset+m_fInitialOffset)*100.0) ));
      76           0 : }
      77           0 : bool DragMethod_PieSegment::BeginSdrDrag()
      78             : {
      79           0 :     Point aStart( DragStat().GetStart() );
      80           0 :     m_aStartVector = B2DVector( aStart.X(), aStart.Y() );
      81           0 :     Show();
      82           0 :     return true;
      83             : }
      84           0 : void DragMethod_PieSegment::MoveSdrDrag(const Point& rPnt)
      85             : {
      86           0 :     if( DragStat().CheckMinMoved(rPnt) )
      87             :     {
      88             :         //calculate new offset
      89           0 :         B2DVector aShiftVector(( B2DVector( rPnt.X(), rPnt.Y() ) - m_aStartVector ));
      90           0 :         m_fAdditionalOffset = m_aDragDirection.scalar( aShiftVector )/m_fDragRange; // projection
      91             : 
      92           0 :         if( m_fAdditionalOffset < -m_fInitialOffset )
      93           0 :             m_fAdditionalOffset = -m_fInitialOffset;
      94           0 :         else if( m_fAdditionalOffset > (1.0-m_fInitialOffset) )
      95           0 :             m_fAdditionalOffset = 1.0 - m_fInitialOffset;
      96             : 
      97           0 :         B2DVector aNewPosVector = m_aStartVector + (m_aDragDirection * m_fAdditionalOffset);
      98           0 :         Point aNewPos = Point( (long)(aNewPosVector.getX()), (long)(aNewPosVector.getY()) );
      99           0 :         if( aNewPos != DragStat().GetNow() )
     100             :         {
     101           0 :             Hide();
     102           0 :             DragStat().NextMove( aNewPos );
     103           0 :             Show();
     104           0 :         }
     105             :     }
     106           0 : }
     107           0 : bool DragMethod_PieSegment::EndSdrDrag(bool /*bCopy*/)
     108             : {
     109           0 :     Hide();
     110             : 
     111             :     try
     112             :     {
     113           0 :         Reference< frame::XModel > xChartModel( this->getChartModel() );
     114           0 :         if( xChartModel.is() )
     115             :         {
     116             :             Reference< beans::XPropertySet > xPointProperties(
     117           0 :                 ObjectIdentifier::getObjectPropertySet( m_aObjectCID, xChartModel ) );
     118           0 :             if( xPointProperties.is() )
     119           0 :                 xPointProperties->setPropertyValue( "Offset", uno::makeAny( m_fAdditionalOffset+m_fInitialOffset ));
     120           0 :         }
     121             :     }
     122           0 :     catch( const uno::Exception & ex )
     123             :     {
     124             :         ASSERT_EXCEPTION( ex );
     125             :     }
     126             : 
     127           0 :     return true;
     128             : }
     129           0 : basegfx::B2DHomMatrix DragMethod_PieSegment::getCurrentTransformation()
     130             : {
     131           0 :     basegfx::B2DHomMatrix aRetval;
     132             : 
     133           0 :     aRetval.translate(DragStat().GetDX(), DragStat().GetDY());
     134             : 
     135           0 :     return aRetval;
     136             : }
     137           0 : void DragMethod_PieSegment::createSdrDragEntries()
     138             : {
     139           0 :     SdrObject* pObj = m_rDrawViewWrapper.getSelectedObject();
     140           0 :     SdrPageView* pPV = m_rDrawViewWrapper.GetPageView();
     141             : 
     142           0 :     if( pObj && pPV )
     143             :     {
     144           0 :         const basegfx::B2DPolyPolygon aNewPolyPolygon(pObj->TakeXorPoly());
     145           0 :         addSdrDragEntry(new SdrDragEntryPolyPolygon(aNewPolyPolygon));
     146             :     }
     147           0 : }
     148             : } //namespace chart
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10