ornamentedobj.cpp
author insilmaril
Tue, 26 May 2009 11:23:44 +0000
changeset 773 340bc29da9a0
parent 767 6d2b32f305f9
child 776 25e634a7e1dc
permissions -rw-r--r--
Various fixes and simplifications
     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 	VymModel *model=treeItem->getModel();
    66 	if (!model) return;
    67 	if (model->getMapLinkColorHint()==HeadingColor)
    68 		LinkableMapObj::setLinkColor (heading->getColor());
    69 	else	
    70 		LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
    71 }
    72 
    73 void OrnamentedObj::setColor (QColor col)
    74 {
    75     heading->setColor(col);
    76 	setLinkColor();
    77 }
    78 
    79 QColor OrnamentedObj::getColor ()
    80 {
    81     return heading->getColor();
    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 	updateLink();
   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 	updateLink();
   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)
   254 {
   255 	return systemFlags->getFlagName(p);	
   256 }
   257 
   258 /* FIXME-3 should move to VymView ?!  void OrnamentedObj::getNoteFromTextEditor ()
   259 {
   260 	note.setFilenameHint (textEditor->getFilename());
   261 	note.setFontHint (textEditor->getFontHint() );
   262 	setNote( textEditor->getText() );
   263 }
   264 */
   265 
   266 QString OrnamentedObj::getOrnXMLAttr()	//FIXME-2 still needed?
   267 {
   268 	QString posAttr;
   269 
   270 	if (treeItem->depth()==0)
   271 		posAttr=		
   272 			attribut("absPosX",QString().setNum(absPos.x())) +
   273 			attribut("absPosY",QString().setNum(absPos.y())); 
   274 	else
   275 	{
   276 	/* FIXME-2
   277 		if (treeItem->depth()==1 || typid (*this)==typid (FloatImageObj))
   278 		{
   279 			if (relPos.x()==0 && relPos.y()==0)
   280 				setRelPos();
   281 			posAttr=
   282 				attribut("relPosX",QString().setNum(relPos.x())) +
   283 				attribut("relPosY",QString().setNum(relPos.y())); 
   284 		} else
   285 			posAttr="";
   286 	*/		
   287 	}	
   288 
   289 /* FIXME-2 QString hideExpAttr;
   290 	if (hideExport)
   291 		hideExpAttr= attribut("hideInExport","true");
   292 	else	
   293 		hideExpAttr="";
   294 */
   295 	return posAttr +getLinkAttr() ;//+hideExpAttr;
   296 }
   297