ornamentedobj.cpp
author insilmaril
Mon, 10 Apr 2006 11:21:35 +0000
changeset 286 70919791db67
parent 260 69d648a0a15b
child 296 692499ea76e1
permissions -rw-r--r--
switching to KDE icons
     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 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   286 {
   287 	return systemFlags->getFlagName(p);	
   288 }
   289 
   290 bool OrnamentedObj::isActiveFlag (const QString & fname)
   291 {
   292 	if (standardFlags->isActive (fname) ) return true;
   293 	return false;
   294 }
   295 
   296 void OrnamentedObj::updateNoteFlag()
   297 {
   298 	if (selected) 
   299 	{
   300 		// text in NoteEditor has changed, notify MapEditor 
   301 		mapEditor->setChanged();
   302 
   303 		// save text
   304 		setNote( textEditor->getText() );
   305 	
   306 		// save font   
   307 		note.setFontHint (textEditor->getFontHint() );
   308 	}	
   309 }
   310 
   311 void OrnamentedObj::setHideInExport(bool b)
   312 {
   313 	if (parObj)
   314 	{
   315 		// Don't allow to MapCenter to be hidden
   316 		hideExport=b;
   317 		if (b)
   318 			systemFlags->activate("hideInExport");
   319 		else	
   320 			systemFlags->deactivate("hideInExport");
   321 		calcBBoxSize();
   322 		positionBBox();
   323 		requestReposition();	
   324 	}
   325 }	
   326 
   327 bool OrnamentedObj::hideInExport()
   328 {
   329 	return hideExport;
   330 }	
   331 
   332 bool OrnamentedObj::isHidden()
   333 {
   334 	return hidden;
   335 }	
   336 
   337 QString OrnamentedObj::getOrnAttr()
   338 {
   339 	QString posAttr;
   340 
   341 	if (useRelPos)
   342 		posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
   343                 attribut("relPosY",QString().setNum(relPos.y(),10)); 
   344 	else
   345 	{
   346 		if (depth==0 || depth==1) posAttr=
   347 			attribut("absPosX",QString().setNum(absPos.x(),10)) +
   348 			attribut("absPosY",QString().setNum(absPos.y(),10)); 
   349 		else
   350 			posAttr="";
   351 	}	
   352 
   353 	QString urlAttr;
   354 	if (!url.isEmpty())
   355 		urlAttr=attribut ("url",url);
   356 
   357 	QString vymLinkAttr;
   358 	if (!vymLink.isEmpty())
   359 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   360 
   361 	QString hideExpAttr;
   362 	if (hideExport)
   363 		hideExpAttr= attribut("hideInExport","true");
   364 	else	
   365 		hideExpAttr="";
   366 
   367 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   368 }
   369