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