ornamentedobj.cpp
author convert-repo
Fri Jul 23 16:43:49 2010 +0000 (2010-07-23)
changeset 849 988f1908a7c4
parent 798 d251c7b2de54
permissions -rw-r--r--
update tags
     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 QRectF OrnamentedObj::getBBoxHeading()
    75 {
    76     return heading->getBBox();
    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 	{
    99 		linkpos=LinkableMapObj::Bottom;
   100 		useBottomline=true;
   101 	} else	
   102 	{
   103 		linkpos=LinkableMapObj::Middle;
   104 		useBottomline=false;
   105 	}
   106 
   107 	calcBBoxSize();
   108 	positionBBox();
   109 	requestReposition();
   110 }
   111 
   112 void OrnamentedObj::setFrameType(const QString &t)
   113 {
   114 	frame->setFrameType(t);
   115 	if (frame->getFrameType() == FrameObj::NoFrame)
   116 		linkpos=LinkableMapObj::Bottom;
   117 	else	
   118 		linkpos=LinkableMapObj::Middle;
   119 
   120 	calcBBoxSize();
   121 	positionBBox();
   122 	requestReposition();
   123 }
   124 
   125 void OrnamentedObj::setFramePadding (const int &i)
   126 {
   127 	frame->setPadding (i);
   128 	calcBBoxSize();
   129 	positionBBox();
   130 	requestReposition();
   131 }
   132 
   133 int OrnamentedObj::getFramePadding ()
   134 {
   135 	return frame->getPadding();
   136 }
   137 
   138 void OrnamentedObj::setFrameBorderWidth (const int &i)
   139 {
   140 	frame->setBorderWidth(i);
   141 	calcBBoxSize();
   142 	positionBBox();
   143 	requestReposition();
   144 }
   145 
   146 int OrnamentedObj::getFrameBorderWidth()
   147 {
   148 	return frame->getBorderWidth();
   149 }
   150 
   151 void OrnamentedObj::setFramePenColor(QColor col)
   152 {
   153 	frame->setPenColor (col);
   154 }
   155 
   156 QColor OrnamentedObj::getFramePenColor()
   157 {
   158 	return frame->getPenColor ();
   159 }
   160 
   161 void OrnamentedObj::setFrameBrushColor(QColor col)
   162 {
   163 	frame->setBrushColor (col);
   164 }
   165 
   166 QColor OrnamentedObj::getFrameBrushColor()
   167 {
   168 	return frame->getBrushColor ();
   169 }
   170 
   171 //#include <iostream>  
   172 //using namespace std;
   173 void OrnamentedObj::positionContents()	//FIXME-4 called multiple times for each object after moving an image with mouse
   174 {
   175 //cout << "OO::positionContents topPad="<<topPad<<"  botPad="<<botPad<<"  "<<treeItem->getHeadingStd()<<endl;
   176 	double d=frame->getPadding()/2;
   177 	double x=absPos.x();
   178 	double y=absPos.y();
   179 
   180 	double ox,oy;	// Offset due to padding
   181 
   182 	ox=leftPad + d;
   183 	oy=topPad + d;
   184 	
   185 	systemFlags-> move (ox +x , oy + y );
   186 
   187 	// vertical align heading to bottom
   188     heading->move (ox + x + systemFlags->getBBox().width(),
   189 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   190 					);
   191 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   192 
   193 	ornamentsBBox.moveTopLeft ( QPointF (ox+x,oy+y));
   194 	clickBox.moveTopLeft (QPointF (ox + x, oy + y));
   195 }
   196 
   197 void OrnamentedObj::move (double x, double y)
   198 {
   199 	MapObj::move (x,y);
   200 	positionContents();
   201 	updateLinkGeometry();
   202 	requestReposition();
   203 }
   204 
   205 void OrnamentedObj::move (QPointF p)
   206 {
   207 	move (p.x(), p.y());
   208 }	
   209 
   210 void OrnamentedObj::moveBy (double x, double y)
   211 {
   212 
   213 	MapObj::moveBy (x,y);
   214     frame->moveBy (x,y);
   215     systemFlags->moveBy (x,y);
   216     standardFlags->moveBy (x,y);
   217     heading->moveBy (x,y);
   218 	updateLinkGeometry();
   219 	requestReposition();
   220 }
   221 
   222 void OrnamentedObj::moveBy (QPointF p)
   223 {
   224 	moveBy (p.x(), p.y());
   225 }	
   226 
   227 void OrnamentedObj::move2RelPos(double x, double y)
   228 {
   229 	setRelPos (QPointF(x,y));
   230 	if (parObj)
   231 	{
   232 		QPointF p=parObj->getChildPos();
   233 		move (p.x()+x, p.y() +y);
   234 	}
   235 }
   236 
   237 void OrnamentedObj::move2RelPos(QPointF p)
   238 {
   239 	move2RelPos (p.x(),p.y());
   240 }
   241 
   242 void OrnamentedObj::activateStandardFlag(Flag *flag)
   243 {
   244 	standardFlags->activate(flag);
   245 	calcBBoxSize();
   246 	positionBBox();
   247 	move (absPos.x(), absPos.y() );
   248 	forceReposition();
   249 }
   250 
   251 void OrnamentedObj::deactivateStandardFlag(const QString &name)
   252 {
   253 	standardFlags->deactivate(name);
   254 	calcBBoxSize();
   255 	positionBBox();
   256 	move (absPos.x(),absPos.y() );
   257 	forceReposition();
   258 }
   259 
   260 
   261 QString OrnamentedObj::getSystemFlagName(const QPointF &p) 
   262 {
   263 	return systemFlags->getFlagName(p);	
   264 }
   265 
   266 QRectF OrnamentedObj::getBBoxFlag (const QString &s)
   267 {
   268 	FlagObj *fo=systemFlags->findFlag (s);
   269 	if (fo) return fo->getBBox();
   270 	fo=standardFlags->findFlag (s);
   271 	if (fo) return fo->getBBox();
   272 	return QRectF();
   273 }
   274