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