ornamentedobj.cpp
author insilmaril
Thu Jun 01 11:19:57 2006 +0000 (2006-06-01)
changeset 343 f5c1cdf79e6e
parent 296 692499ea76e1
child 366 e95081c21da2
permissions -rw-r--r--
added warningdialog.ui
     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 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 (QPoint 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 (QPoint p)
   156 {
   157 	moveBy (p.x(), p.y());
   158 }	
   159 
   160 void OrnamentedObj::move2RelPos(double x, double y)
   161 {
   162 	if (!parObj) return;
   163 	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
   164 }
   165 
   166 void OrnamentedObj::move2RelPos(QPoint p)
   167 {
   168 	move2RelPos (p.x(),p.y());
   169 }
   170 
   171 void OrnamentedObj::setNote(QString s)
   172 {
   173 	note.setNote(s);
   174 	if (!note.isEmpty())
   175 		systemFlags->activate("note");
   176 	else		
   177 		systemFlags->deactivate("note");
   178 	calcBBoxSize();
   179 	positionBBox();	
   180 	move (absPos.x(), absPos.y() );
   181 	forceReposition();
   182 }
   183 
   184 void OrnamentedObj::setNote(NoteObj n)
   185 {
   186 	note=n;
   187 	if (!note.isEmpty())
   188 		systemFlags->activate("note");
   189 	else		
   190 		systemFlags->deactivate("note");
   191 	calcBBoxSize();
   192 	positionBBox();	
   193 	move (absPos.x(), absPos.y() );
   194 	forceReposition();
   195 	
   196 }
   197 
   198 QString OrnamentedObj::getNote()
   199 {
   200     return note.getNote();
   201 }
   202 
   203 QString OrnamentedObj::getNoteASCII()
   204 {
   205     return note.getNoteASCII();
   206 }
   207 
   208 QString OrnamentedObj::getNoteOpenDoc()
   209 {
   210     return note.getNoteOpenDoc();
   211 }
   212 
   213 void OrnamentedObj::setURL(QString s)
   214 {
   215 	url=s;
   216 	if (!url.isEmpty())
   217 		systemFlags->activate("url");
   218 	else	
   219 		systemFlags->deactivate("url");
   220 	calcBBoxSize();			// recalculate bbox
   221     positionBBox();			// rearrange contents
   222 	forceReposition();
   223 }
   224 
   225 QString OrnamentedObj::getURL()
   226 {
   227 	return url;
   228 }
   229 
   230 void OrnamentedObj::setVymLink(QString s)
   231 {
   232 	if (!s.isEmpty())
   233 	{
   234 		// We need the relative (from loading) 
   235 		// or absolute path (from User event)
   236 		// and build the absolute path.
   237 		// Note: If we have relative, use path of
   238 		// current map to build absolute path
   239 		QDir d(s);
   240 		if (!d.path().startsWith ("/"))
   241 		{
   242 			QString p=mapEditor->getDestPath();
   243 			int i=p.findRev("/",-1);
   244 			d.setPath(p.left(i)+"/"+s);
   245 			d.convertToAbs();
   246 		}
   247 		vymLink=d.path();
   248 		systemFlags->activate("vymLink");
   249 	}	
   250 	else	
   251 	{
   252 		systemFlags->deactivate("vymLink");
   253 		vymLink="";
   254 	}	
   255 	calcBBoxSize();			// recalculate bbox
   256     positionBBox();			// rearrange contents
   257 	forceReposition();
   258 }
   259 
   260 QString OrnamentedObj::getVymLink()
   261 {
   262 	return vymLink;
   263 }
   264 
   265 
   266 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   267 {
   268 	standardFlags->toggle(f,exclusive);
   269 	calcBBoxSize();
   270 	positionBBox();
   271 	move (absPos.x(), absPos.y() );
   272 	forceReposition();
   273 }
   274 
   275 void OrnamentedObj::activateStandardFlag(QString f)
   276 {
   277 	standardFlags->activate(f);
   278 	calcBBoxSize();
   279 	positionBBox();
   280 	move (absPos.x(), absPos.y() );
   281 	forceReposition();
   282 }
   283 
   284 bool OrnamentedObj::isSetStandardFlag (QString f)
   285 {
   286 	return standardFlags->isActive(f);
   287 }
   288 
   289 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   290 {
   291 	return systemFlags->getFlagName(p);	
   292 }
   293 
   294 bool OrnamentedObj::isActiveFlag (const QString & fname)
   295 {
   296 	if (standardFlags->isActive (fname) ) return true;
   297 	return false;
   298 }
   299 
   300 void OrnamentedObj::updateNoteFlag()
   301 {
   302 	if (selected) 
   303 	{
   304 		// text in NoteEditor has changed, notify MapEditor 
   305 		mapEditor->setChanged();
   306 
   307 		// save text
   308 		setNote( textEditor->getText() );
   309 	
   310 		// save font   
   311 		note.setFontHint (textEditor->getFontHint() );
   312 	}	
   313 }
   314 
   315 void OrnamentedObj::setHideInExport(bool b)
   316 {
   317 	if (parObj)
   318 	{
   319 		// Don't allow to MapCenter to be hidden
   320 		hideExport=b;
   321 		if (b)
   322 			systemFlags->activate("hideInExport");
   323 		else	
   324 			systemFlags->deactivate("hideInExport");
   325 		calcBBoxSize();
   326 		positionBBox();
   327 		requestReposition();	
   328 	}
   329 }	
   330 
   331 bool OrnamentedObj::hideInExport()
   332 {
   333 	return hideExport;
   334 }	
   335 
   336 bool OrnamentedObj::isHidden()
   337 {
   338 	return hidden;
   339 }	
   340 
   341 QString OrnamentedObj::getOrnAttr()
   342 {
   343 	QString posAttr;
   344 
   345 	if (useRelPos)
   346 		posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
   347                 attribut("relPosY",QString().setNum(relPos.y(),10)); 
   348 	else
   349 	{
   350 		if (depth==0 || depth==1) posAttr=
   351 			attribut("absPosX",QString().setNum(absPos.x(),10)) +
   352 			attribut("absPosY",QString().setNum(absPos.y(),10)); 
   353 		else
   354 			posAttr="";
   355 	}	
   356 
   357 	QString urlAttr;
   358 	if (!url.isEmpty())
   359 		urlAttr=attribut ("url",url);
   360 
   361 	QString vymLinkAttr;
   362 	if (!vymLink.isEmpty())
   363 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   364 
   365 	QString hideExpAttr;
   366 	if (hideExport)
   367 		hideExpAttr= attribut("hideInExport","true");
   368 	else	
   369 		hideExpAttr="";
   370 
   371 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   372 }
   373