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