ornamentedobj.cpp
author insilmaril
Mon, 07 Dec 2009 21:56:46 +0000
changeset 815 2881c4424190
parent 798 d251c7b2de54
child 819 8f987e376035
permissions -rw-r--r--
bugfixes, added flag-wip
     1 #include "ornamentedobj.h"
     2 #include "linkablemapobj.h"
     3 #include "vymmodel.h"
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // OrnamentedObj
     7 /////////////////////////////////////////////////////////////////
     8 
     9 
    10 OrnamentedObj::OrnamentedObj(QGraphicsScene* s,TreeItem *ti) :LinkableMapObj(s,ti)
    11 {
    12 //    cout << "Const OrnamentedObj (s)\n";
    13     init ();
    14 }
    15 
    16 OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
    17 {
    18     copy (lmo);
    19 }
    20 
    21 OrnamentedObj::~OrnamentedObj()
    22 {
    23     delete heading;
    24 	delete systemFlags;
    25 	delete standardFlags;
    26 	delete frame;
    27 }
    28 
    29 
    30 void OrnamentedObj::init ()
    31 {
    32 	heading = new HeadingObj(scene);
    33 	heading->move (absPos.x(), absPos.y());
    34 
    35 	systemFlags=new FlagRowObj(scene);
    36 	standardFlags=new FlagRowObj(scene);
    37 
    38 	frame = new FrameObj (scene);
    39 }
    40 
    41 void OrnamentedObj::copy (OrnamentedObj* other)
    42 {
    43     LinkableMapObj::copy(other);
    44 	heading->copy(other->heading);
    45     setColor   (other->heading->getColor());	
    46 
    47 	systemFlags->copy (other->systemFlags);
    48 	standardFlags->copy (other->standardFlags);
    49 
    50 	ornamentsBBox=other->ornamentsBBox;
    51 }
    52 
    53 void OrnamentedObj::setLinkColor()
    54 {
    55 	VymModel *model=treeItem->getModel();
    56 	if (!model) return;
    57 	if (model->getMapLinkColorHint()==HeadingColor)
    58 		LinkableMapObj::setLinkColor (heading->getColor());
    59 	else	
    60 		LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
    61 }
    62 
    63 void OrnamentedObj::setColor (QColor col)
    64 {
    65     heading->setColor(col);
    66 	setLinkColor();
    67 }
    68 
    69 QColor OrnamentedObj::getColor ()
    70 {
    71     return heading->getColor();
    72 }
    73 
    74 FrameObj* OrnamentedObj::getFrame()
    75 {
    76 	return frame;
    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 	{
    94 		linkpos=LinkableMapObj::Bottom;
    95 		useBottomline=true;
    96 	} else	
    97 	{
    98 		linkpos=LinkableMapObj::Middle;
    99 		useBottomline=false;
   100 	}
   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 //#include <iostream>  
   167 //using namespace std;
   168 void OrnamentedObj::positionContents()	//FIXME-4 called multiple times for each object after moving an image with mouse
   169 {
   170 //cout << "OO::positionContents topPad="<<topPad<<"  botPad="<<botPad<<"  "<<treeItem->getHeadingStd()<<endl;
   171 	double d=frame->getPadding()/2;
   172 	double x=absPos.x();
   173 	double y=absPos.y();
   174 
   175 	double ox,oy;	// Offset due to padding
   176 
   177 	ox=leftPad + d;
   178 	oy=topPad + d;
   179 	
   180 	systemFlags-> move (ox +x , oy + y );
   181 
   182 	// vertical align heading to bottom
   183     heading->move (ox + x + systemFlags->getBBox().width(),
   184 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   185 					);
   186 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   187 
   188 	ornamentsBBox.moveTopLeft ( QPointF (ox+x,oy+y));
   189 	clickBox.moveTopLeft (QPointF (ox + x, oy + y));
   190 }
   191 
   192 void OrnamentedObj::move (double x, double y)
   193 {
   194 	MapObj::move (x,y);
   195 	positionContents();
   196 	updateLinkGeometry();
   197 	requestReposition();
   198 }
   199 
   200 void OrnamentedObj::move (QPointF p)
   201 {
   202 	move (p.x(), p.y());
   203 }	
   204 
   205 void OrnamentedObj::moveBy (double x, double y)
   206 {
   207 
   208 	MapObj::moveBy (x,y);
   209     frame->moveBy (x,y);
   210     systemFlags->moveBy (x,y);
   211     standardFlags->moveBy (x,y);
   212     heading->moveBy (x,y);
   213 	updateLinkGeometry();
   214 	requestReposition();
   215 }
   216 
   217 void OrnamentedObj::moveBy (QPointF p)
   218 {
   219 	moveBy (p.x(), p.y());
   220 }	
   221 
   222 void OrnamentedObj::move2RelPos(double x, double y)
   223 {
   224 	setRelPos (QPointF(x,y));
   225 	if (parObj)
   226 	{
   227 		QPointF p=parObj->getChildPos();
   228 		move (p.x()+x, p.y() +y);
   229 	}
   230 }
   231 
   232 void OrnamentedObj::move2RelPos(QPointF p)
   233 {
   234 	move2RelPos (p.x(),p.y());
   235 }
   236 
   237 void OrnamentedObj::activateStandardFlag(Flag *flag)
   238 {
   239 	standardFlags->activate(flag);
   240 	calcBBoxSize();
   241 	positionBBox();
   242 	move (absPos.x(), absPos.y() );
   243 	forceReposition();
   244 }
   245 
   246 void OrnamentedObj::deactivateStandardFlag(const QString &name)
   247 {
   248 	standardFlags->deactivate(name);
   249 	calcBBoxSize();
   250 	positionBBox();
   251 	move (absPos.x(), absPos.y() );
   252 	forceReposition();
   253 }
   254 
   255 
   256 QString OrnamentedObj::getSystemFlagName(const QPointF &p) //FIXME-3
   257 {
   258 	return systemFlags->getFlagName(p);	
   259 }
   260