/***************************************************************************
                          area.cpp  -  description
                             -------------------
    begin                : Tue Jul 31 2001
    copyright            : (C) 2001 by Marc Bartsch
    email                : marc.bartsch@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "area.h"

Area::Area()
{
	ID = ID_area;
  identificator = "Area";

	int temp[] = { ID_circle, 1, -1, ID_fixedCircle, 1, -1 };
	convertParams( temp, sizeof( temp ) / sizeof( temp[0] ) );
	pic = QPixmap( UserIcon( "areaCircle" ) );
	picRect  = QRect( 2, 2, 20, 20 );
}

Area::~Area()
{
}

void Area::move()
{
	if ( textRect.height() == 0 )
	{
		textRect = QRect( 0, 0, 0, 22 );
  	textRect.moveCenter( coords.getQPoint() );
	}

	Coordinates coord1, coord2, coord3, coord4;

	if ( parents.at( 0 )->identify() == "Circle" )
	{
		coord1 = parents.at( 0 )->parents.at( 0 )->getCoordinates();
		coord2 = parents.at( 0 )->parents.at( 1 )->getCoordinates();
		coord3 = Coordinates( textRect.center() ) - coord1;
		coord3.setLength( coord1.getDistance( coord2 ) );
		coord3 += coord1;

		anchorPoint = coord3.getQPoint();

		MetricsCenter::mapCanvasToGrid( coord1 );
		MetricsCenter::mapCanvasToGrid( coord2 );

		double myValue = pow( coord1.getDistance( coord2 ), 2 ) * PI;

	  value = QString().setNum( myValue,'f',4 );
	}

	if ( parents.at( 0 )->identify() == "FixedCircle" )
	{
		coord1 = parents.at( 0 )->parents.at( 0 )->getCoordinates();

		float myValue = parents.at( 0 )->getRealRadius();

	  value = QString().setNum( pow( myValue,2 ) * PI,'f',4 );

		coord3 = Coordinates( textRect.center() ) - coord1;
		coord3.setLength( myValue );
		coord3 += coord1;
		anchorPoint = coord3.getQPoint();
	}

	coords = Coordinates( textRect.center() );
}
