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