ornamentedobj.cpp
author insilmaril
Thu, 08 Nov 2007 15:28:03 +0000
changeset 619 b48f072a347a
parent 613 8fb5b3956b3e
child 628 d7d0708b1c60
permissions -rw-r--r--
1.11.2 split up of xml helper functions. started to work on attributes
     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(const QString &indent, const int &width)
   279 {
   280     return note.getNoteASCII();
   281 }
   282 
   283 QString OrnamentedObj::getNoteASCII()
   284 {
   285     return note.getNoteASCII();
   286 }
   287 
   288 QString OrnamentedObj::getNoteOpenDoc()
   289 {
   290     return note.getNoteOpenDoc();
   291 }
   292 
   293 void OrnamentedObj::setURL(QString s)
   294 {
   295 	url=s;
   296 	if (!url.isEmpty())
   297 		systemFlags->activate("url");
   298 	else	
   299 		systemFlags->deactivate("url");
   300 	calcBBoxSize();			// recalculate bbox
   301     positionBBox();			// rearrange contents
   302 	forceReposition();
   303 }
   304 
   305 QString OrnamentedObj::getURL()
   306 {
   307 	return url;
   308 }
   309 
   310 void OrnamentedObj::setVymLink(QString s)
   311 {
   312 	if (!s.isEmpty())
   313 	{
   314 		// We need the relative (from loading) 
   315 		// or absolute path (from User event)
   316 		// and build the absolute path.
   317 		// Note: If we have relative, use path of
   318 		// current map to build absolute path
   319 		QDir d(s);
   320 		if (!d.path().startsWith ("/"))
   321 		{
   322 			QString p=mapEditor->getDestPath();
   323 			int i=p.findRev("/",-1);
   324 			d.setPath(p.left(i)+"/"+s);
   325 			d.convertToAbs();
   326 		}
   327 		vymLink=d.path();
   328 		systemFlags->activate("vymLink");
   329 	}	
   330 	else	
   331 	{
   332 		systemFlags->deactivate("vymLink");
   333 		vymLink="";
   334 	}	
   335 	calcBBoxSize();			// recalculate bbox
   336     positionBBox();			// rearrange contents
   337 	forceReposition();
   338 }
   339 
   340 QString OrnamentedObj::getVymLink()
   341 {
   342 	return vymLink;
   343 }
   344 
   345 
   346 void OrnamentedObj::clearStandardFlags()
   347 {
   348 	standardFlags->deactivateAll();
   349 	calcBBoxSize();
   350 	positionBBox();
   351 	move (absPos.x(), absPos.y() );
   352 	forceReposition();
   353 }
   354 
   355 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   356 {
   357 	standardFlags->toggle(f,exclusive);
   358 	calcBBoxSize();
   359 	positionBBox();
   360 	move (absPos.x(), absPos.y() );
   361 	forceReposition();
   362 }
   363 
   364 void OrnamentedObj::activateStandardFlag(QString f)
   365 {
   366 	standardFlags->activate(f);
   367 	calcBBoxSize();
   368 	positionBBox();
   369 	move (absPos.x(), absPos.y() );
   370 	forceReposition();
   371 }
   372 
   373 void OrnamentedObj::deactivateStandardFlag(QString f)
   374 {
   375 	standardFlags->deactivate(f);
   376 	calcBBoxSize();
   377 	positionBBox();
   378 	move (absPos.x(), absPos.y() );
   379 	forceReposition();
   380 }
   381 
   382 bool OrnamentedObj::isSetStandardFlag (QString f)
   383 {
   384 	return standardFlags->isActive(f);
   385 }
   386 
   387 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
   388 {
   389 	return systemFlags->getFlagName(p);	
   390 }
   391 
   392 bool OrnamentedObj::isActiveFlag (const QString & fname)
   393 {
   394 	if (standardFlags->isActive (fname) ) return true;
   395 	return false;
   396 }
   397 
   398 void OrnamentedObj::getNoteFromTextEditor ()
   399 {
   400 	note.setFilenameHint (textEditor->getFilename());
   401 	note.setFontHint (textEditor->getFontHint() );
   402 	setNote( textEditor->getText() );
   403 }
   404 
   405 void OrnamentedObj::updateNoteFlag()
   406 {
   407 	bool noteEmpty;
   408 	if (isNoteInEditor)
   409 		noteEmpty=textEditor->isEmpty();
   410 	else	
   411 		noteEmpty=note.isEmpty();
   412 
   413 	if (!noteEmpty)
   414 	{	
   415 		if (systemFlags->isActive ("note")) return;
   416 		systemFlags->activate("note");
   417 	}	
   418 	else		
   419 	{	
   420 		if (!systemFlags->isActive ("note")) return;
   421 		systemFlags->deactivate("note");
   422 	}	
   423 	mapEditor->setChanged();
   424 	calcBBoxSize();
   425 	positionBBox();	
   426 	move (absPos.x(), absPos.y() );
   427 	forceReposition();
   428 	
   429 }	
   430 
   431 void OrnamentedObj::updateFlagsToolbar()
   432 {
   433 	standardFlags->updateToolbar();
   434 }
   435 
   436 void OrnamentedObj::setHideInExport(bool b)
   437 {
   438 	if (parObj)
   439 	{
   440 		// Don't allow to MapCenter to be hidden
   441 		hideExport=b;
   442 		if (b)
   443 			systemFlags->activate("hideInExport");
   444 		else	
   445 			systemFlags->deactivate("hideInExport");
   446 		calcBBoxSize();
   447 		positionBBox();
   448 		requestReposition();	
   449 	}
   450 }	
   451 
   452 bool OrnamentedObj::hideInExport()
   453 {
   454 	return hideExport;
   455 }	
   456 
   457 bool OrnamentedObj::isHidden()
   458 {
   459 	return hidden;
   460 }	
   461 
   462 QString OrnamentedObj::getOrnAttr()
   463 {
   464 	QString posAttr;
   465 
   466 	if (depth==0)
   467 		posAttr=		
   468 			attribut("absPosX",QString().setNum(absPos.x())) +
   469 			attribut("absPosY",QString().setNum(absPos.y())); 
   470 	else
   471 	{
   472 		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
   473 			posAttr=
   474 				attribut("relPosX",QString().setNum(relPos.x())) +
   475 				attribut("relPosY",QString().setNum(relPos.y())); 
   476 		else
   477 			posAttr="";
   478 	}	
   479 
   480 	QString urlAttr;
   481 	if (!url.isEmpty())
   482 		urlAttr=attribut ("url",url);
   483 
   484 	QString vymLinkAttr;
   485 	if (!vymLink.isEmpty())
   486 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   487 
   488 	QString hideExpAttr;
   489 	if (hideExport)
   490 		hideExpAttr= attribut("hideInExport","true");
   491 	else	
   492 		hideExpAttr="";
   493 
   494 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   495 }
   496