ornamentedobj.cpp
author insilmaril
Tue, 10 Apr 2007 13:22:55 +0000
changeset 449 5378ed53ec92
parent 447 72afe12da1c8
child 476 a551ed6005cc
permissions -rw-r--r--
1.8.71 Basic support for macros
     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 FrameType OrnamentedObj::getFrameType()
   110 {
   111 	return frame->getFrameType();
   112 }
   113 
   114 void OrnamentedObj::setFrameType(const FrameType &t)
   115 {
   116 	frame->setFrameType(t);
   117 	if (t == NoFrame)
   118 		linkpos=LinkBottom;
   119 	else	
   120 		linkpos=LinkMiddle;
   121 
   122 	calcBBoxSize();
   123 	positionBBox();
   124 	requestReposition();
   125 }
   126 
   127 void OrnamentedObj::setFrameType(const QString &t)
   128 {
   129 	frame->setFrameType(t);
   130 	if (frame->getFrameType() == NoFrame)
   131 		linkpos=LinkBottom;
   132 	else	
   133 		linkpos=LinkMiddle;
   134 
   135 	calcBBoxSize();
   136 	positionBBox();
   137 	requestReposition();
   138 }
   139 
   140 void OrnamentedObj::setFramePenColor(QColor col)
   141 {
   142 	frame->setPenColor (col);
   143 }
   144 
   145 QColor OrnamentedObj::getFramePenColor()
   146 {
   147 	return frame->getPenColor ();
   148 }
   149 
   150 void OrnamentedObj::setFrameBrushColor(QColor col)
   151 {
   152 	frame->setBrushColor (col);
   153 }
   154 
   155 QColor OrnamentedObj::getFrameBrushColor()
   156 {
   157 	return frame->getBrushColor ();
   158 }
   159 
   160 void OrnamentedObj::positionContents()
   161 {
   162 	double d=frame->getBorder()/2;
   163 	double x=absPos.x();
   164 	double y=absPos.y();
   165 
   166 	double ox,oy;	// Offset due to padding
   167 
   168 	ox=leftPad + d;
   169 	oy=topPad + d;
   170 	
   171 	systemFlags-> move (ox +x , oy + y );
   172 
   173 	// vertical align heading to bottom
   174     heading->move (ox + x + systemFlags->getBBox().width(),
   175 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   176 					);
   177 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   178 
   179 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   180 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   181 }
   182 
   183 void OrnamentedObj::move (double x, double y)
   184 {
   185 	MapObj::move (x,y);
   186 	positionContents();
   187 	updateLink();
   188 	requestReposition();
   189 }
   190 
   191 void OrnamentedObj::move (QPointF p)
   192 {
   193 	move (p.x(), p.y());
   194 }	
   195 
   196 void OrnamentedObj::moveBy (double x, double y)
   197 {
   198 
   199 	MapObj::moveBy (x,y);
   200     frame->moveBy (x,y);
   201     systemFlags->moveBy (x,y);
   202     standardFlags->moveBy (x,y);
   203     heading->moveBy (x,y);
   204 	updateLink();
   205 	requestReposition();
   206 }
   207 
   208 void OrnamentedObj::moveBy (QPointF p)
   209 {
   210 	moveBy (p.x(), p.y());
   211 }	
   212 
   213 void OrnamentedObj::move2RelPos(double x, double y)
   214 {
   215 	setRelPos (QPointF((int)x,(int)y));
   216 	if (parObj)
   217 	{
   218 		QPointF p=parObj->getChildPos();
   219 		move (p.x()+x, p.y() +y);
   220 	}
   221 }
   222 
   223 void OrnamentedObj::move2RelPos(QPointF p)
   224 {
   225 	move2RelPos (p.x(),p.y());
   226 }
   227 
   228 void OrnamentedObj::setNote(QString s)
   229 {
   230 	note.setNote(s);
   231 	updateNoteFlag();
   232 }
   233 
   234 void OrnamentedObj::setNote(NoteObj n)
   235 {
   236 	note=n;
   237 	updateNoteFlag();
   238 }
   239 
   240 QString OrnamentedObj::getNote()
   241 {
   242     return note.getNote();
   243 }
   244 
   245 QString OrnamentedObj::getNoteASCII()
   246 {
   247     return note.getNoteASCII();
   248 }
   249 
   250 QString OrnamentedObj::getNoteOpenDoc()
   251 {
   252     return note.getNoteOpenDoc();
   253 }
   254 
   255 void OrnamentedObj::setURL(QString s)
   256 {
   257 	url=s;
   258 	if (!url.isEmpty())
   259 		systemFlags->activate("url");
   260 	else	
   261 		systemFlags->deactivate("url");
   262 	calcBBoxSize();			// recalculate bbox
   263     positionBBox();			// rearrange contents
   264 	forceReposition();
   265 }
   266 
   267 QString OrnamentedObj::getURL()
   268 {
   269 	return url;
   270 }
   271 
   272 void OrnamentedObj::setVymLink(QString s)
   273 {
   274 	if (!s.isEmpty())
   275 	{
   276 		// We need the relative (from loading) 
   277 		// or absolute path (from User event)
   278 		// and build the absolute path.
   279 		// Note: If we have relative, use path of
   280 		// current map to build absolute path
   281 		QDir d(s);
   282 		if (!d.path().startsWith ("/"))
   283 		{
   284 			QString p=mapEditor->getDestPath();
   285 			int i=p.findRev("/",-1);
   286 			d.setPath(p.left(i)+"/"+s);
   287 			d.convertToAbs();
   288 		}
   289 		vymLink=d.path();
   290 		systemFlags->activate("vymLink");
   291 	}	
   292 	else	
   293 	{
   294 		systemFlags->deactivate("vymLink");
   295 		vymLink="";
   296 	}	
   297 	calcBBoxSize();			// recalculate bbox
   298     positionBBox();			// rearrange contents
   299 	forceReposition();
   300 }
   301 
   302 QString OrnamentedObj::getVymLink()
   303 {
   304 	return vymLink;
   305 }
   306 
   307 
   308 void OrnamentedObj::clearStandardFlags()
   309 {
   310 	standardFlags->deactivateAll();
   311 	calcBBoxSize();
   312 	positionBBox();
   313 	move (absPos.x(), absPos.y() );
   314 	forceReposition();
   315 }
   316 
   317 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   318 {
   319 	standardFlags->toggle(f,exclusive);
   320 	calcBBoxSize();
   321 	positionBBox();
   322 	move (absPos.x(), absPos.y() );
   323 	forceReposition();
   324 }
   325 
   326 void OrnamentedObj::activateStandardFlag(QString f)
   327 {
   328 	standardFlags->activate(f);
   329 	calcBBoxSize();
   330 	positionBBox();
   331 	move (absPos.x(), absPos.y() );
   332 	forceReposition();
   333 }
   334 
   335 void OrnamentedObj::deactivateStandardFlag(QString f)
   336 {
   337 	standardFlags->deactivate(f);
   338 	calcBBoxSize();
   339 	positionBBox();
   340 	move (absPos.x(), absPos.y() );
   341 	forceReposition();
   342 }
   343 
   344 bool OrnamentedObj::isSetStandardFlag (QString f)
   345 {
   346 	return standardFlags->isActive(f);
   347 }
   348 
   349 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
   350 {
   351 	return systemFlags->getFlagName(p);	
   352 }
   353 
   354 bool OrnamentedObj::isActiveFlag (const QString & fname)
   355 {
   356 	if (standardFlags->isActive (fname) ) return true;
   357 	return false;
   358 }
   359 
   360 void OrnamentedObj::getNoteFromTextEditor ()
   361 {
   362 	note.setFilenameHint (textEditor->getFilename());
   363 	note.setFontHint (textEditor->getFontHint() );
   364 	setNote( textEditor->getText() );
   365 }
   366 
   367 void OrnamentedObj::updateNoteFlag()
   368 {
   369 	bool noteEmpty;
   370 	if (isNoteInEditor)
   371 		noteEmpty=textEditor->isEmpty();
   372 	else	
   373 		noteEmpty=note.isEmpty();
   374 
   375 	if (!noteEmpty)
   376 	{	
   377 		if (systemFlags->isActive ("note")) return;
   378 		systemFlags->activate("note");
   379 	}	
   380 	else		
   381 	{	
   382 		if (!systemFlags->isActive ("note")) return;
   383 		systemFlags->deactivate("note");
   384 	}	
   385 	mapEditor->setChanged();
   386 	calcBBoxSize();
   387 	positionBBox();	
   388 	move (absPos.x(), absPos.y() );
   389 	forceReposition();
   390 	
   391 }	
   392 
   393 void OrnamentedObj::updateFlagsToolbar()
   394 {
   395 	standardFlags->updateToolbar();
   396 }
   397 
   398 void OrnamentedObj::setHideInExport(bool b)
   399 {
   400 	if (parObj)
   401 	{
   402 		// Don't allow to MapCenter to be hidden
   403 		hideExport=b;
   404 		if (b)
   405 			systemFlags->activate("hideInExport");
   406 		else	
   407 			systemFlags->deactivate("hideInExport");
   408 		calcBBoxSize();
   409 		positionBBox();
   410 		requestReposition();	
   411 	}
   412 }	
   413 
   414 bool OrnamentedObj::hideInExport()
   415 {
   416 	return hideExport;
   417 }	
   418 
   419 bool OrnamentedObj::isHidden()
   420 {
   421 	return hidden;
   422 }	
   423 
   424 QString OrnamentedObj::getOrnAttr()
   425 {
   426 	QString posAttr;
   427 
   428 	if (depth==0)
   429 		posAttr=		
   430 			attribut("absPosX",QString().setNum(absPos.x())) +
   431 			attribut("absPosY",QString().setNum(absPos.y())); 
   432 	else
   433 	{
   434 		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
   435 			posAttr=
   436 				attribut("relPosX",QString().setNum(relPos.x())) +
   437 				attribut("relPosY",QString().setNum(relPos.y())); 
   438 		else
   439 			posAttr="";
   440 	}	
   441 
   442 	QString urlAttr;
   443 	if (!url.isEmpty())
   444 		urlAttr=attribut ("url",url);
   445 
   446 	QString vymLinkAttr;
   447 	if (!vymLink.isEmpty())
   448 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   449 
   450 	QString hideExpAttr;
   451 	if (hideExport)
   452 		hideExpAttr= attribut("hideInExport","true");
   453 	else	
   454 		hideExpAttr="";
   455 
   456 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   457 }
   458