ornamentedobj.cpp
author insilmaril
Wed, 15 Feb 2006 12:54:55 +0000
changeset 204 657078664946
parent 187 2658871fdda4
child 218 160459d924a1
permissions -rw-r--r--
1.7.9 Import of KDE bookmarks, some _de translations
     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 	if (!parObj) return;
   144 	move (parObj->getChildPos().x() + p.x(), parObj->getChildPos().y() + p.y() );
   145 }
   146 
   147 void OrnamentedObj::setNote(QString s)
   148 {
   149 	note.setNote(s);
   150 	if (!note.isEmpty())
   151 		systemFlags->activate("note");
   152 	else		
   153 		systemFlags->deactivate("note");
   154 	calcBBoxSize();
   155 	positionBBox();	
   156 	move (absPos.x(), absPos.y() );
   157 	forceReposition();
   158 }
   159 
   160 void OrnamentedObj::setNote(NoteObj n)
   161 {
   162 	note=n;
   163 	if (!note.isEmpty())
   164 		systemFlags->activate("note");
   165 	else		
   166 		systemFlags->deactivate("note");
   167 	calcBBoxSize();
   168 	positionBBox();	
   169 	move (absPos.x(), absPos.y() );
   170 	forceReposition();
   171 	
   172 }
   173 
   174 QString OrnamentedObj::getNote()
   175 {
   176     return note.getNote();
   177 }
   178 
   179 QString OrnamentedObj::getNoteASCII()
   180 {
   181     return note.getNoteASCII();
   182 }
   183 
   184 QString OrnamentedObj::getNoteOpenDoc()
   185 {
   186     return note.getNoteOpenDoc();
   187 }
   188 
   189 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   190 {
   191 	standardFlags->toggle(f,exclusive);
   192 	calcBBoxSize();
   193 	positionBBox();
   194 	move (absPos.x(), absPos.y() );
   195 	forceReposition();
   196 }
   197 
   198 void OrnamentedObj::activateStandardFlag(QString f)
   199 {
   200 	standardFlags->activate(f);
   201 	calcBBoxSize();
   202 	positionBBox();
   203 	move (absPos.x(), absPos.y() );
   204 	forceReposition();
   205 }
   206 
   207 QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   208 {
   209 	return systemFlags->getFlagName(p);	
   210 }
   211 
   212 void OrnamentedObj::updateNoteFlag()
   213 {
   214 	if (selected) 
   215 	{
   216 		// text in NoteEditor has changed, notify MapEditor 
   217 		mapEditor->setChanged();
   218 
   219 		// save text
   220 		setNote( textEditor->getText() );
   221 	
   222 		// save font   
   223 		note.setFontHint (textEditor->getFontHint() );
   224 	}	
   225 }
   226