frameobj.cpp
author insilmaril
Wed Apr 25 16:02:54 2007 +0000 (2007-04-25)
changeset 464 d42d12074ff4
parent 425 7014be3ac7d0
child 470 80ae7b79828c
permissions -rw-r--r--
started doxygen documentation
     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 	penColor=QColor (Qt::black);
    30 	brushColor=QColor (Qt::white);
    31 }
    32 
    33 void FrameObj::clear()
    34 {
    35     switch (type)
    36     {
    37 		case NoFrame:
    38 			break;
    39 		case Rectangle:
    40 			delete rectFrame;
    41 			break;
    42 		case Ellipse:
    43 			delete ellipseFrame;
    44 			break;
    45     }
    46 	type=NoFrame;
    47 	border=0;
    48 }
    49 
    50 void FrameObj::move(double x, double y)
    51 {
    52     switch (type)
    53     {
    54 		case NoFrame:
    55 			break;
    56 		case Rectangle:
    57 			rectFrame->setPos (x,y);
    58 			break;
    59 		case Ellipse:
    60 			ellipseFrame->setPos (x,y);
    61 			break;
    62     }
    63 }
    64 
    65 void FrameObj::moveBy(double x, double y)
    66 {
    67 	MapObj::moveBy (x,y);
    68 }
    69 
    70 void FrameObj::positionBBox()
    71 {
    72 }
    73 
    74 void FrameObj::calcBBoxSize()
    75 {
    76 }
    77 
    78 void FrameObj::setRect(const QRectF &r)
    79 {
    80 	bbox=r;
    81     switch (type)
    82     {
    83 		case NoFrame:
    84 			break;
    85 		case Rectangle:
    86 	//		rectFrame->prepareGeometryChange();
    87 			rectFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    88 			break;
    89 		case Ellipse:
    90 	//		ellipseFrame->prepareGeometryChange();
    91 			ellipseFrame->setRect (QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ));
    92 			break;
    93     }
    94 }
    95 
    96 int FrameObj::getBorder()
    97 {
    98 	return border;
    99 }
   100 
   101 FrameType FrameObj::getFrameType()
   102 {
   103 	return type;
   104 }
   105 
   106 QString FrameObj::getFrameTypeName()
   107 {
   108     switch (type)
   109     {
   110 		case Rectangle:
   111 			return "Rectangle";
   112 			break;
   113 		case Ellipse:
   114 			return "Ellipse";
   115 			break;
   116 		default:
   117 			return "NoFrame";
   118     }
   119 }
   120 
   121 void FrameObj::setFrameType(const FrameType &t)
   122 {
   123 	if (t!=type)
   124 	{
   125 		clear();
   126 		type=t;
   127 		switch (type)
   128 		{
   129 			case NoFrame:
   130 				border=0;
   131 				break;
   132 			case Rectangle:
   133 				border=10;
   134 				rectFrame = scene->addRect(QRectF(0,0,0,0), QPen(penColor), brushColor);
   135 				rectFrame->setZValue(Z_FRAME);
   136 				rectFrame->show();
   137 				break;
   138 			case Ellipse:
   139 				border=10;
   140 				ellipseFrame = scene->addEllipse(QRectF(0,0,0,0), QPen(penColor), brushColor);
   141 				ellipseFrame->setZValue(Z_FRAME);
   142 				ellipseFrame->show();
   143 				break;
   144 		}
   145 	}
   146 	setVisibility (visible);
   147 }
   148 
   149 void FrameObj::setFrameType(const QString &t)
   150 {
   151 	if (t=="Rectangle")
   152 		FrameObj::setFrameType (Rectangle);
   153 	else if (t=="Ellipse")	
   154 		FrameObj::setFrameType (Ellipse);
   155 	else	
   156 		FrameObj::setFrameType (NoFrame);
   157 }
   158 
   159 void FrameObj::setPenColor (QColor col)
   160 {
   161 	penColor=col;
   162 	repaint();
   163 }
   164 
   165 QColor FrameObj::getPenColor ()
   166 {
   167 	return penColor;
   168 }
   169 
   170 void FrameObj::setBrushColor (QColor col)
   171 {
   172 	brushColor=col;
   173 	repaint();
   174 }
   175 
   176 QColor FrameObj::getBrushColor ()
   177 {
   178 	return brushColor;
   179 }
   180 
   181 void FrameObj::repaint()
   182 {
   183 	switch (type)
   184 	{
   185 		case Rectangle:
   186 			rectFrame->setPen   (penColor);
   187 			rectFrame->setBrush (brushColor);
   188 			break;
   189 		case Ellipse:
   190 			ellipseFrame->setPen   (penColor);
   191 			ellipseFrame->setBrush (brushColor);
   192 			break;
   193 		default:
   194 			break;
   195 	}
   196 }
   197 
   198 
   199 void FrameObj::setVisibility (bool v)
   200 {
   201     MapObj::setVisibility(v);
   202 	switch (type)
   203 	{
   204 		case NoFrame:
   205 			break;
   206 		case Rectangle:
   207 			if (visible)
   208 				rectFrame->show();
   209 			else    
   210 				rectFrame->hide();
   211 			break;
   212 		case Ellipse:
   213 			if (visible)
   214 				ellipseFrame->show();
   215 			else    
   216 				ellipseFrame->hide();
   217 			break;
   218 	}
   219 }
   220 
   221 QString FrameObj::saveToDir ()
   222 {
   223 	QString	frameTypeAttr=attribut ("frameType",getFrameTypeName());
   224 	QString	penColAttr=attribut ("penColor",penColor.name() );
   225 	QString	brushColAttr=attribut ("brushColor",brushColor.name() );
   226 	return singleElement ("frame",frameTypeAttr + penColAttr + brushColAttr);
   227 }
   228