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