ornamentedobj.cpp
author insilmaril
Tue, 23 Oct 2007 13:05:22 +0000
changeset 611 a1ae877b438d
parent 476 a551ed6005cc
child 613 8fb5b3956b3e
permissions -rw-r--r--
Fixes for compiling with gcc 4.3
     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 	note.setNote("");
    49 	note.setFontHint (textEditor->getFontHintDefault() );
    50 	isNoteInEditor=false;
    51 
    52 	systemFlags=new FlagRowObj(scene);
    53 	systemFlags->clone(systemFlagsDefault);
    54 	systemFlags->setName ("systemFlags");
    55 	
    56 	standardFlags=new FlagRowObj(scene);
    57 	standardFlags->clone(standardFlagsDefault);
    58 	standardFlags->setName ("standardFlags");
    59 
    60 	frame = new FrameObj (scene);
    61 
    62 	hideExport=false;
    63 	hidden=false;
    64 
    65 	url="";
    66 	vymLink="";
    67 	
    68 }
    69 
    70 void OrnamentedObj::copy (OrnamentedObj* other)
    71 {
    72     LinkableMapObj::copy(other);
    73 	heading->copy(other->heading);
    74     setColor   (other->heading->getColor());	
    75 
    76 	note.copy (other->note);
    77 	systemFlags->copy (other->systemFlags);
    78 	standardFlags->copy (other->standardFlags);
    79 
    80 	ornamentsBBox=other->ornamentsBBox;
    81 
    82 	hideExport=other->hideExport;
    83 	url=other->url;
    84 	vymLink=other->vymLink;
    85 }
    86 
    87 QString OrnamentedObj::getHeading()
    88 {
    89     return heading->text();
    90 }
    91 
    92 void OrnamentedObj::setLinkColor()
    93 {
    94 	if (mapEditor->getMapLinkColorHint()==HeadingColor)
    95 		LinkableMapObj::setLinkColor (heading->getColor());
    96 	else	
    97 		LinkableMapObj::setLinkColor (mapEditor->getMapDefLinkColor());
    98 }
    99 
   100 void OrnamentedObj::setColor (QColor col)
   101 {
   102     heading->setColor(col);
   103 	setLinkColor();
   104 }
   105 
   106 QColor OrnamentedObj::getColor ()
   107 {
   108     return heading->getColor();
   109 }
   110 
   111 FrameObj::FrameType OrnamentedObj::getFrameType()
   112 {
   113 	return frame->getFrameType();
   114 }
   115 
   116 QString OrnamentedObj::getFrameTypeName()
   117 {
   118 	return frame->getFrameTypeName();
   119 }
   120 
   121 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
   122 {
   123 	frame->setFrameType(t);
   124 	if (t == FrameObj::NoFrame)
   125 		linkpos=LinkableMapObj::Bottom;
   126 	else	
   127 		linkpos=LinkableMapObj::Middle;
   128 
   129 	calcBBoxSize();
   130 	positionBBox();
   131 	requestReposition();
   132 }
   133 
   134 void OrnamentedObj::setFrameType(const QString &t)
   135 {
   136 	frame->setFrameType(t);
   137 	if (frame->getFrameType() == FrameObj::NoFrame)
   138 		linkpos=LinkableMapObj::Bottom;
   139 	else	
   140 		linkpos=LinkableMapObj::Middle;
   141 
   142 	calcBBoxSize();
   143 	positionBBox();
   144 	requestReposition();
   145 }
   146 
   147 void OrnamentedObj::setFramePadding (const int &i)
   148 {
   149 	frame->setPadding (i);
   150 	calcBBoxSize();
   151 	positionBBox();
   152 	requestReposition();
   153 }
   154 
   155 int OrnamentedObj::getFramePadding ()
   156 {
   157 	return frame->getPadding();
   158 }
   159 
   160 void OrnamentedObj::setFrameBorderWidth (const int &i)
   161 {
   162 	frame->setBorderWidth(i);
   163 	calcBBoxSize();
   164 	positionBBox();
   165 	requestReposition();
   166 }
   167 
   168 int OrnamentedObj::getFrameBorderWidth()
   169 {
   170 	return frame->getBorderWidth();
   171 }
   172 
   173 void OrnamentedObj::setFramePenColor(QColor col)
   174 {
   175 	frame->setPenColor (col);
   176 }
   177 
   178 QColor OrnamentedObj::getFramePenColor()
   179 {
   180 	return frame->getPenColor ();
   181 }
   182 
   183 void OrnamentedObj::setFrameBrushColor(QColor col)
   184 {
   185 	frame->setBrushColor (col);
   186 }
   187 
   188 QColor OrnamentedObj::getFrameBrushColor()
   189 {
   190 	return frame->getBrushColor ();
   191 }
   192 
   193 void OrnamentedObj::positionContents()
   194 {
   195 	double d=frame->getPadding()/2;
   196 	double x=absPos.x();
   197 	double y=absPos.y();
   198 
   199 	double ox,oy;	// Offset due to padding
   200 
   201 	ox=leftPad + d;
   202 	oy=topPad + d;
   203 	
   204 	systemFlags-> move (ox +x , oy + y );
   205 
   206 	// vertical align heading to bottom
   207     heading->move (ox + x + systemFlags->getBBox().width(),
   208 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   209 					);
   210 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   211 
   212 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   213 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   214 }
   215 
   216 void OrnamentedObj::move (double x, double y)
   217 {
   218 	MapObj::move (x,y);
   219 	positionContents();
   220 	updateLink();
   221 	requestReposition();
   222 }
   223 
   224 void OrnamentedObj::move (QPointF p)
   225 {
   226 	move (p.x(), p.y());
   227 }	
   228 
   229 void OrnamentedObj::moveBy (double x, double y)
   230 {
   231 
   232 	MapObj::moveBy (x,y);
   233     frame->moveBy (x,y);
   234     systemFlags->moveBy (x,y);
   235     standardFlags->moveBy (x,y);
   236     heading->moveBy (x,y);
   237 	updateLink();
   238 	requestReposition();
   239 }
   240 
   241 void OrnamentedObj::moveBy (QPointF p)
   242 {
   243 	moveBy (p.x(), p.y());
   244 }	
   245 
   246 void OrnamentedObj::move2RelPos(double x, double y)
   247 {
   248 	setRelPos (QPointF((int)x,(int)y));
   249 	if (parObj)
   250 	{
   251 		QPointF p=parObj->getChildPos();
   252 		move (p.x()+x, p.y() +y);
   253 	}
   254 }
   255 
   256 void OrnamentedObj::move2RelPos(QPointF p)
   257 {
   258 	move2RelPos (p.x(),p.y());
   259 }
   260 
   261 void OrnamentedObj::setNote(QString s)
   262 {
   263 	note.setNote(s);
   264 	updateNoteFlag();
   265 }
   266 
   267 void OrnamentedObj::setNote(NoteObj n)
   268 {
   269 	note=n;
   270 	updateNoteFlag();
   271 }
   272 
   273 QString OrnamentedObj::getNote()
   274 {
   275     return note.getNote();
   276 }
   277 
   278 QString OrnamentedObj::getNoteASCII()
   279 {
   280     return note.getNoteASCII();
   281 }
   282 
   283 QString OrnamentedObj::getNoteOpenDoc()
   284 {
   285     return note.getNoteOpenDoc();
   286 }
   287 
   288 void OrnamentedObj::setURL(QString s)
   289 {
   290 	url=s;
   291 	if (!url.isEmpty())
   292 		systemFlags->activate("url");
   293 	else	
   294 		systemFlags->deactivate("url");
   295 	calcBBoxSize();			// recalculate bbox
   296     positionBBox();			// rearrange contents
   297 	forceReposition();
   298 }
   299 
   300 QString OrnamentedObj::getURL()
   301 {
   302 	return url;
   303 }
   304 
   305 void OrnamentedObj::setVymLink(QString s)
   306 {
   307 	if (!s.isEmpty())
   308 	{
   309 		// We need the relative (from loading) 
   310 		// or absolute path (from User event)
   311 		// and build the absolute path.
   312 		// Note: If we have relative, use path of
   313 		// current map to build absolute path
   314 		QDir d(s);
   315 		if (!d.path().startsWith ("/"))
   316 		{
   317 			QString p=mapEditor->getDestPath();
   318 			int i=p.findRev("/",-1);
   319 			d.setPath(p.left(i)+"/"+s);
   320 			d.convertToAbs();
   321 		}
   322 		vymLink=d.path();
   323 		systemFlags->activate("vymLink");
   324 	}	
   325 	else	
   326 	{
   327 		systemFlags->deactivate("vymLink");
   328 		vymLink="";
   329 	}	
   330 	calcBBoxSize();			// recalculate bbox
   331     positionBBox();			// rearrange contents
   332 	forceReposition();
   333 }
   334 
   335 QString OrnamentedObj::getVymLink()
   336 {
   337 	return vymLink;
   338 }
   339 
   340 
   341 void OrnamentedObj::clearStandardFlags()
   342 {
   343 	standardFlags->deactivateAll();
   344 	calcBBoxSize();
   345 	positionBBox();
   346 	move (absPos.x(), absPos.y() );
   347 	forceReposition();
   348 }
   349 
   350 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   351 {
   352 	standardFlags->toggle(f,exclusive);
   353 	calcBBoxSize();
   354 	positionBBox();
   355 	move (absPos.x(), absPos.y() );
   356 	forceReposition();
   357 }
   358 
   359 void OrnamentedObj::activateStandardFlag(QString f)
   360 {
   361 	standardFlags->activate(f);
   362 	calcBBoxSize();
   363 	positionBBox();
   364 	move (absPos.x(), absPos.y() );
   365 	forceReposition();
   366 }
   367 
   368 void OrnamentedObj::deactivateStandardFlag(QString f)
   369 {
   370 	standardFlags->deactivate(f);
   371 	calcBBoxSize();
   372 	positionBBox();
   373 	move (absPos.x(), absPos.y() );
   374 	forceReposition();
   375 }
   376 
   377 bool OrnamentedObj::isSetStandardFlag (QString f)
   378 {
   379 	return standardFlags->isActive(f);
   380 }
   381 
   382 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
   383 {
   384 	return systemFlags->getFlagName(p);	
   385 }
   386 
   387 bool OrnamentedObj::isActiveFlag (const QString & fname)
   388 {
   389 	if (standardFlags->isActive (fname) ) return true;
   390 	return false;
   391 }
   392 
   393 void OrnamentedObj::getNoteFromTextEditor ()
   394 {
   395 	note.setFilenameHint (textEditor->getFilename());
   396 	note.setFontHint (textEditor->getFontHint() );
   397 	setNote( textEditor->getText() );
   398 }
   399 
   400 void OrnamentedObj::updateNoteFlag()
   401 {
   402 	bool noteEmpty;
   403 	if (isNoteInEditor)
   404 		noteEmpty=textEditor->isEmpty();
   405 	else	
   406 		noteEmpty=note.isEmpty();
   407 
   408 	if (!noteEmpty)
   409 	{	
   410 		if (systemFlags->isActive ("note")) return;
   411 		systemFlags->activate("note");
   412 	}	
   413 	else		
   414 	{	
   415 		if (!systemFlags->isActive ("note")) return;
   416 		systemFlags->deactivate("note");
   417 	}	
   418 	mapEditor->setChanged();
   419 	calcBBoxSize();
   420 	positionBBox();	
   421 	move (absPos.x(), absPos.y() );
   422 	forceReposition();
   423 	
   424 }	
   425 
   426 void OrnamentedObj::updateFlagsToolbar()
   427 {
   428 	standardFlags->updateToolbar();
   429 }
   430 
   431 void OrnamentedObj::setHideInExport(bool b)
   432 {
   433 	if (parObj)
   434 	{
   435 		// Don't allow to MapCenter to be hidden
   436 		hideExport=b;
   437 		if (b)
   438 			systemFlags->activate("hideInExport");
   439 		else	
   440 			systemFlags->deactivate("hideInExport");
   441 		calcBBoxSize();
   442 		positionBBox();
   443 		requestReposition();	
   444 	}
   445 }	
   446 
   447 bool OrnamentedObj::hideInExport()
   448 {
   449 	return hideExport;
   450 }	
   451 
   452 bool OrnamentedObj::isHidden()
   453 {
   454 	return hidden;
   455 }	
   456 
   457 QString OrnamentedObj::getOrnAttr()
   458 {
   459 	QString posAttr;
   460 
   461 	if (depth==0)
   462 		posAttr=		
   463 			attribut("absPosX",QString().setNum(absPos.x())) +
   464 			attribut("absPosY",QString().setNum(absPos.y())); 
   465 	else
   466 	{
   467 		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
   468 			posAttr=
   469 				attribut("relPosX",QString().setNum(relPos.x())) +
   470 				attribut("relPosY",QString().setNum(relPos.y())); 
   471 		else
   472 			posAttr="";
   473 	}	
   474 
   475 	QString urlAttr;
   476 	if (!url.isEmpty())
   477 		urlAttr=attribut ("url",url);
   478 
   479 	QString vymLinkAttr;
   480 	if (!vymLink.isEmpty())
   481 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   482 
   483 	QString hideExpAttr;
   484 	if (hideExport)
   485 		hideExpAttr= attribut("hideInExport","true");
   486 	else	
   487 		hideExpAttr="";
   488 
   489 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   490 }
   491