frameobj.cpp
author insilmaril
Tue, 23 Jan 2007 11:50:53 +0000
changeset 421 5522d1da7e37
parent 408 c2a05fa925a1
child 425 7014be3ac7d0
permissions -rw-r--r--
1.8.65 Various fixes
     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->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    85 			break;
    86 		case Ellipse:
    87 			ellipseFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    88 			break;
    89     }
    90 }
    91 
    92 int FrameObj::getBorder()
    93 {
    94 	return border;
    95 }
    96 
    97 FrameType FrameObj::getFrameType()
    98 {
    99 	return type;
   100 }
   101 
   102 QString FrameObj::getFrameTypeName()
   103 {
   104     switch (type)
   105     {
   106 		case Rectangle:
   107 			return "Rectangle";
   108 			break;
   109 		case Ellipse:
   110 			return "Ellipse";
   111 			break;
   112 		default:
   113 			return "NoFrame";
   114     }
   115 }
   116 
   117 void FrameObj::setFrameType(const FrameType &t)
   118 {
   119 	if (t!=type)
   120 	{
   121 		clear();
   122 		type=t;
   123 		switch (type)
   124 		{
   125 			case NoFrame:
   126 				border=0;
   127 				break;
   128 			case Rectangle:
   129 				border=10;
   130 				rectFrame = scene->addRect(QRectF(0,0,0,0), QPen(QColor("black") ), QColor("white"));
   131 				rectFrame->setZValue(Z_FRAME);
   132 				break;
   133 			case Ellipse:
   134 				border=10;
   135 				ellipseFrame = scene->addEllipse(QRectF(0,0,0,0), QPen(QColor("black") ), QColor("white"));
   136 				ellipseFrame->setZValue(Z_FRAME);
   137 				break;
   138 		}
   139 		setVisibility (visible);
   140 	}
   141 }
   142 
   143 void FrameObj::setFrameType(const QString &t)
   144 {
   145 	if (t=="Rectangle")
   146 		FrameObj::setFrameType (Rectangle);
   147 	else if (t=="Ellipse")	
   148 		FrameObj::setFrameType (Ellipse);
   149 	else	
   150 		FrameObj::setFrameType (NoFrame);
   151 }
   152 
   153 void FrameObj::setVisibility (bool v)
   154 {
   155     MapObj::setVisibility(v);
   156 	switch (type)
   157 	{
   158 		case NoFrame:
   159 			break;
   160 		case Rectangle:
   161 			if (visible)
   162 				rectFrame->show();
   163 			else    
   164 				rectFrame->hide();
   165 			break;
   166 		case Ellipse:
   167 			if (visible)
   168 				ellipseFrame->show();
   169 			else    
   170 				ellipseFrame->hide();
   171 			break;
   172 	}
   173 }
   174 
   175 QString FrameObj::saveToDir ()
   176 {
   177 	QString	frameTypeAttr=attribut ("frameType",getFrameTypeName());
   178 	return singleElement ("frame",frameTypeAttr);
   179 }
   180