ornamentedobj.cpp
author insilmaril
Wed, 30 Aug 2006 12:16:25 +0000
branchqt4-port
changeset 17 557239819c45
parent 16 41c3d7f9f532
child 18 70c41284cb48
permissions -rw-r--r--
Fixed editing of headings. Undo debug output still enabled
     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 	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 void OrnamentedObj::deactivateStandardFlag(QString f)
   285 {
   286 	standardFlags->deactivate(f);
   287 	calcBBoxSize();
   288 	positionBBox();
   289 	move (absPos.x(), absPos.y() );
   290 	forceReposition();
   291 }
   292 
   293 bool OrnamentedObj::isSetStandardFlag (QString f)
   294 {
   295 	return standardFlags->isActive(f);
   296 }
   297 
   298 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   299 {
   300 	return systemFlags->getFlagName(p);	
   301 }
   302 
   303 bool OrnamentedObj::isActiveFlag (const QString & fname)
   304 {
   305 	if (standardFlags->isActive (fname) ) return true;
   306 	return false;
   307 }
   308 
   309 void OrnamentedObj::updateNoteFlag()
   310 {
   311 	if (selected) 
   312 	{
   313 		// text in NoteEditor has changed, notify MapEditor 
   314 		mapEditor->setChanged();
   315 
   316 		// save text
   317 		setNote( textEditor->getText() );
   318 	
   319 		// save font   
   320 		note.setFontHint (textEditor->getFontHint() );
   321 	}	
   322 }
   323 
   324 void OrnamentedObj::setHideInExport(bool b)
   325 {
   326 	if (parObj)
   327 	{
   328 		// Don't allow to MapCenter to be hidden
   329 		hideExport=b;
   330 		if (b)
   331 			systemFlags->activate("hideInExport");
   332 		else	
   333 			systemFlags->deactivate("hideInExport");
   334 		calcBBoxSize();
   335 		positionBBox();
   336 		requestReposition();	
   337 	}
   338 }	
   339 
   340 bool OrnamentedObj::hideInExport()
   341 {
   342 	return hideExport;
   343 }	
   344 
   345 bool OrnamentedObj::isHidden()
   346 {
   347 	return hidden;
   348 }	
   349 
   350 QString OrnamentedObj::getOrnAttr()
   351 {
   352 	QString posAttr;
   353 
   354 	if (useRelPos)
   355 		posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
   356                 attribut("relPosY",QString().setNum(relPos.y(),10)); 
   357 	else
   358 	{
   359 		if (depth==0 || depth==1) posAttr=
   360 			attribut("absPosX",QString().setNum(absPos.x(),10)) +
   361 			attribut("absPosY",QString().setNum(absPos.y(),10)); 
   362 		else
   363 			posAttr="";
   364 	}	
   365 
   366 	QString urlAttr;
   367 	if (!url.isEmpty())
   368 		urlAttr=attribut ("url",url);
   369 
   370 	QString vymLinkAttr;
   371 	if (!vymLink.isEmpty())
   372 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   373 
   374 	QString hideExpAttr;
   375 	if (hideExport)
   376 		hideExpAttr= attribut("hideInExport","true");
   377 	else	
   378 		hideExpAttr="";
   379 
   380 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   381 }
   382