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