ornamentedobj.cpp
author insilmaril
Wed, 15 Mar 2006 13:53:53 +0000
changeset 248 30a4b721cffd
parent 243 fad762341d2d
child 252 f9ed11f2ab60
permissions -rw-r--r--
hide export for floatimages.
     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 
    59 	url="";
    60 	vymLink="";
    61 	
    62 }
    63 
    64 void OrnamentedObj::copy (OrnamentedObj* other)
    65 {
    66     LinkableMapObj::copy(other);
    67 	heading->copy(other->heading);
    68     setColor   (other->heading->getColor());	
    69 
    70 	note.copy (other->note);
    71 	systemFlags->copy (other->systemFlags);
    72 	standardFlags->copy (other->standardFlags);
    73 
    74 	ornamentsBBox=other->ornamentsBBox;
    75 
    76 	hideExport=other->hideExport;
    77 	url=other->url;
    78 	vymLink=other->vymLink;
    79 }
    80 
    81 QString OrnamentedObj::getHeading()
    82 {
    83     return heading->text();
    84 }
    85 
    86 void OrnamentedObj::setLinkColor()
    87 {
    88 	if (mapEditor->getLinkColorHint()==HeadingColor)
    89 		LinkableMapObj::setLinkColor (heading->getColor());
    90 	else	
    91 		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    92 }
    93 
    94 void OrnamentedObj::setColor (QColor col)
    95 {
    96     heading->setColor(col);
    97 	setLinkColor();
    98 }
    99 
   100 QColor OrnamentedObj::getColor ()
   101 {
   102     return heading->getColor();
   103 }
   104 
   105 
   106 void OrnamentedObj::positionContents()
   107 {
   108 	double d=frame->getBorder()/2;
   109 	double x=absPos.x();
   110 	double y=absPos.y();
   111 
   112 	double ox,oy;	// Offset due to padding
   113 
   114 	ox=leftPad + d;
   115 	oy=topPad + d;
   116 	
   117 	systemFlags-> move (ox +x , oy + y );
   118 
   119 	// vertical align heading to bottom
   120     heading->move (ox + x + systemFlags->getBBox().width(),
   121 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   122 					);
   123 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   124 
   125 	ornamentsBBox.moveTopLeft ( QPoint ((int)(ox+x),(int)(oy+y)));
   126 	clickBox.moveTopLeft (QPoint ((int)(ox + x), (int)(oy + y)));
   127 
   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 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   285 {
   286 	return systemFlags->getFlagName(p);	
   287 }
   288 
   289 bool OrnamentedObj::isActiveFlag (const QString & fname)
   290 {
   291 	if (standardFlags->isActive (fname) ) return true;
   292 	return false;
   293 }
   294 
   295 void OrnamentedObj::updateNoteFlag()
   296 {
   297 	if (selected) 
   298 	{
   299 		// text in NoteEditor has changed, notify MapEditor 
   300 		mapEditor->setChanged();
   301 
   302 		// save text
   303 		setNote( textEditor->getText() );
   304 	
   305 		// save font   
   306 		note.setFontHint (textEditor->getFontHint() );
   307 	}	
   308 }
   309 
   310 void OrnamentedObj::setHideInExport(bool b)
   311 {
   312 	hideExport=b;
   313 	if (b)
   314 		systemFlags->activate("hideInExport");
   315 	else	
   316 		systemFlags->deactivate("hideInExport");
   317 	calcBBoxSize();
   318 	positionBBox();
   319 	requestReposition();	
   320 }	
   321 
   322 bool OrnamentedObj::hideInExport()
   323 {
   324 	return hideExport;
   325 }	
   326 
   327 QString OrnamentedObj::getOrnAttr()
   328 {
   329 	QString posAttr;
   330 	if (depth==0 || depth==1) posAttr=
   331 		attribut("absPosX",QString().setNum(absPos.x(),10)) +
   332 		attribut("absPosY",QString().setNum(absPos.y(),10)); 
   333 	else
   334 		posAttr="";
   335 
   336 	QString urlAttr;
   337 	if (!url.isEmpty())
   338 		urlAttr=attribut ("url",url);
   339 
   340 	QString vymLinkAttr;
   341 	if (!vymLink.isEmpty())
   342 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   343 
   344 	QString hideExpAttr;
   345 	if (hideExport)
   346 		hideExpAttr= attribut("hideInExport","true");
   347 	else	
   348 		hideExpAttr="";
   349 
   350 	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   351 }
   352