ornamentedobj.cpp
author insilmaril
Mon, 08 May 2006 13:25:48 +0000
changeset 320 f83fa771061f
parent 296 692499ea76e1
child 336 5b6f2a396979
permissions -rw-r--r--
1.7.16 Small bugfixes
     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(QCanvas* c) :LinkableMapObj(c)
    22 {
    23 //    cout << "Const OrnamentedObj\n";
    24     init ();
    25 }
    26 
    27 OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->canvas)
    28 {
    29     copy (lmo);
    30 }
    31 
    32 OrnamentedObj::~OrnamentedObj()
    33 {
    34     delete (heading);
    35 	delete (systemFlags);
    36 	delete (standardFlags);
    37 
    38 }
    39 
    40 
    41 void OrnamentedObj::init ()
    42 {
    43 	heading = new HeadingObj(canvas);
    44 	heading->move (absPos.x(), absPos.y());
    45 
    46 	note.setNote("");
    47 	note.setFontHint (textEditor->getFontHintDefault() );
    48 
    49 	systemFlags=new FlagRowObj(canvas);
    50 	systemFlags->clone(systemFlagsDefault);
    51 	systemFlags->setName ("systemFlags");
    52 	
    53 	standardFlags=new FlagRowObj(canvas);
    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->getLinkColorHint()==HeadingColor)
    90 		LinkableMapObj::setLinkColor (heading->getColor());
    91 	else	
    92 		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    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 ( QPoint ((int)(ox+x),(int)(oy+y)));
   127 	clickBox.moveTopLeft (QPoint ((int)(ox + x), (int)(oy + y)));
   128 
   129 }
   130 
   131 void OrnamentedObj::move (double x, double y)
   132 {
   133 	MapObj::move (x,y);
   134 	positionContents();
   135 	updateLink();
   136 	requestReposition();
   137 }
   138 
   139 void OrnamentedObj::move (QPoint p)
   140 {
   141 	move (p.x(), p.y());
   142 }	
   143 
   144 void OrnamentedObj::moveBy (double x, double y)
   145 {
   146 
   147 	MapObj::moveBy (x,y);
   148     frame->moveBy (x,y);
   149     systemFlags->moveBy (x,y);
   150     standardFlags->moveBy (x,y);
   151     heading->moveBy (x,y);
   152 	updateLink();
   153 	requestReposition();
   154 }
   155 
   156 void OrnamentedObj::moveBy (QPoint p)
   157 {
   158 	moveBy (p.x(), p.y());
   159 }	
   160 
   161 void OrnamentedObj::move2RelPos(double x, double y)
   162 {
   163 	if (!parObj) return;
   164 	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
   165 }
   166 
   167 void OrnamentedObj::move2RelPos(QPoint p)
   168 {
   169 	move2RelPos (p.x(),p.y());
   170 }
   171 
   172 void OrnamentedObj::setNote(QString s)
   173 {
   174 	note.setNote(s);
   175 	if (!note.isEmpty())
   176 		systemFlags->activate("note");
   177 	else		
   178 		systemFlags->deactivate("note");
   179 	calcBBoxSize();
   180 	positionBBox();	
   181 	move (absPos.x(), absPos.y() );
   182 	forceReposition();
   183 }
   184 
   185 void OrnamentedObj::setNote(NoteObj n)
   186 {
   187 	note=n;
   188 	if (!note.isEmpty())
   189 		systemFlags->activate("note");
   190 	else		
   191 		systemFlags->deactivate("note");
   192 	calcBBoxSize();
   193 	positionBBox();	
   194 	move (absPos.x(), absPos.y() );
   195 	forceReposition();
   196 	
   197 }
   198 
   199 QString OrnamentedObj::getNote()
   200 {
   201     return note.getNote();
   202 }
   203 
   204 QString OrnamentedObj::getNoteASCII()
   205 {
   206     return note.getNoteASCII();
   207 }
   208 
   209 QString OrnamentedObj::getNoteOpenDoc()
   210 {
   211     return note.getNoteOpenDoc();
   212 }
   213 
   214 void OrnamentedObj::setURL(QString s)
   215 {
   216 	url=s;
   217 	if (!url.isEmpty())
   218 		systemFlags->activate("url");
   219 	else	
   220 		systemFlags->deactivate("url");
   221 	calcBBoxSize();			// recalculate bbox
   222     positionBBox();			// rearrange contents
   223 	forceReposition();
   224 }
   225 
   226 QString OrnamentedObj::getURL()
   227 {
   228 	return url;
   229 }
   230 
   231 void OrnamentedObj::setVymLink(QString s)
   232 {
   233 	if (!s.isEmpty())
   234 	{
   235 		// We need the relative (from loading) 
   236 		// or absolute path (from User event)
   237 		// and build the absolute path.
   238 		// Note: If we have relative, use path of
   239 		// current map to build absolute path
   240 		QDir d(s);
   241 		if (!d.path().startsWith ("/"))
   242 		{
   243 			QString p=mapEditor->getDestPath();
   244 			int i=p.findRev("/",-1);
   245 			d.setPath(p.left(i)+"/"+s);
   246 			d.convertToAbs();
   247 		}
   248 		vymLink=d.path();
   249 		systemFlags->activate("vymLink");
   250 	}	
   251 	else	
   252 	{
   253 		systemFlags->deactivate("vymLink");
   254 		vymLink="";
   255 	}	
   256 	calcBBoxSize();			// recalculate bbox
   257     positionBBox();			// rearrange contents
   258 	forceReposition();
   259 }
   260 
   261 QString OrnamentedObj::getVymLink()
   262 {
   263 	return vymLink;
   264 }
   265 
   266 
   267 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   268 {
   269 	standardFlags->toggle(f,exclusive);
   270 	calcBBoxSize();
   271 	positionBBox();
   272 	move (absPos.x(), absPos.y() );
   273 	forceReposition();
   274 }
   275 
   276 void OrnamentedObj::activateStandardFlag(QString f)
   277 {
   278 	standardFlags->activate(f);
   279 	calcBBoxSize();
   280 	positionBBox();
   281 	move (absPos.x(), absPos.y() );
   282 	forceReposition();
   283 }
   284 
   285 bool OrnamentedObj::isSetStandardFlag (QString f)
   286 {
   287 	return standardFlags->isActive(f);
   288 }
   289 
   290 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   291 {
   292 	return systemFlags->getFlagName(p);	
   293 }
   294 
   295 bool OrnamentedObj::isActiveFlag (const QString & fname)
   296 {
   297 	if (standardFlags->isActive (fname) ) return true;
   298 	return false;
   299 }
   300 
   301 void OrnamentedObj::updateNoteFlag()
   302 {
   303 	if (selected) 
   304 	{
   305 		// text in NoteEditor has changed, notify MapEditor 
   306 		mapEditor->setChanged();
   307 
   308 		// save text
   309 		setNote( textEditor->getText() );
   310 	
   311 		// save font   
   312 		note.setFontHint (textEditor->getFontHint() );
   313 	}	
   314 }
   315 
   316 void OrnamentedObj::setHideInExport(bool b)
   317 {
   318 	if (parObj)
   319 	{
   320 		// Don't allow to MapCenter to be hidden
   321 		hideExport=b;
   322 		if (b)
   323 			systemFlags->activate("hideInExport");
   324 		else	
   325 			systemFlags->deactivate("hideInExport");
   326 		calcBBoxSize();
   327 		positionBBox();
   328 		requestReposition();	
   329 	}
   330 }	
   331 
   332 bool OrnamentedObj::hideInExport()
   333 {
   334 	return hideExport;
   335 }	
   336 
   337 bool OrnamentedObj::isHidden()
   338 {
   339 	return hidden;
   340 }	
   341 
   342 QString OrnamentedObj::getOrnAttr()
   343 {
   344 	QString posAttr;
   345 
   346 	if (useRelPos)
   347 		posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
   348                 attribut("relPosY",QString().setNum(relPos.y(),10)); 
   349 	else
   350 	{
   351 		if (depth==0 || depth==1) posAttr=
   352 			attribut("absPosX",QString().setNum(absPos.x(),10)) +
   353 			attribut("absPosY",QString().setNum(absPos.y(),10)); 
   354 		else
   355 			posAttr="";
   356 	}	
   357 
   358 	QString urlAttr;
   359 	if (!url.isEmpty())
   360 		urlAttr=attribut ("url",url);
   361 
   362 	QString vymLinkAttr;
   363 	if (!vymLink.isEmpty())
   364 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   365 
   366 	QString hideExpAttr;
   367 	if (hideExport)
   368 		hideExpAttr= attribut("hideInExport","true");
   369 	else	
   370 		hideExpAttr="";
   371 
   372 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   373 }
   374