mapcenterobj.cpp
author insilmaril
Thu, 02 Apr 2009 09:46:29 +0000
changeset 750 ff3b01ce0960
parent 749 9ff332964015
child 753 25a77484ec72
permissions -rw-r--r--
More moving from BranchObj to BranchItem
     1 #include <QDateTime>
     2 
     3 #include "floatimageobj.h"
     4 #include "geometry.h"
     5 #include "mapcenterobj.h"
     6 #include "mapeditor.h"
     7 
     8 
     9 /////////////////////////////////////////////////////////////////
    10 // MapCenterObj
    11 /////////////////////////////////////////////////////////////////
    12 MapCenterObj::MapCenterObj() : BranchObj ()
    13 {
    14 //    cout << "Const MapCenterObj\n";
    15     init();
    16 }
    17 
    18 MapCenterObj::MapCenterObj(QGraphicsScene* s) : BranchObj (s)
    19 {
    20 //    cout << "Const MapCenterObj   canvas="<<s<<"\n";
    21     init();
    22 }
    23 
    24 MapCenterObj::MapCenterObj(QGraphicsScene* s,VymModel *m) : BranchObj (s)
    25 {
    26 //    cout << "Const MapCenterObj   canvas="<<s<<"\n";
    27 	model=m;
    28     init();
    29 }
    30 
    31 MapCenterObj::~MapCenterObj() 
    32 {
    33 //    cout << "Destr MapCenterObj\n";
    34 	clear();
    35 }	
    36 
    37 void MapCenterObj::clear() 
    38 {
    39 	BranchObj::clear();
    40 }
    41 
    42 void MapCenterObj::init () 
    43 {
    44 	BranchObj::init();
    45     orientation=LinkableMapObj::UndefinedOrientation;
    46 
    47 	// TODO this should be done in TextObj later...
    48 	//QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
    49 	//heading->setFont(font);
    50 	depth=0;
    51 	setDefAttr(MovedBranch);
    52 
    53 	frame->setFrameType (FrameObj::Rectangle);
    54 }
    55 
    56 void MapCenterObj::move (double x, double y)
    57 {
    58 	BranchObj::move(x,y);
    59 }
    60 
    61 void MapCenterObj::move (QPointF absPos)
    62 {
    63 	BranchObj::move(absPos);
    64 }
    65 
    66 void MapCenterObj::moveBy (double x, double y)
    67 {
    68 	BranchObj::moveBy(x,y);
    69 }
    70 
    71 void MapCenterObj::moveAll (double x, double y)
    72 {
    73 	// Get rel. position
    74 	double dx=x-absPos.x();
    75 	double dy=y-absPos.y();
    76 
    77 	// Move myself and branches
    78 	moveAllBy (dx,dy);
    79 }
    80 
    81 void MapCenterObj::moveAllBy (double dx, double dy)
    82 {
    83 	// Move myself and children
    84 	BranchObj::moveBy(dx,dy);
    85 }
    86 
    87 void MapCenterObj::updateLink()
    88 {
    89 	// set childPos to middle of MapCenterObj
    90 	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
    91 	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
    92 	parPos=childPos;		
    93 	for (int i=0; i<branch.size(); ++i)
    94 		branch.at(i)->updateLink();
    95 }
    96 
    97 void MapCenterObj::updateRelPositions()
    98 {
    99 	if (repositionRequest) unsetAllRepositionRequests();
   100 
   101 	// update relative Positions of branches and floats
   102 	for (int i=0; i<branch.size(); ++i)
   103 	{
   104 		branch.at(i)->setRelPos();
   105 		branch.at(i)->setOrientation();
   106 	}
   107 	
   108 	for (int i=0; i<floatimage.size(); ++i)
   109 		floatimage.at(i)->setRelPos();
   110 
   111 	if (repositionRequest) reposition();
   112 }
   113 
   114 LinkableMapObj* MapCenterObj::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
   115 	{
   116 	LinkableMapObj *lmo;
   117 
   118 	// Search through child branches
   119 	for (int i=0; i<branch.size(); ++i)
   120 	{	
   121 		lmo = branch.at(i)->findMapObj(p, excludeLMO);
   122 		if (lmo!= NULL) return lmo;
   123 	}
   124 	// is p in MapCenter?
   125 	if (inBox (p,clickBox) && (this != excludeLMO) ) return this;
   126 
   127 	// Search float images
   128 	for (int i=0; i<floatimage.size(); ++i)
   129 		if (inBox(p,floatimage.at(i)->getClickBox()) && (floatimage.at(i) != excludeLMO) && floatimage.at(i)->getParObj()!= excludeLMO) return floatimage.at(i);
   130 
   131 	// nothing found
   132 	return NULL;
   133 }
   134 
   135 QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
   136 {
   137     QString s,a;
   138 
   139 	// save area, if not scrolled
   140 	QString areaAttr=
   141 		attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   142 		attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   143 		attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   144 		attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   145 	
   146 	// Providing an ID for a branch makes export to XHTML easier
   147 	QString idAttr;
   148 	if (treeItem->xlinkCount()>0)
   149 		idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
   150 
   151 	else
   152 		idAttr="";
   153 
   154 	QString linkAttr=getLinkAttr();
   155 
   156     s=beginElement ("mapcenter" 
   157 		+getOrnXMLAttr() 
   158 		+areaAttr 
   159 		+idAttr 
   160 		+getIncludeImageAttr() );
   161     incIndent();
   162     if (heading->getColor()!=QColor("black"))
   163 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   164     else	
   165 		a="";
   166     
   167 	// Save flags. If verbose is set (export to xml dir), also write
   168 	// the flags as picture
   169 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   170 
   171 	// Save heading
   172     s+=valueElement("heading", getHeading(),a);
   173 
   174 	// Save frame
   175 	s+=frame->saveToDir ();
   176 
   177 	// Update of note is usually done while unselecting a branch
   178 	//if (isNoteInEditor) getNoteFromTextEditor();  FIXME-3
   179 
   180 	// save note
   181 	if (!treeItem->getNoteObj().isEmpty() )
   182 		s+=treeItem->getNoteObj().saveToDir();
   183 	
   184 	// Save branches
   185 	for (int i=0; i<branch.size(); ++i)
   186 		s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
   187 
   188 	// Save FloatImages
   189 	for (int i=0; i<floatimage.size(); ++i)
   190 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   191 
   192 	// Save XLinks
   193 	for (int i=0;i<xlink.size(); ++i)
   194 		s+=xlink.at(i)->saveToDir();
   195 
   196     decIndent();
   197     s+=endElement   ("mapcenter");
   198     return s;
   199 }
   200 
   201 void MapCenterObj::setVersion (const QString &s)
   202 {
   203 	version=s;
   204 }
   205 
   206 void MapCenterObj::setAuthor (const QString &s)
   207 {
   208 	author=s;
   209 }
   210 
   211 QString MapCenterObj::getAuthor()
   212 {
   213 	return author;
   214 }
   215 
   216 void MapCenterObj::setComment (const QString &s)
   217 {
   218 	comment=s;
   219 }
   220 
   221 QString MapCenterObj::getComment ()
   222 {
   223 	return comment;
   224 }
   225 
   226 QString MapCenterObj::getDate ()
   227 {
   228 	return QDate::currentDate().toString ("yyyy-MM-dd");
   229 }
   230