ornamentedobj.cpp
author insilmaril
Tue, 23 Jan 2007 11:50:53 +0000
changeset 422 07a2f3f31101
parent 417 1cc7bbf75f0b
child 442 dfbc371b7280
permissions -rw-r--r--
1.8.65 Various fixes
     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 }
    38 
    39 
    40 void OrnamentedObj::init ()
    41 {
    42 	heading = new HeadingObj(scene);
    43 	heading->move (absPos.x(), absPos.y());
    44 
    45 	note.setNote("");
    46 	note.setFontHint (textEditor->getFontHintDefault() );
    47 	isNoteInEditor=false;
    48 
    49 	systemFlags=new FlagRowObj(scene);
    50 	systemFlags->clone(systemFlagsDefault);
    51 	systemFlags->setName ("systemFlags");
    52 	
    53 	standardFlags=new FlagRowObj(scene);
    54 	standardFlags->clone(standardFlagsDefault);
    55 	standardFlags->setName ("standardFlags");
    56 
    57 	hideExport=false;
    58 	hidden=false;
    59 
    60 	url="";
    61 	vymLink="";
    62 	
    63 }
    64 
    65 void OrnamentedObj::copy (OrnamentedObj* other)
    66 {
    67     LinkableMapObj::copy(other);
    68 	heading->copy(other->heading);
    69     setColor   (other->heading->getColor());	
    70 
    71 	note.copy (other->note);
    72 	systemFlags->copy (other->systemFlags);
    73 	standardFlags->copy (other->standardFlags);
    74 
    75 	ornamentsBBox=other->ornamentsBBox;
    76 
    77 	hideExport=other->hideExport;
    78 	url=other->url;
    79 	vymLink=other->vymLink;
    80 }
    81 
    82 QString OrnamentedObj::getHeading()
    83 {
    84     return heading->text();
    85 }
    86 
    87 void OrnamentedObj::setLinkColor()
    88 {
    89 	if (mapEditor->getMapLinkColorHint()==HeadingColor)
    90 		LinkableMapObj::setLinkColor (heading->getColor());
    91 	else	
    92 		LinkableMapObj::setLinkColor (mapEditor->getMapDefLinkColor());
    93 }
    94 
    95 void OrnamentedObj::setColor (QColor col)
    96 {
    97     heading->setColor(col);
    98 	setLinkColor();
    99 }
   100 
   101 QColor OrnamentedObj::getColor ()
   102 {
   103     return heading->getColor();
   104 }
   105 
   106 
   107 void OrnamentedObj::positionContents()
   108 {
   109 	double d=frame->getBorder()/2;
   110 	double x=absPos.x();
   111 	double y=absPos.y();
   112 
   113 	double ox,oy;	// Offset due to padding
   114 
   115 	ox=leftPad + d;
   116 	oy=topPad + d;
   117 	
   118 	systemFlags-> move (ox +x , oy + y );
   119 
   120 	// vertical align heading to bottom
   121     heading->move (ox + x + systemFlags->getBBox().width(),
   122 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   123 					);
   124 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   125 
   126 	ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
   127 	clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
   128 }
   129 
   130 void OrnamentedObj::move (double x, double y)
   131 {
   132 	MapObj::move (x,y);
   133 	positionContents();
   134 	updateLink();
   135 	requestReposition();
   136 }
   137 
   138 void OrnamentedObj::move (QPointF p)
   139 {
   140 	move (p.x(), p.y());
   141 }	
   142 
   143 void OrnamentedObj::moveBy (double x, double y)
   144 {
   145 
   146 	MapObj::moveBy (x,y);
   147     frame->moveBy (x,y);
   148     systemFlags->moveBy (x,y);
   149     standardFlags->moveBy (x,y);
   150     heading->moveBy (x,y);
   151 	updateLink();
   152 	requestReposition();
   153 }
   154 
   155 void OrnamentedObj::moveBy (QPointF p)
   156 {
   157 	moveBy (p.x(), p.y());
   158 }	
   159 
   160 void OrnamentedObj::move2RelPos(double x, double y)
   161 {
   162 	setRelPos (QPointF((int)x,(int)y));
   163 	if (parObj)
   164 	{
   165 		QPointF p=parObj->getChildPos();
   166 		move (p.x()+x, p.y() +y);
   167 	}
   168 }
   169 
   170 void OrnamentedObj::move2RelPos(QPointF p)
   171 {
   172 	move2RelPos (p.x(),p.y());
   173 }
   174 
   175 void OrnamentedObj::setNote(QString s)
   176 {
   177 	note.setNote(s);
   178 	updateNoteFlag();
   179 }
   180 
   181 void OrnamentedObj::setNote(NoteObj n)
   182 {
   183 	note=n;
   184 	updateNoteFlag();
   185 }
   186 
   187 QString OrnamentedObj::getNote()
   188 {
   189     return note.getNote();
   190 }
   191 
   192 QString OrnamentedObj::getNoteASCII()
   193 {
   194     return note.getNoteASCII();
   195 }
   196 
   197 QString OrnamentedObj::getNoteOpenDoc()
   198 {
   199     return note.getNoteOpenDoc();
   200 }
   201 
   202 void OrnamentedObj::setURL(QString s)
   203 {
   204 	url=s;
   205 	if (!url.isEmpty())
   206 		systemFlags->activate("url");
   207 	else	
   208 		systemFlags->deactivate("url");
   209 	calcBBoxSize();			// recalculate bbox
   210     positionBBox();			// rearrange contents
   211 	forceReposition();
   212 }
   213 
   214 QString OrnamentedObj::getURL()
   215 {
   216 	return url;
   217 }
   218 
   219 void OrnamentedObj::setVymLink(QString s)
   220 {
   221 	if (!s.isEmpty())
   222 	{
   223 		// We need the relative (from loading) 
   224 		// or absolute path (from User event)
   225 		// and build the absolute path.
   226 		// Note: If we have relative, use path of
   227 		// current map to build absolute path
   228 		QDir d(s);
   229 		if (!d.path().startsWith ("/"))
   230 		{
   231 			QString p=mapEditor->getDestPath();
   232 			int i=p.findRev("/",-1);
   233 			d.setPath(p.left(i)+"/"+s);
   234 			d.convertToAbs();
   235 		}
   236 		vymLink=d.path();
   237 		systemFlags->activate("vymLink");
   238 	}	
   239 	else	
   240 	{
   241 		systemFlags->deactivate("vymLink");
   242 		vymLink="";
   243 	}	
   244 	calcBBoxSize();			// recalculate bbox
   245     positionBBox();			// rearrange contents
   246 	forceReposition();
   247 }
   248 
   249 QString OrnamentedObj::getVymLink()
   250 {
   251 	return vymLink;
   252 }
   253 
   254 
   255 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   256 {
   257 	standardFlags->toggle(f,exclusive);
   258 	calcBBoxSize();
   259 	positionBBox();
   260 	move (absPos.x(), absPos.y() );
   261 	forceReposition();
   262 }
   263 
   264 void OrnamentedObj::activateStandardFlag(QString f)
   265 {
   266 	standardFlags->activate(f);
   267 	calcBBoxSize();
   268 	positionBBox();
   269 	move (absPos.x(), absPos.y() );
   270 	forceReposition();
   271 }
   272 
   273 void OrnamentedObj::deactivateStandardFlag(QString f)
   274 {
   275 	standardFlags->deactivate(f);
   276 	calcBBoxSize();
   277 	positionBBox();
   278 	move (absPos.x(), absPos.y() );
   279 	forceReposition();
   280 }
   281 
   282 bool OrnamentedObj::isSetStandardFlag (QString f)
   283 {
   284 	return standardFlags->isActive(f);
   285 }
   286 
   287 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
   288 {
   289 	return systemFlags->getFlagName(p);	
   290 }
   291 
   292 bool OrnamentedObj::isActiveFlag (const QString & fname)
   293 {
   294 	if (standardFlags->isActive (fname) ) return true;
   295 	return false;
   296 }
   297 
   298 void OrnamentedObj::getNoteFromTextEditor ()
   299 {
   300 	note.setFilenameHint (textEditor->getFilename());
   301 	note.setFontHint (textEditor->getFontHint() );
   302 	setNote( textEditor->getText() );
   303 }
   304 
   305 void OrnamentedObj::updateNoteFlag()
   306 {
   307 	bool noteEmpty;
   308 	if (isNoteInEditor)
   309 		noteEmpty=textEditor->isEmpty();
   310 	else	
   311 		noteEmpty=note.isEmpty();
   312 
   313 	if (!noteEmpty)
   314 	{	
   315 		if (systemFlags->isActive ("note")) return;
   316 		systemFlags->activate("note");
   317 	}	
   318 	else		
   319 	{	
   320 		if (!systemFlags->isActive ("note")) return;
   321 		systemFlags->deactivate("note");
   322 	}	
   323 	mapEditor->setChanged();
   324 	calcBBoxSize();
   325 	positionBBox();	
   326 	move (absPos.x(), absPos.y() );
   327 	forceReposition();
   328 	
   329 }	
   330 
   331 void OrnamentedObj::updateFlagsToolbar()
   332 {
   333 	standardFlags->updateToolbar();
   334 }
   335 
   336 void OrnamentedObj::setHideInExport(bool b)
   337 {
   338 	if (parObj)
   339 	{
   340 		// Don't allow to MapCenter to be hidden
   341 		hideExport=b;
   342 		if (b)
   343 			systemFlags->activate("hideInExport");
   344 		else	
   345 			systemFlags->deactivate("hideInExport");
   346 		calcBBoxSize();
   347 		positionBBox();
   348 		requestReposition();	
   349 	}
   350 }	
   351 
   352 bool OrnamentedObj::hideInExport()
   353 {
   354 	return hideExport;
   355 }	
   356 
   357 bool OrnamentedObj::isHidden()
   358 {
   359 	return hidden;
   360 }	
   361 
   362 QString OrnamentedObj::getOrnAttr()
   363 {
   364 	QString posAttr;
   365 
   366 	if (depth==0)
   367 		posAttr=		
   368 			attribut("absPosX",QString().setNum(absPos.x())) +
   369 			attribut("absPosY",QString().setNum(absPos.y())); 
   370 	else
   371 	{
   372 		if (depth==1 || typeid (*this)==typeid (FloatImageObj))
   373 			posAttr=
   374 				attribut("relPosX",QString().setNum(relPos.x())) +
   375 				attribut("relPosY",QString().setNum(relPos.y())); 
   376 		else
   377 			posAttr="";
   378 	}	
   379 
   380 	QString urlAttr;
   381 	if (!url.isEmpty())
   382 		urlAttr=attribut ("url",url);
   383 
   384 	QString vymLinkAttr;
   385 	if (!vymLink.isEmpty())
   386 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   387 
   388 	QString hideExpAttr;
   389 	if (hideExport)
   390 		hideExpAttr= attribut("hideInExport","true");
   391 	else	
   392 		hideExpAttr="";
   393 
   394 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   395 }
   396