ornamentedobj.cpp
author insilmaril
Sun, 30 Jan 2005 12:58:52 +0000
branchvendor
changeset 23 1773dcd0a0a4
parent 0 7a96bd401351
child 2 608f976aa7bb
child 103 c810a11d11d9
permissions -rw-r--r--
Initial import.
     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 
    59 }
    60 
    61 void OrnamentedObj::copy (OrnamentedObj* other)
    62 {
    63     LinkableMapObj::copy(other);
    64 	heading->copy(other->heading);
    65     setColor   (other->heading->getColor(),false);	
    66 
    67 	note.copy (other->note);
    68 	systemFlags->copy (other->systemFlags);
    69 	standardFlags->copy (other->standardFlags);
    70 
    71 }
    72 
    73 QString OrnamentedObj::getHeading()
    74 {
    75     return heading->text();
    76 }
    77 
    78 void OrnamentedObj::setLinkColor()
    79 {
    80 	if (mapEditor->getLinkColorHint()==HeadingColor)
    81 		LinkableMapObj::setLinkColor (heading->getColor());
    82 	else	
    83 		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    84 }
    85 
    86 QColor OrnamentedObj::getColor ()
    87 {
    88     return heading->getColor();
    89 }
    90 
    91 
    92 void OrnamentedObj::move (double x, double y)
    93 {
    94 	MapObj::move (x,y);
    95 	double dx=frame->getBorder()/2;  // care for border around object
    96 	double dy=frame->getBorder()/2;
    97 	systemFlags-> move (x + dx, y + dy);
    98 
    99 	// vertical align heading to bottom
   100 	int h=max (systemFlags->getBBox().height(), standardFlags->getBBox().height());
   101 	h=max (h,heading->getHeight());
   102     heading->move (x + dx + systemFlags->getBBox().width(),
   103 					y + dy  + h - heading->getHeight() 
   104 					);
   105 	standardFlags->move (x + heading->getWidth() + systemFlags->getBBox().width(), y + dy );				
   106 
   107 	updateLink();
   108 	requestReposition();
   109 }
   110 
   111 void OrnamentedObj::move (QPoint p)
   112 {
   113 	move (p.x(), p.y());
   114 }	
   115 
   116 void OrnamentedObj::moveBy (double x, double y)
   117 {
   118 
   119 	MapObj::moveBy (x,y);
   120     frame->moveBy (x,y);
   121     systemFlags->moveBy (x,y);
   122     standardFlags->moveBy (x,y);
   123     heading->moveBy (x,y);
   124 	updateLink();
   125 	requestReposition();
   126 }
   127 
   128 void OrnamentedObj::moveBy (QPoint p)
   129 {
   130 	moveBy (p.x(), p.y());
   131 }	
   132 
   133 void OrnamentedObj::move2RelPos(double x, double y)
   134 {
   135 	if (!parObj) return;
   136 	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
   137 }
   138 
   139 void OrnamentedObj::move2RelPos(QPoint p)
   140 {
   141 	if (!parObj) return;
   142 	move (parObj->getChildPos().x() + p.x(), parObj->getChildPos().y() + p.y() );
   143 }
   144 
   145 void OrnamentedObj::setNote(QString s)
   146 {
   147 	note.setNote(s);
   148 	if (!note.isEmpty())
   149 		systemFlags->activate("note");
   150 	else		
   151 		systemFlags->deactivate("note");
   152 	calcBBoxSize();
   153 	positionBBox();	
   154 	move (absPos.x(), absPos.y() );
   155 	forceReposition();
   156 }
   157 
   158 void OrnamentedObj::setNote(NoteObj n)
   159 {
   160 	note=n;
   161 	if (!note.isEmpty())
   162 		systemFlags->activate("note");
   163 	else		
   164 		systemFlags->deactivate("note");
   165 	calcBBoxSize();
   166 	positionBBox();	
   167 	move (absPos.x(), absPos.y() );
   168 	forceReposition();
   169 	
   170 }
   171 
   172 QString OrnamentedObj::getNote()
   173 {
   174     return note.getNote();
   175 }
   176 
   177 void OrnamentedObj::toggleStandardFlag(QString f)
   178 {
   179 	standardFlags->toggle(f);
   180 	calcBBoxSize();
   181 	positionBBox();
   182 	move (absPos.x(), absPos.y() );
   183 	forceReposition();
   184 }
   185 
   186 void OrnamentedObj::activateStandardFlag(QString f)
   187 {
   188 	standardFlags->activate(f);
   189 	calcBBoxSize();
   190 	positionBBox();
   191 	move (absPos.x(), absPos.y() );
   192 	forceReposition();
   193 }
   194 
   195 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   196 {
   197 	return systemFlags->getFlagName(p);	
   198 }
   199 
   200 void OrnamentedObj::updateNoteFlag()
   201 {
   202 	// text in NoteEditor has changed, notify MapEditor 
   203 	mapEditor->setChanged();
   204 
   205 	// save text
   206 	setNote( textEditor->getText() );
   207 	
   208 	// save font   
   209 	note.setFontHint (textEditor->getFontHint() );
   210 }
   211