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