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