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