ornamentedobj.cpp
author insilmaril
Wed, 29 Apr 2009 21:40:37 +0000
changeset 761 0301e6109702
parent 755 ed5b407975b3
child 766 7a71a914afdb
permissions -rw-r--r--
speedup
     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 extern FlagRowObj *systemFlagsDefault;
    10 extern FlagRowObj *standardFlagsDefault;
    11 
    12 
    13 /////////////////////////////////////////////////////////////////
    14 // OrnamentedObj
    15 /////////////////////////////////////////////////////////////////
    16 
    17 OrnamentedObj::OrnamentedObj():LinkableMapObj()
    18 {
    19   //  cout << "Const OrnamentedObj ()\n";
    20     init ();
    21 }
    22 
    23 OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
    24 {
    25 //    cout << "Const OrnamentedObj (s)\n";
    26     init ();
    27 }
    28 
    29 OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
    30 {
    31     copy (lmo);
    32 }
    33 
    34 OrnamentedObj::~OrnamentedObj()
    35 {
    36     delete heading;
    37 	delete systemFlags;
    38 	delete standardFlags;
    39 	delete frame;
    40 }
    41 
    42 
    43 void OrnamentedObj::init ()
    44 {
    45 	heading = new HeadingObj(scene);
    46 	heading->move (absPos.x(), absPos.y());
    47 
    48 	systemFlags=new FlagRowObj(scene);
    49 	systemFlags->clone(systemFlagsDefault);
    50 	systemFlags->setName ("systemFlags");
    51 	
    52 	standardFlags=new FlagRowObj(scene);
    53 	standardFlags->clone(standardFlagsDefault);
    54 	standardFlags->setName ("standardFlags");
    55 
    56 	attributes.clear();
    57 
    58 	frame = new FrameObj (scene);
    59 
    60 	url="";
    61 	vymLink="";
    62 	
    63 }
    64 
    65 void OrnamentedObj::copy (OrnamentedObj* other)
    66 {
    67     LinkableMapObj::copy(other);
    68 	heading->copy(other->heading);
    69     setColor   (other->heading->getColor());	
    70 
    71 	systemFlags->copy (other->systemFlags);
    72 	standardFlags->copy (other->standardFlags);
    73 
    74 	ornamentsBBox=other->ornamentsBBox;
    75 
    76 	url=other->url;
    77 	vymLink=other->vymLink;
    78 }
    79 
    80 void OrnamentedObj::setLinkColor()
    81 {
    82 	if (model->getMapLinkColorHint()==HeadingColor)
    83 		LinkableMapObj::setLinkColor (heading->getColor());
    84 	else	
    85 		LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
    86 }
    87 
    88 void OrnamentedObj::setColor (QColor col)
    89 {
    90     heading->setColor(col);
    91 	setLinkColor();
    92 }
    93 
    94 QColor OrnamentedObj::getColor ()
    95 {
    96     return heading->getColor();
    97 }
    98 
    99 FrameObj::FrameType OrnamentedObj::getFrameType()
   100 {
   101 	return frame->getFrameType();
   102 }
   103 
   104 QString OrnamentedObj::getFrameTypeName()
   105 {
   106 	return frame->getFrameTypeName();
   107 }
   108 
   109 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
   110 {
   111 	frame->setFrameType(t);
   112 	if (t == FrameObj::NoFrame)
   113 		linkpos=LinkableMapObj::Bottom;
   114 	else	
   115 		linkpos=LinkableMapObj::Middle;
   116 
   117 	calcBBoxSize();
   118 	positionBBox();
   119 	requestReposition();
   120 }
   121 
   122 void OrnamentedObj::setFrameType(const QString &t)
   123 {
   124 	frame->setFrameType(t);
   125 	if (frame->getFrameType() == FrameObj::NoFrame)
   126 		linkpos=LinkableMapObj::Bottom;
   127 	else	
   128 		linkpos=LinkableMapObj::Middle;
   129 
   130 	calcBBoxSize();
   131 	positionBBox();
   132 	requestReposition();
   133 }
   134 
   135 void OrnamentedObj::setFramePadding (const int &i)
   136 {
   137 	frame->setPadding (i);
   138 	calcBBoxSize();
   139 	positionBBox();
   140 	requestReposition();
   141 }
   142 
   143 int OrnamentedObj::getFramePadding ()
   144 {
   145 	return frame->getPadding();
   146 }
   147 
   148 void OrnamentedObj::setFrameBorderWidth (const int &i)
   149 {
   150 	frame->setBorderWidth(i);
   151 	calcBBoxSize();
   152 	positionBBox();
   153 	requestReposition();
   154 }
   155 
   156 int OrnamentedObj::getFrameBorderWidth()
   157 {
   158 	return frame->getBorderWidth();
   159 }
   160 
   161 void OrnamentedObj::setFramePenColor(QColor col)
   162 {
   163 	frame->setPenColor (col);
   164 }
   165 
   166 QColor OrnamentedObj::getFramePenColor()
   167 {
   168 	return frame->getPenColor ();
   169 }
   170 
   171 void OrnamentedObj::setFrameBrushColor(QColor col)
   172 {
   173 	frame->setBrushColor (col);
   174 }
   175 
   176 QColor OrnamentedObj::getFrameBrushColor()
   177 {
   178 	return frame->getBrushColor ();
   179 }
   180 
   181 void OrnamentedObj::positionContents()
   182 {
   183 	double d=frame->getPadding()/2;
   184 	double x=absPos.x();
   185 	double y=absPos.y();
   186 
   187 	double ox,oy;	// Offset due to padding
   188 
   189 	ox=leftPad + d;
   190 	oy=topPad + d;
   191 	
   192 	//FIXME-2 systemFlags-> move (ox +x , oy + y );
   193 
   194 	// vertical align heading to bottom
   195     heading->move (ox + x + systemFlags->getBBox().width(),
   196 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   197 					);
   198 	//FIXME-2 standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   199 
   200 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   201 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   202 }
   203 
   204 void OrnamentedObj::move (double x, double y)
   205 {
   206 	MapObj::move (x,y);
   207 	positionContents();
   208 	updateLink();
   209 	requestReposition();
   210 }
   211 
   212 void OrnamentedObj::move (QPointF p)
   213 {
   214 	move (p.x(), p.y());
   215 }	
   216 
   217 void OrnamentedObj::moveBy (double x, double y)
   218 {
   219 
   220 	MapObj::moveBy (x,y);
   221     frame->moveBy (x,y);
   222     systemFlags->moveBy (x,y);
   223     standardFlags->moveBy (x,y);
   224     heading->moveBy (x,y);
   225 	updateLink();
   226 	requestReposition();
   227 }
   228 
   229 void OrnamentedObj::moveBy (QPointF p)
   230 {
   231 	moveBy (p.x(), p.y());
   232 }	
   233 
   234 void OrnamentedObj::move2RelPos(double x, double y)
   235 {
   236 	setRelPos (QPointF(x,y));
   237 	if (parObj)
   238 	{
   239 		QPointF p=parObj->getChildPos();
   240 		move (p.x()+x, p.y() +y);
   241 	}
   242 }
   243 
   244 void OrnamentedObj::move2RelPos(QPointF p)
   245 {
   246 	move2RelPos (p.x(),p.y());
   247 }
   248 
   249 void OrnamentedObj::setURL(QString s)
   250 {
   251 	url=s;
   252 	if (!url.isEmpty())
   253 		systemFlags->activate("url");
   254 	else	
   255 		systemFlags->deactivate("url");
   256 	calcBBoxSize();			// recalculate bbox
   257     positionBBox();			// rearrange contents
   258 	forceReposition();
   259 }
   260 
   261 QString OrnamentedObj::getURL()
   262 {
   263 	return url;
   264 }
   265 
   266 void OrnamentedObj::setVymLink(QString s)
   267 {
   268 	if (!s.isEmpty())
   269 	{
   270 		// We need the relative (from loading) 
   271 		// or absolute path (from User event)
   272 		// and build the absolute path.
   273 		// Note: If we have relative, use path of
   274 		// current map to build absolute path
   275 		QDir d(s);
   276 		if (!d.path().startsWith ("/"))
   277 		{
   278 			QString p=model->getDestPath();
   279 			int i=p.findRev("/",-1);
   280 			d.setPath(p.left(i)+"/"+s);
   281 			d.convertToAbs();
   282 		}
   283 		vymLink=d.path();
   284 		systemFlags->activate("vymLink");
   285 	}	
   286 	else	
   287 	{
   288 		systemFlags->deactivate("vymLink");
   289 		vymLink="";
   290 	}	
   291 	calcBBoxSize();			// recalculate bbox
   292     positionBBox();			// rearrange contents
   293 	forceReposition();
   294 }
   295 
   296 QString OrnamentedObj::getVymLink()
   297 {
   298 	return vymLink;
   299 }
   300 
   301 
   302 void OrnamentedObj::setAttributes (const QList <Attribute> &al)
   303 {
   304 	attributes=al;
   305 }
   306 
   307 QList <Attribute> OrnamentedObj::getAttributes()
   308 {
   309 	return attributes;
   310 }
   311 
   312 void OrnamentedObj::clearStandardFlags()
   313 {
   314 	standardFlags->deactivateAll();
   315 	calcBBoxSize();
   316 	positionBBox();
   317 	move (absPos.x(), absPos.y() );
   318 	forceReposition();
   319 }
   320 
   321 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   322 {
   323 	standardFlags->toggle(f,exclusive);
   324 	calcBBoxSize();
   325 	positionBBox();
   326 	move (absPos.x(), absPos.y() );
   327 	forceReposition();
   328 }
   329 
   330 void OrnamentedObj::activateStandardFlag(QString f)
   331 {
   332 	standardFlags->activate(f);
   333 	calcBBoxSize();
   334 	positionBBox();
   335 	move (absPos.x(), absPos.y() );
   336 	forceReposition();
   337 }
   338 
   339 void OrnamentedObj::deactivateStandardFlag(QString f)
   340 {
   341 	standardFlags->deactivate(f);
   342 	calcBBoxSize();
   343 	positionBBox();
   344 	move (absPos.x(), absPos.y() );
   345 	forceReposition();
   346 }
   347 
   348 bool OrnamentedObj::isSetStandardFlag (QString f)
   349 {
   350 	return standardFlags->isActive(f);
   351 }
   352 
   353 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
   354 {
   355 	return systemFlags->getFlagName(p);	
   356 }
   357 
   358 bool OrnamentedObj::isActiveFlag (const QString & fname)
   359 {
   360 	if (standardFlags->isActive (fname) ) return true;
   361 	return false;
   362 }
   363 
   364 /* FIXME-3 should move to VymView ?!  void OrnamentedObj::getNoteFromTextEditor ()
   365 {
   366 	note.setFilenameHint (textEditor->getFilename());
   367 	note.setFontHint (textEditor->getFontHint() );
   368 	setNote( textEditor->getText() );
   369 }
   370 */
   371 
   372 void OrnamentedObj::updateSystemFlags()
   373 {
   374 	// FIXME-3 check if note here and text in editor are still in sync!!	
   375 	// Best would be to always have current text here...
   376 	bool noteEmpty=treeItem->getNoteObj().isEmpty();
   377 	/*
   378 	if (isNoteInEditor)
   379 		noteEmpty=textEditor->isEmpty();
   380 	else	
   381 		noteEmpty=note.isEmpty();
   382 	*/	
   383 
   384 	if (!noteEmpty)
   385 	{	
   386 		if (systemFlags->isActive ("note")) return;
   387 		systemFlags->activate("note");
   388 	}	
   389 	else		
   390 	{	
   391 		if (!systemFlags->isActive ("note")) return;
   392 		systemFlags->deactivate("note");
   393 	}	
   394 	//model->setChanged();
   395 	calcBBoxSize();
   396 	positionBBox();	
   397 	move (absPos.x(), absPos.y() );
   398 	forceReposition();
   399 }	
   400 
   401 void OrnamentedObj::updateFlagsToolbar()
   402 {
   403 	standardFlags->updateToolbar();
   404 }
   405 
   406 QString OrnamentedObj::getOrnXMLAttr()
   407 {
   408 	QString posAttr;
   409 
   410 	if (treeItem->depth()==0)
   411 		posAttr=		
   412 			attribut("absPosX",QString().setNum(absPos.x())) +
   413 			attribut("absPosY",QString().setNum(absPos.y())); 
   414 	else
   415 	{
   416 		if (treeItem->depth()==1 || typeid (*this)==typeid (FloatImageObj))
   417 		{
   418 			if (relPos.x()==0 && relPos.y()==0)
   419 				setRelPos();
   420 			posAttr=
   421 				attribut("relPosX",QString().setNum(relPos.x())) +
   422 				attribut("relPosY",QString().setNum(relPos.y())); 
   423 		} else
   424 			posAttr="";
   425 	}	
   426 
   427 	QString urlAttr;
   428 	if (!url.isEmpty())
   429 		urlAttr=attribut ("url",url);
   430 
   431 	QString vymLinkAttr;
   432 	if (!vymLink.isEmpty())
   433 		vymLinkAttr=attribut ("vymLink",convertToRel(model->getDestPath(),vymLink) );
   434 
   435 /* FIXME-2 QString hideExpAttr;
   436 	if (hideExport)
   437 		hideExpAttr= attribut("hideInExport","true");
   438 	else	
   439 		hideExpAttr="";
   440 */
   441 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() ;//+hideExpAttr;
   442 }
   443