mapcenterobj.cpp
author insilmaril
Mon, 12 Feb 2007 09:28:47 +0000
changeset 427 fb74fa7bfb4c
parent 421 5522d1da7e37
child 459 9bc55005a0f1
permissions -rw-r--r--
1.8.66 Various fixes
     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 		+areaAttr 
   142 		+idAttr 
   143 		+getIncludeImageAttr() );
   144     incIndent();
   145     if (heading->getColor()!=QColor("black"))
   146 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   147     else	
   148 		a="";
   149     
   150 	// Save flags. If verbose is set (export to xml dir), also write
   151 	// the flags as picture
   152 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   153 
   154 	// Save heading
   155     s+=valueElement("heading", getHeading(),a);
   156 
   157 	// Save frame
   158 	s+=frame->saveToDir ();
   159 
   160 	// add link to file in s
   161 	if (!note.isEmpty() )
   162 		s+=note.saveToDir();
   163 	
   164 	// Save branches
   165 	for (int i=0; i<branch.size(); ++i)
   166 		s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
   167 
   168 	// Save FloatImages
   169 	for (int i=0; i<floatimage.size(); ++i)
   170 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   171 
   172 	// Save XLinks
   173 	for (int i=0;i<xlink.size(); ++i)
   174 		s+=xlink.at(i)->saveToDir();
   175 
   176     decIndent();
   177     s+=endElement   ("mapcenter");
   178     return s;
   179 }
   180 
   181 void MapCenterObj::setVersion (const QString &s)
   182 {
   183 	version=s;
   184 }
   185 
   186 void MapCenterObj::setAuthor (const QString &s)
   187 {
   188 	author=s;
   189 }
   190 
   191 QString MapCenterObj::getAuthor()
   192 {
   193 	return author;
   194 }
   195 
   196 void MapCenterObj::setComment (const QString &s)
   197 {
   198 	comment=s;
   199 }
   200 
   201 QString MapCenterObj::getComment ()
   202 {
   203 	return comment;
   204 }
   205 
   206 QString MapCenterObj::getDate ()
   207 {
   208 	return QDate::currentDate().toString ("yyyy-MM-dd");
   209 }
   210