ornamentedobj.cpp
author insilmaril
Mon, 08 Jun 2009 11:36:56 +0000
changeset 776 25e634a7e1dc
parent 773 340bc29da9a0
child 777 8acac4fade1b
permissions -rw-r--r--
Images basically work (again)
     1 #include "ornamentedobj.h"
     2 #include "linkablemapobj.h"
     3 #include "vymmodel.h"
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // OrnamentedObj
     7 /////////////////////////////////////////////////////////////////
     8 
     9 OrnamentedObj::OrnamentedObj():LinkableMapObj()
    10 {
    11   //  cout << "Const OrnamentedObj ()\n";
    12     init ();
    13 }
    14 
    15 OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
    16 {
    17 //    cout << "Const OrnamentedObj (s)\n";
    18     init ();
    19 }
    20 
    21 OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
    22 {
    23     copy (lmo);
    24 }
    25 
    26 OrnamentedObj::~OrnamentedObj()
    27 {
    28     delete heading;
    29 	delete systemFlags;
    30 	delete standardFlags;
    31 	delete frame;
    32 }
    33 
    34 
    35 void OrnamentedObj::init ()
    36 {
    37 	heading = new HeadingObj(scene);
    38 	heading->move (absPos.x(), absPos.y());
    39 
    40 	systemFlags=new FlagRowObj(scene);
    41 	standardFlags=new FlagRowObj(scene);
    42 
    43 	frame = new FrameObj (scene);
    44 }
    45 
    46 void OrnamentedObj::copy (OrnamentedObj* other)
    47 {
    48     LinkableMapObj::copy(other);
    49 	heading->copy(other->heading);
    50     setColor   (other->heading->getColor());	
    51 
    52 	systemFlags->copy (other->systemFlags);
    53 	standardFlags->copy (other->standardFlags);
    54 
    55 	ornamentsBBox=other->ornamentsBBox;
    56 }
    57 
    58 void OrnamentedObj::setLinkColor()
    59 {
    60 	VymModel *model=treeItem->getModel();
    61 	if (!model) return;
    62 	if (model->getMapLinkColorHint()==HeadingColor)
    63 		LinkableMapObj::setLinkColor (heading->getColor());
    64 	else	
    65 		LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
    66 }
    67 
    68 void OrnamentedObj::setColor (QColor col)
    69 {
    70     heading->setColor(col);
    71 	setLinkColor();
    72 }
    73 
    74 QColor OrnamentedObj::getColor ()
    75 {
    76     return heading->getColor();
    77 }
    78 
    79 FrameObj::FrameType OrnamentedObj::getFrameType()
    80 {
    81 	return frame->getFrameType();
    82 }
    83 
    84 QString OrnamentedObj::getFrameTypeName()
    85 {
    86 	return frame->getFrameTypeName();
    87 }
    88 
    89 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
    90 {
    91 	frame->setFrameType(t);
    92 	if (t == FrameObj::NoFrame)
    93 		linkpos=LinkableMapObj::Bottom;
    94 	else	
    95 		linkpos=LinkableMapObj::Middle;
    96 
    97 	calcBBoxSize();
    98 	positionBBox();
    99 	requestReposition();
   100 }
   101 
   102 void OrnamentedObj::setFrameType(const QString &t)
   103 {
   104 	frame->setFrameType(t);
   105 	if (frame->getFrameType() == FrameObj::NoFrame)
   106 		linkpos=LinkableMapObj::Bottom;
   107 	else	
   108 		linkpos=LinkableMapObj::Middle;
   109 
   110 	calcBBoxSize();
   111 	positionBBox();
   112 	requestReposition();
   113 }
   114 
   115 void OrnamentedObj::setFramePadding (const int &i)
   116 {
   117 	frame->setPadding (i);
   118 	calcBBoxSize();
   119 	positionBBox();
   120 	requestReposition();
   121 }
   122 
   123 int OrnamentedObj::getFramePadding ()
   124 {
   125 	return frame->getPadding();
   126 }
   127 
   128 void OrnamentedObj::setFrameBorderWidth (const int &i)
   129 {
   130 	frame->setBorderWidth(i);
   131 	calcBBoxSize();
   132 	positionBBox();
   133 	requestReposition();
   134 }
   135 
   136 int OrnamentedObj::getFrameBorderWidth()
   137 {
   138 	return frame->getBorderWidth();
   139 }
   140 
   141 void OrnamentedObj::setFramePenColor(QColor col)
   142 {
   143 	frame->setPenColor (col);
   144 }
   145 
   146 QColor OrnamentedObj::getFramePenColor()
   147 {
   148 	return frame->getPenColor ();
   149 }
   150 
   151 void OrnamentedObj::setFrameBrushColor(QColor col)
   152 {
   153 	frame->setBrushColor (col);
   154 }
   155 
   156 QColor OrnamentedObj::getFrameBrushColor()
   157 {
   158 	return frame->getBrushColor ();
   159 }
   160 
   161 void OrnamentedObj::positionContents()
   162 {
   163 	double d=frame->getPadding()/2;
   164 	double x=absPos.x();
   165 	double y=absPos.y();
   166 
   167 	double ox,oy;	// Offset due to padding
   168 
   169 	ox=leftPad + d;
   170 	oy=topPad + d;
   171 	
   172 	systemFlags-> move (ox +x , oy + y );
   173 
   174 	// vertical align heading to bottom
   175     heading->move (ox + x + systemFlags->getBBox().width(),
   176 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   177 					);
   178 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   179 
   180 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   181 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   182 }
   183 
   184 void OrnamentedObj::move (double x, double y)
   185 {
   186 	MapObj::move (x,y);
   187 	positionContents();
   188 	updateLink();
   189 	requestReposition();
   190 }
   191 
   192 void OrnamentedObj::move (QPointF p)
   193 {
   194 	move (p.x(), p.y());
   195 }	
   196 
   197 void OrnamentedObj::moveBy (double x, double y)
   198 {
   199 
   200 	MapObj::moveBy (x,y);
   201     frame->moveBy (x,y);
   202     systemFlags->moveBy (x,y);
   203     standardFlags->moveBy (x,y);
   204     heading->moveBy (x,y);
   205 	updateLink();
   206 	requestReposition();
   207 }
   208 
   209 void OrnamentedObj::moveBy (QPointF p)
   210 {
   211 	moveBy (p.x(), p.y());
   212 }	
   213 
   214 void OrnamentedObj::move2RelPos(double x, double y)
   215 {
   216 	setRelPos (QPointF(x,y));
   217 	if (parObj)
   218 	{
   219 		QPointF p=parObj->getChildPos();
   220 		move (p.x()+x, p.y() +y);
   221 	}
   222 }
   223 
   224 void OrnamentedObj::move2RelPos(QPointF p)
   225 {
   226 	move2RelPos (p.x(),p.y());
   227 }
   228 
   229 void OrnamentedObj::activateStandardFlag(Flag *flag)
   230 {
   231 	standardFlags->activate(flag);
   232 	calcBBoxSize();
   233 	positionBBox();
   234 	move (absPos.x(), absPos.y() );
   235 	forceReposition();
   236 }
   237 
   238 void OrnamentedObj::deactivateStandardFlag(const QString &name)
   239 {
   240 	standardFlags->deactivate(name);
   241 	calcBBoxSize();
   242 	positionBBox();
   243 	move (absPos.x(), absPos.y() );
   244 	forceReposition();
   245 }
   246 
   247 
   248 QString OrnamentedObj::getSystemFlagName(const QPointF &p) //FIXME-3
   249 {
   250 	return systemFlags->getFlagName(p);	
   251 }
   252