3 #include "ornamentedobj.h"
4 #include "texteditor.h"
6 #include "linkablemapobj.h"
8 extern TextEditor *textEditor;
9 extern FlagRowObj *systemFlagsDefault;
10 extern FlagRowObj *standardFlagsDefault;
13 /////////////////////////////////////////////////////////////////
15 /////////////////////////////////////////////////////////////////
17 OrnamentedObj::OrnamentedObj():LinkableMapObj()
19 // cout << "Const OrnamentedObj ()\n";
23 OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
25 // cout << "Const OrnamentedObj (s)\n";
29 OrnamentedObj::OrnamentedObj (OrnamentedObj* lmo) : LinkableMapObj (lmo->scene)
34 OrnamentedObj::~OrnamentedObj()
43 void OrnamentedObj::init ()
45 heading = new HeadingObj(scene);
46 heading->move (absPos.x(), absPos.y());
48 systemFlags=new FlagRowObj(scene);
49 systemFlags->clone(systemFlagsDefault);
50 systemFlags->setName ("systemFlags");
52 standardFlags=new FlagRowObj(scene);
53 standardFlags->clone(standardFlagsDefault);
54 standardFlags->setName ("standardFlags");
58 frame = new FrameObj (scene);
68 void OrnamentedObj::copy (OrnamentedObj* other)
70 LinkableMapObj::copy(other);
71 heading->copy(other->heading);
72 setColor (other->heading->getColor());
74 systemFlags->copy (other->systemFlags);
75 standardFlags->copy (other->standardFlags);
77 ornamentsBBox=other->ornamentsBBox;
79 hideExport=other->hideExport;
81 vymLink=other->vymLink;
84 QString OrnamentedObj::getHeading()
86 return heading->text();
89 void OrnamentedObj::setLinkColor()
91 if (model->getMapLinkColorHint()==HeadingColor)
92 LinkableMapObj::setLinkColor (heading->getColor());
94 LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
97 void OrnamentedObj::setColor (QColor col)
99 heading->setColor(col);
103 QColor OrnamentedObj::getColor ()
105 return heading->getColor();
108 FrameObj::FrameType OrnamentedObj::getFrameType()
110 return frame->getFrameType();
113 QString OrnamentedObj::getFrameTypeName()
115 return frame->getFrameTypeName();
118 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
120 frame->setFrameType(t);
121 if (t == FrameObj::NoFrame)
122 linkpos=LinkableMapObj::Bottom;
124 linkpos=LinkableMapObj::Middle;
131 void OrnamentedObj::setFrameType(const QString &t)
133 frame->setFrameType(t);
134 if (frame->getFrameType() == FrameObj::NoFrame)
135 linkpos=LinkableMapObj::Bottom;
137 linkpos=LinkableMapObj::Middle;
144 void OrnamentedObj::setFramePadding (const int &i)
146 frame->setPadding (i);
152 int OrnamentedObj::getFramePadding ()
154 return frame->getPadding();
157 void OrnamentedObj::setFrameBorderWidth (const int &i)
159 frame->setBorderWidth(i);
165 int OrnamentedObj::getFrameBorderWidth()
167 return frame->getBorderWidth();
170 void OrnamentedObj::setFramePenColor(QColor col)
172 frame->setPenColor (col);
175 QColor OrnamentedObj::getFramePenColor()
177 return frame->getPenColor ();
180 void OrnamentedObj::setFrameBrushColor(QColor col)
182 frame->setBrushColor (col);
185 QColor OrnamentedObj::getFrameBrushColor()
187 return frame->getBrushColor ();
190 void OrnamentedObj::positionContents()
192 double d=frame->getPadding()/2;
196 double ox,oy; // Offset due to padding
201 systemFlags-> move (ox +x , oy + y );
203 // vertical align heading to bottom
204 heading->move (ox + x + systemFlags->getBBox().width(),
205 oy + y + ornamentsBBox.height() - heading->getHeight()
207 standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
209 ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
210 clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
213 void OrnamentedObj::move (double x, double y)
221 void OrnamentedObj::move (QPointF p)
226 void OrnamentedObj::moveBy (double x, double y)
229 MapObj::moveBy (x,y);
231 systemFlags->moveBy (x,y);
232 standardFlags->moveBy (x,y);
233 heading->moveBy (x,y);
238 void OrnamentedObj::moveBy (QPointF p)
240 moveBy (p.x(), p.y());
243 void OrnamentedObj::move2RelPos(double x, double y)
245 setRelPos (QPointF(x,y));
248 QPointF p=parObj->getChildPos();
249 move (p.x()+x, p.y() +y);
253 void OrnamentedObj::move2RelPos(QPointF p)
255 move2RelPos (p.x(),p.y());
258 void OrnamentedObj::setURL(QString s)
262 systemFlags->activate("url");
264 systemFlags->deactivate("url");
265 calcBBoxSize(); // recalculate bbox
266 positionBBox(); // rearrange contents
270 QString OrnamentedObj::getURL()
275 void OrnamentedObj::setVymLink(QString s)
279 // We need the relative (from loading)
280 // or absolute path (from User event)
281 // and build the absolute path.
282 // Note: If we have relative, use path of
283 // current map to build absolute path
285 if (!d.path().startsWith ("/"))
287 QString p=model->getDestPath();
288 int i=p.findRev("/",-1);
289 d.setPath(p.left(i)+"/"+s);
293 systemFlags->activate("vymLink");
297 systemFlags->deactivate("vymLink");
300 calcBBoxSize(); // recalculate bbox
301 positionBBox(); // rearrange contents
305 QString OrnamentedObj::getVymLink()
311 void OrnamentedObj::setAttributes (const QList <Attribute> &al)
316 QList <Attribute> OrnamentedObj::getAttributes()
321 void OrnamentedObj::clearStandardFlags()
323 standardFlags->deactivateAll();
326 move (absPos.x(), absPos.y() );
330 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
332 standardFlags->toggle(f,exclusive);
335 move (absPos.x(), absPos.y() );
339 void OrnamentedObj::activateStandardFlag(QString f)
341 standardFlags->activate(f);
344 move (absPos.x(), absPos.y() );
348 void OrnamentedObj::deactivateStandardFlag(QString f)
350 standardFlags->deactivate(f);
353 move (absPos.x(), absPos.y() );
357 bool OrnamentedObj::isSetStandardFlag (QString f)
359 return standardFlags->isActive(f);
362 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
364 return systemFlags->getFlagName(p);
367 bool OrnamentedObj::isActiveFlag (const QString & fname)
369 if (standardFlags->isActive (fname) ) return true;
373 /* FIXME-3 should move to VymView ?! void OrnamentedObj::getNoteFromTextEditor ()
375 note.setFilenameHint (textEditor->getFilename());
376 note.setFontHint (textEditor->getFontHint() );
377 setNote( textEditor->getText() );
381 void OrnamentedObj::updateSystemFlags()
383 // FIXME-3 check if note here and text in editor are still in sync!!
384 // Best would be to always have current text here...
385 bool noteEmpty=treeItem->getNoteObj().isEmpty();
388 noteEmpty=textEditor->isEmpty();
390 noteEmpty=note.isEmpty();
395 if (systemFlags->isActive ("note")) return;
396 systemFlags->activate("note");
400 if (!systemFlags->isActive ("note")) return;
401 systemFlags->deactivate("note");
403 //model->setChanged();
406 move (absPos.x(), absPos.y() );
410 void OrnamentedObj::updateFlagsToolbar()
412 standardFlags->updateToolbar();
415 void OrnamentedObj::setHideInExport(bool b)
419 // Don't allow to MapCenter to be hidden
422 systemFlags->activate("hideInExport");
424 systemFlags->deactivate("hideInExport");
431 bool OrnamentedObj::hideInExport()
436 bool OrnamentedObj::isHidden()
441 QString OrnamentedObj::getOrnXMLAttr()
447 attribut("absPosX",QString().setNum(absPos.x())) +
448 attribut("absPosY",QString().setNum(absPos.y()));
451 if (depth==1 || typeid (*this)==typeid (FloatImageObj))
453 if (relPos.x()==0 && relPos.y()==0)
456 attribut("relPosX",QString().setNum(relPos.x())) +
457 attribut("relPosY",QString().setNum(relPos.y()));
464 urlAttr=attribut ("url",url);
467 if (!vymLink.isEmpty())
468 vymLinkAttr=attribut ("vymLink",convertToRel(model->getDestPath(),vymLink) );
472 hideExpAttr= attribut("hideInExport","true");
476 return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;