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);
65 void OrnamentedObj::copy (OrnamentedObj* other)
67 LinkableMapObj::copy(other);
68 heading->copy(other->heading);
69 setColor (other->heading->getColor());
71 systemFlags->copy (other->systemFlags);
72 standardFlags->copy (other->standardFlags);
74 ornamentsBBox=other->ornamentsBBox;
77 vymLink=other->vymLink;
80 void OrnamentedObj::setLinkColor()
82 if (model->getMapLinkColorHint()==HeadingColor)
83 LinkableMapObj::setLinkColor (heading->getColor());
85 LinkableMapObj::setLinkColor (model->getMapDefLinkColor());
88 void OrnamentedObj::setColor (QColor col)
90 heading->setColor(col);
94 QColor OrnamentedObj::getColor ()
96 return heading->getColor();
99 FrameObj::FrameType OrnamentedObj::getFrameType()
101 return frame->getFrameType();
104 QString OrnamentedObj::getFrameTypeName()
106 return frame->getFrameTypeName();
109 void OrnamentedObj::setFrameType(const FrameObj::FrameType &t)
111 frame->setFrameType(t);
112 if (t == FrameObj::NoFrame)
113 linkpos=LinkableMapObj::Bottom;
115 linkpos=LinkableMapObj::Middle;
122 void OrnamentedObj::setFrameType(const QString &t)
124 frame->setFrameType(t);
125 if (frame->getFrameType() == FrameObj::NoFrame)
126 linkpos=LinkableMapObj::Bottom;
128 linkpos=LinkableMapObj::Middle;
135 void OrnamentedObj::setFramePadding (const int &i)
137 frame->setPadding (i);
143 int OrnamentedObj::getFramePadding ()
145 return frame->getPadding();
148 void OrnamentedObj::setFrameBorderWidth (const int &i)
150 frame->setBorderWidth(i);
156 int OrnamentedObj::getFrameBorderWidth()
158 return frame->getBorderWidth();
161 void OrnamentedObj::setFramePenColor(QColor col)
163 frame->setPenColor (col);
166 QColor OrnamentedObj::getFramePenColor()
168 return frame->getPenColor ();
171 void OrnamentedObj::setFrameBrushColor(QColor col)
173 frame->setBrushColor (col);
176 QColor OrnamentedObj::getFrameBrushColor()
178 return frame->getBrushColor ();
181 void OrnamentedObj::positionContents()
183 double d=frame->getPadding()/2;
187 double ox,oy; // Offset due to padding
192 //FIXME-2 systemFlags-> move (ox +x , oy + y );
194 // vertical align heading to bottom
195 heading->move (ox + x + systemFlags->getBBox().width(),
196 oy + y + ornamentsBBox.height() - heading->getHeight()
198 //FIXME-2 standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
200 ornamentsBBox.moveTopLeft ( QPointF ((int)(ox+x),(int)(oy+y)));
201 clickBox.moveTopLeft (QPointF ((int)(ox + x), (int)(oy + y)));
204 void OrnamentedObj::move (double x, double y)
212 void OrnamentedObj::move (QPointF p)
217 void OrnamentedObj::moveBy (double x, double y)
220 MapObj::moveBy (x,y);
222 systemFlags->moveBy (x,y);
223 standardFlags->moveBy (x,y);
224 heading->moveBy (x,y);
229 void OrnamentedObj::moveBy (QPointF p)
231 moveBy (p.x(), p.y());
234 void OrnamentedObj::move2RelPos(double x, double y)
236 setRelPos (QPointF(x,y));
239 QPointF p=parObj->getChildPos();
240 move (p.x()+x, p.y() +y);
244 void OrnamentedObj::move2RelPos(QPointF p)
246 move2RelPos (p.x(),p.y());
249 void OrnamentedObj::setURL(QString s)
253 systemFlags->activate("url");
255 systemFlags->deactivate("url");
256 calcBBoxSize(); // recalculate bbox
257 positionBBox(); // rearrange contents
261 QString OrnamentedObj::getURL()
266 void OrnamentedObj::setVymLink(QString s)
270 // We need the relative (from loading)
271 // or absolute path (from User event)
272 // and build the absolute path.
273 // Note: If we have relative, use path of
274 // current map to build absolute path
276 if (!d.path().startsWith ("/"))
278 QString p=model->getDestPath();
279 int i=p.findRev("/",-1);
280 d.setPath(p.left(i)+"/"+s);
284 systemFlags->activate("vymLink");
288 systemFlags->deactivate("vymLink");
291 calcBBoxSize(); // recalculate bbox
292 positionBBox(); // rearrange contents
296 QString OrnamentedObj::getVymLink()
302 void OrnamentedObj::setAttributes (const QList <Attribute> &al)
307 QList <Attribute> OrnamentedObj::getAttributes()
312 void OrnamentedObj::clearStandardFlags()
314 standardFlags->deactivateAll();
317 move (absPos.x(), absPos.y() );
321 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
323 standardFlags->toggle(f,exclusive);
326 move (absPos.x(), absPos.y() );
330 void OrnamentedObj::activateStandardFlag(QString f)
332 standardFlags->activate(f);
335 move (absPos.x(), absPos.y() );
339 void OrnamentedObj::deactivateStandardFlag(QString f)
341 standardFlags->deactivate(f);
344 move (absPos.x(), absPos.y() );
348 bool OrnamentedObj::isSetStandardFlag (QString f)
350 return standardFlags->isActive(f);
353 QString OrnamentedObj::getSystemFlagName(const QPointF &p)
355 return systemFlags->getFlagName(p);
358 bool OrnamentedObj::isActiveFlag (const QString & fname)
360 if (standardFlags->isActive (fname) ) return true;
364 /* FIXME-3 should move to VymView ?! void OrnamentedObj::getNoteFromTextEditor ()
366 note.setFilenameHint (textEditor->getFilename());
367 note.setFontHint (textEditor->getFontHint() );
368 setNote( textEditor->getText() );
372 void OrnamentedObj::updateSystemFlags()
374 // FIXME-3 check if note here and text in editor are still in sync!!
375 // Best would be to always have current text here...
376 bool noteEmpty=treeItem->getNoteObj().isEmpty();
379 noteEmpty=textEditor->isEmpty();
381 noteEmpty=note.isEmpty();
386 if (systemFlags->isActive ("note")) return;
387 systemFlags->activate("note");
391 if (!systemFlags->isActive ("note")) return;
392 systemFlags->deactivate("note");
394 //model->setChanged();
397 move (absPos.x(), absPos.y() );
401 void OrnamentedObj::updateFlagsToolbar()
403 standardFlags->updateToolbar();
406 QString OrnamentedObj::getOrnXMLAttr()
410 if (treeItem->depth()==0)
412 attribut("absPosX",QString().setNum(absPos.x())) +
413 attribut("absPosY",QString().setNum(absPos.y()));
416 if (treeItem->depth()==1 || typeid (*this)==typeid (FloatImageObj))
418 if (relPos.x()==0 && relPos.y()==0)
421 attribut("relPosX",QString().setNum(relPos.x())) +
422 attribut("relPosY",QString().setNum(relPos.y()));
429 urlAttr=attribut ("url",url);
432 if (!vymLink.isEmpty())
433 vymLinkAttr=attribut ("vymLink",convertToRel(model->getDestPath(),vymLink) );
435 /* FIXME-2 QString hideExpAttr;
437 hideExpAttr= attribut("hideInExport","true");
441 return posAttr +urlAttr +vymLinkAttr +getLinkAttr() ;//+hideExpAttr;