ornamentedobj.cpp
author insilmaril
Wed, 22 Jul 2009 11:48:23 +0000
changeset 781 6cbf3c9cbd21
parent 779 1fb50e79661c
child 785 5987f9f15bac
permissions -rw-r--r--
Empty branches are always unscrolled after import, relinking to scrolled branch doesn't open branch, starting DBUS implementation
     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* OrnamentedObj::getFrame()
    80 {
    81 	return frame;
    82 }
    83 
    84 FrameObj::FrameType OrnamentedObj::getFrameType()
    85 {
    86 	return frame->getFrameType();
    87 }
    88 
    89 QString OrnamentedObj::getFrameTypeName()
    90 {
    91 	return frame->getFrameTypeName();
    92 }
    93 
    94 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
    95 {
    96 	frame->setFrameType(t);
    97 	if (t == FrameObj::NoFrame)
    98 		linkpos=LinkableMapObj::Bottom;
    99 	else	
   100 		linkpos=LinkableMapObj::Middle;
   101 
   102 	calcBBoxSize();
   103 	positionBBox();
   104 	requestReposition();
   105 }
   106 
   107 void OrnamentedObj::setFrameType(const QString &t)
   108 {
   109 	frame->setFrameType(t);
   110 	if (frame->getFrameType() == FrameObj::NoFrame)
   111 		linkpos=LinkableMapObj::Bottom;
   112 	else	
   113 		linkpos=LinkableMapObj::Middle;
   114 
   115 	calcBBoxSize();
   116 	positionBBox();
   117 	requestReposition();
   118 }
   119 
   120 void OrnamentedObj::setFramePadding (const int &i)
   121 {
   122 	frame->setPadding (i);
   123 	calcBBoxSize();
   124 	positionBBox();
   125 	requestReposition();
   126 }
   127 
   128 int OrnamentedObj::getFramePadding ()
   129 {
   130 	return frame->getPadding();
   131 }
   132 
   133 void OrnamentedObj::setFrameBorderWidth (const int &i)
   134 {
   135 	frame->setBorderWidth(i);
   136 	calcBBoxSize();
   137 	positionBBox();
   138 	requestReposition();
   139 }
   140 
   141 int OrnamentedObj::getFrameBorderWidth()
   142 {
   143 	return frame->getBorderWidth();
   144 }
   145 
   146 void OrnamentedObj::setFramePenColor(QColor col)
   147 {
   148 	frame->setPenColor (col);
   149 }
   150 
   151 QColor OrnamentedObj::getFramePenColor()
   152 {
   153 	return frame->getPenColor ();
   154 }
   155 
   156 void OrnamentedObj::setFrameBrushColor(QColor col)
   157 {
   158 	frame->setBrushColor (col);
   159 }
   160 
   161 QColor OrnamentedObj::getFrameBrushColor()
   162 {
   163 	return frame->getBrushColor ();
   164 }
   165 
   166 void OrnamentedObj::positionContents()
   167 {
   168 	double d=frame->getPadding()/2;
   169 	double x=absPos.x();
   170 	double y=absPos.y();
   171 
   172 	double ox,oy;	// Offset due to padding
   173 
   174 	ox=leftPad + d;
   175 	oy=topPad + d;
   176 	
   177 	systemFlags-> move (ox +x , oy + y );
   178 
   179 	// vertical align heading to bottom
   180     heading->move (ox + x + systemFlags->getBBox().width(),
   181 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   182 					);
   183 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   184 
   185 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   186 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   187 }
   188 
   189 void OrnamentedObj::move (double x, double y)
   190 {
   191 	MapObj::move (x,y);
   192 	positionContents();
   193 	updateLinkGeometry();
   194 	requestReposition();
   195 }
   196 
   197 void OrnamentedObj::move (QPointF p)
   198 {
   199 	move (p.x(), p.y());
   200 }	
   201 
   202 void OrnamentedObj::moveBy (double x, double y)
   203 {
   204 
   205 	MapObj::moveBy (x,y);
   206     frame->moveBy (x,y);
   207     systemFlags->moveBy (x,y);
   208     standardFlags->moveBy (x,y);
   209     heading->moveBy (x,y);
   210 	updateLinkGeometry();
   211 	requestReposition();
   212 }
   213 
   214 void OrnamentedObj::moveBy (QPointF p)
   215 {
   216 	moveBy (p.x(), p.y());
   217 }	
   218 
   219 void OrnamentedObj::move2RelPos(double x, double y)
   220 {
   221 	setRelPos (QPointF(x,y));
   222 	if (parObj)
   223 	{
   224 		QPointF p=parObj->getChildPos();
   225 		move (p.x()+x, p.y() +y);
   226 	}
   227 }
   228 
   229 void OrnamentedObj::move2RelPos(QPointF p)
   230 {
   231 	move2RelPos (p.x(),p.y());
   232 }
   233 
   234 void OrnamentedObj::activateStandardFlag(Flag *flag)
   235 {
   236 	standardFlags->activate(flag);
   237 	calcBBoxSize();
   238 	positionBBox();
   239 	move (absPos.x(), absPos.y() );
   240 	forceReposition();
   241 }
   242 
   243 void OrnamentedObj::deactivateStandardFlag(const QString &name)
   244 {
   245 	standardFlags->deactivate(name);
   246 	calcBBoxSize();
   247 	positionBBox();
   248 	move (absPos.x(), absPos.y() );
   249 	forceReposition();
   250 }
   251 
   252 
   253 QString OrnamentedObj::getSystemFlagName(const QPointF &p) //FIXME-3
   254 {
   255 	return systemFlags->getFlagName(p);	
   256 }
   257