ornamentedobj.cpp
author insilmaril
Thu, 23 Feb 2006 08:37:39 +0000
changeset 218 160459d924a1
parent 187 2658871fdda4
child 227 38ad83f1d4ce
permissions -rw-r--r--
New translation: Italian. Minor Improvements in mmap 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 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 }
    69 
    70 QString OrnamentedObj::getHeading()
    71 {
    72     return heading->text();
    73 }
    74 
    75 void OrnamentedObj::setLinkColor()
    76 {
    77 	if (mapEditor->getLinkColorHint()==HeadingColor)
    78 		LinkableMapObj::setLinkColor (heading->getColor());
    79 	else	
    80 		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    81 }
    82 
    83 QColor OrnamentedObj::getColor ()
    84 {
    85     return heading->getColor();
    86 }
    87 
    88 
    89 void OrnamentedObj::positionContents()
    90 {
    91 	double d=frame->getBorder()/2;
    92 	double x=absPos.x();
    93 	double y=absPos.y();
    94 	systemFlags-> move (x + d, y + d );
    95 
    96 	// vertical align heading to bottom
    97 	int h=max (systemFlags->getBBox().height(), standardFlags->getBBox().height());
    98 	h=max (h,heading->getHeight());
    99     heading->move (x + d + systemFlags->getBBox().width(),
   100 					y + d  + h - heading->getHeight() 
   101 					);
   102 	standardFlags->move (x + heading->getWidth() + systemFlags->getBBox().width() + d , y + d  );
   103 }
   104 
   105 void OrnamentedObj::move (double x, double y)
   106 {
   107 	MapObj::move (x,y);
   108 	positionContents();
   109 	updateLink();
   110 	requestReposition();
   111 }
   112 
   113 void OrnamentedObj::move (QPoint p)
   114 {
   115 	move (p.x(), p.y());
   116 }	
   117 
   118 void OrnamentedObj::moveBy (double x, double y)
   119 {
   120 
   121 	MapObj::moveBy (x,y);
   122     frame->moveBy (x,y);
   123     systemFlags->moveBy (x,y);
   124     standardFlags->moveBy (x,y);
   125     heading->moveBy (x,y);
   126 	updateLink();
   127 	requestReposition();
   128 }
   129 
   130 void OrnamentedObj::moveBy (QPoint p)
   131 {
   132 	moveBy (p.x(), p.y());
   133 }	
   134 
   135 void OrnamentedObj::move2RelPos(double x, double y)
   136 {
   137 	if (!parObj) return;
   138 	move (parObj->getChildPos().x()+x, parObj->getChildPos().y()+y);
   139 }
   140 
   141 void OrnamentedObj::move2RelPos(QPoint p)
   142 {
   143 	move2RelPos (p.x(),p.y());
   144 }
   145 
   146 void OrnamentedObj::setNote(QString s)
   147 {
   148 	note.setNote(s);
   149 	if (!note.isEmpty())
   150 		systemFlags->activate("note");
   151 	else		
   152 		systemFlags->deactivate("note");
   153 	calcBBoxSize();
   154 	positionBBox();	
   155 	move (absPos.x(), absPos.y() );
   156 	forceReposition();
   157 }
   158 
   159 void OrnamentedObj::setNote(NoteObj n)
   160 {
   161 	note=n;
   162 	if (!note.isEmpty())
   163 		systemFlags->activate("note");
   164 	else		
   165 		systemFlags->deactivate("note");
   166 	calcBBoxSize();
   167 	positionBBox();	
   168 	move (absPos.x(), absPos.y() );
   169 	forceReposition();
   170 	
   171 }
   172 
   173 QString OrnamentedObj::getNote()
   174 {
   175     return note.getNote();
   176 }
   177 
   178 QString OrnamentedObj::getNoteASCII()
   179 {
   180     return note.getNoteASCII();
   181 }
   182 
   183 QString OrnamentedObj::getNoteOpenDoc()
   184 {
   185     return note.getNoteOpenDoc();
   186 }
   187 
   188 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   189 {
   190 	standardFlags->toggle(f,exclusive);
   191 	calcBBoxSize();
   192 	positionBBox();
   193 	move (absPos.x(), absPos.y() );
   194 	forceReposition();
   195 }
   196 
   197 void OrnamentedObj::activateStandardFlag(QString f)
   198 {
   199 	standardFlags->activate(f);
   200 	calcBBoxSize();
   201 	positionBBox();
   202 	move (absPos.x(), absPos.y() );
   203 	forceReposition();
   204 }
   205 
   206 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   207 {
   208 	return systemFlags->getFlagName(p);	
   209 }
   210 
   211 void OrnamentedObj::updateNoteFlag()
   212 {
   213 	if (selected) 
   214 	{
   215 		// text in NoteEditor has changed, notify MapEditor 
   216 		mapEditor->setChanged();
   217 
   218 		// save text
   219 		setNote( textEditor->getText() );
   220 	
   221 		// save font   
   222 		note.setFontHint (textEditor->getFontHint() );
   223 	}	
   224 }
   225