frameobj.cpp
author insilmaril
Sat, 31 Mar 2007 09:28:27 +0000
changeset 440 c6a8651e6bbc
parent 425 7014be3ac7d0
child 442 dfbc371b7280
permissions -rw-r--r--
1.8.70 Fixes in property window
     1 #include "frameobj.h"
     2 
     3 #include <qcolor.h>
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // FrameObj
     7 /////////////////////////////////////////////////////////////////
     8 FrameObj::FrameObj() : MapObj()
     9 {
    10 //    cout << "Const FrameObj ()\n";
    11     init ();
    12 }
    13 
    14 FrameObj::FrameObj(QGraphicsScene *s) :MapObj(s)
    15 {
    16 //    cout << "Const FrameObj\n";
    17     init ();
    18 }
    19 
    20 FrameObj::~FrameObj()
    21 {
    22 	clear();
    23 }
    24 
    25 void FrameObj::init()
    26 {
    27     type=NoFrame;
    28     border=0;
    29 }
    30 
    31 void FrameObj::clear()
    32 {
    33     switch (type)
    34     {
    35 		case NoFrame:
    36 			break;
    37 		case Rectangle:
    38 			delete rectFrame;
    39 			break;
    40 		case Ellipse:
    41 			delete ellipseFrame;
    42 			break;
    43     }
    44 	type=NoFrame;
    45 	border=0;
    46 }
    47 
    48 void FrameObj::move(double x, double y)
    49 {
    50     switch (type)
    51     {
    52 		case NoFrame:
    53 			break;
    54 		case Rectangle:
    55 			rectFrame->setPos (x,y);
    56 			break;
    57 		case Ellipse:
    58 			ellipseFrame->setPos (x,y);
    59 			break;
    60     }
    61 }
    62 
    63 void FrameObj::moveBy(double x, double y)
    64 {
    65 	MapObj::moveBy (x,y);
    66 }
    67 
    68 void FrameObj::positionBBox()
    69 {
    70 }
    71 
    72 void FrameObj::calcBBoxSize()
    73 {
    74 }
    75 
    76 void FrameObj::setRect(const QRectF &r)
    77 {
    78 	bbox=r;
    79     switch (type)
    80     {
    81 		case NoFrame:
    82 			break;
    83 		case Rectangle:
    84 	//		rectFrame->prepareGeometryChange();
    85 			rectFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    86 			break;
    87 		case Ellipse:
    88 	//		ellipseFrame->prepareGeometryChange();
    89 			ellipseFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    90 			break;
    91     }
    92 }
    93 
    94 int FrameObj::getBorder()
    95 {
    96 	return border;
    97 }
    98 
    99 FrameType FrameObj::getFrameType()
   100 {
   101 	return type;
   102 }
   103 
   104 QString FrameObj::getFrameTypeName()
   105 {
   106     switch (type)
   107     {
   108 		case Rectangle:
   109 			return "Rectangle";
   110 			break;
   111 		case Ellipse:
   112 			return "Ellipse";
   113 			break;
   114 		default:
   115 			return "NoFrame";
   116     }
   117 }
   118 
   119 void FrameObj::setFrameType(const FrameType &t)
   120 {
   121 	if (t!=type)
   122 	{
   123 		clear();
   124 		type=t;
   125 		switch (type)
   126 		{
   127 			case NoFrame:
   128 				border=0;
   129 				break;
   130 			case Rectangle:
   131 				border=10;
   132 				rectFrame = scene->addRect(QRectF(0,0,0,0), QPen(QColor("black") ), QColor("white"));
   133 				rectFrame->setZValue(Z_FRAME);
   134 				break;
   135 			case Ellipse:
   136 				border=10;
   137 				ellipseFrame = scene->addEllipse(QRectF(0,0,0,0), QPen(QColor("black") ), QColor("white"));
   138 				ellipseFrame->setZValue(Z_FRAME);
   139 				break;
   140 		}
   141 		setVisibility (visible);
   142 	}
   143 }
   144 
   145 void FrameObj::setFrameType(const QString &t)
   146 {
   147 	if (t=="Rectangle")
   148 		FrameObj::setFrameType (Rectangle);
   149 	else if (t=="Ellipse")	
   150 		FrameObj::setFrameType (Ellipse);
   151 	else	
   152 		FrameObj::setFrameType (NoFrame);
   153 }
   154 
   155 void FrameObj::setVisibility (bool v)
   156 {
   157     MapObj::setVisibility(v);
   158 	switch (type)
   159 	{
   160 		case NoFrame:
   161 			break;
   162 		case Rectangle:
   163 			if (visible)
   164 				rectFrame->show();
   165 			else    
   166 				rectFrame->hide();
   167 			break;
   168 		case Ellipse:
   169 			if (visible)
   170 				ellipseFrame->show();
   171 			else    
   172 				ellipseFrame->hide();
   173 			break;
   174 	}
   175 }
   176 
   177 QString FrameObj::saveToDir ()
   178 {
   179 	QString	frameTypeAttr=attribut ("frameType",getFrameTypeName());
   180 	return singleElement ("frame",frameTypeAttr);
   181 }
   182