ornamentedobj.cpp
author insilmaril
Tue Mar 14 14:27:04 2006 +0000 (2006-03-14)
changeset 240 bcfd5aad58d6
parent 227 38ad83f1d4ce
child 243 fad762341d2d
permissions -rw-r--r--
hideLinkInExport for Branches (Floats still missing). Floats are now OrnamentedObj.
     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 
    58 void OrnamentedObj::copy (OrnamentedObj* other)
    59 {
    60     LinkableMapObj::copy(other);
    61 	heading->copy(other->heading);
    62     setColor   (other->heading->getColor(),false);	
    63 
    64 	note.copy (other->note);
    65 	systemFlags->copy (other->systemFlags);
    66 	standardFlags->copy (other->standardFlags);
    67 
    68 	ornamentsBBox=other->ornamentsBBox;
    69 
    70 }
    71 
    72 QString OrnamentedObj::getHeading()
    73 {
    74     return heading->text();
    75 }
    76 
    77 void OrnamentedObj::setLinkColor()
    78 {
    79 	if (mapEditor->getLinkColorHint()==HeadingColor)
    80 		LinkableMapObj::setLinkColor (heading->getColor());
    81 	else	
    82 		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    83 }
    84 
    85 QColor OrnamentedObj::getColor ()
    86 {
    87     return heading->getColor();
    88 }
    89 
    90 
    91 void OrnamentedObj::positionContents()
    92 {
    93 	double d=frame->getBorder()/2;
    94 	double x=absPos.x();
    95 	double y=absPos.y();
    96 
    97 	double ox,oy;	// Offset due to padding
    98 
    99 	ox=leftPad + d;
   100 	oy=topPad + d;
   101 	
   102 	systemFlags-> move (ox +x , oy + y );
   103 
   104 	// vertical align heading to bottom
   105     heading->move (ox + x + systemFlags->getBBox().width(),
   106 				   oy + y + ornamentsBBox.height() - heading->getHeight() 
   107 					);
   108 	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
   109 
   110 	ornamentsBBox.moveTopLeft ( QPoint ((int)(ox+x),(int)(oy+y)));
   111 	clickBox.moveTopLeft (QPoint ((int)(ox + x), (int)(oy + y)));
   112 
   113 }
   114 
   115 void OrnamentedObj::move (double x, double y)
   116 {
   117 	MapObj::move (x,y);
   118 	positionContents();
   119 	updateLink();
   120 	requestReposition();
   121 }
   122 
   123 void OrnamentedObj::move (QPoint p)
   124 {
   125 	move (p.x(), p.y());
   126 }	
   127 
   128 void OrnamentedObj::moveBy (double x, double y)
   129 {
   130 
   131 	MapObj::moveBy (x,y);
   132     frame->moveBy (x,y);
   133     systemFlags->moveBy (x,y);
   134     standardFlags->moveBy (x,y);
   135     heading->moveBy (x,y);
   136 	updateLink();
   137 	requestReposition();
   138 }
   139 
   140 void OrnamentedObj::moveBy (QPoint p)
   141 {
   142 	moveBy (p.x(), p.y());
   143 }	
   144 
   145 void OrnamentedObj::move2RelPos(double x, double y)
   146 {
   147 	if (!parObj) return;
   148 	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
   149 }
   150 
   151 void OrnamentedObj::move2RelPos(QPoint p)
   152 {
   153 	move2RelPos (p.x(),p.y());
   154 }
   155 
   156 void OrnamentedObj::setNote(QString s)
   157 {
   158 	note.setNote(s);
   159 	if (!note.isEmpty())
   160 		systemFlags->activate("note");
   161 	else		
   162 		systemFlags->deactivate("note");
   163 	calcBBoxSize();
   164 	positionBBox();	
   165 	move (absPos.x(), absPos.y() );
   166 	forceReposition();
   167 }
   168 
   169 void OrnamentedObj::setNote(NoteObj n)
   170 {
   171 	note=n;
   172 	if (!note.isEmpty())
   173 		systemFlags->activate("note");
   174 	else		
   175 		systemFlags->deactivate("note");
   176 	calcBBoxSize();
   177 	positionBBox();	
   178 	move (absPos.x(), absPos.y() );
   179 	forceReposition();
   180 	
   181 }
   182 
   183 QString OrnamentedObj::getNote()
   184 {
   185     return note.getNote();
   186 }
   187 
   188 QString OrnamentedObj::getNoteASCII()
   189 {
   190     return note.getNoteASCII();
   191 }
   192 
   193 QString OrnamentedObj::getNoteOpenDoc()
   194 {
   195     return note.getNoteOpenDoc();
   196 }
   197 
   198 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   199 {
   200 	standardFlags->toggle(f,exclusive);
   201 	calcBBoxSize();
   202 	positionBBox();
   203 	move (absPos.x(), absPos.y() );
   204 	forceReposition();
   205 }
   206 
   207 void OrnamentedObj::activateStandardFlag(QString f)
   208 {
   209 	standardFlags->activate(f);
   210 	calcBBoxSize();
   211 	positionBBox();
   212 	move (absPos.x(), absPos.y() );
   213 	forceReposition();
   214 }
   215 
   216 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   217 {
   218 	return systemFlags->getFlagName(p);	
   219 }
   220 
   221 bool OrnamentedObj::isActiveFlag (const QString & fname)
   222 {
   223 	if (standardFlags->isActive (fname) ) return true;
   224 	return false;
   225 }
   226 
   227 void OrnamentedObj::updateNoteFlag()
   228 {
   229 	if (selected) 
   230 	{
   231 		// text in NoteEditor has changed, notify MapEditor 
   232 		mapEditor->setChanged();
   233 
   234 		// save text
   235 		setNote( textEditor->getText() );
   236 	
   237 		// save font   
   238 		note.setFontHint (textEditor->getFontHint() );
   239 	}	
   240 }
   241