mapcenterobj.cpp
author insilmaril
Mon, 20 Nov 2006 12:12:05 +0000
changeset 405 a4532e5c2ce3
parent 404 53efc2562a7d
child 406 1c8ff1928b97
permissions -rw-r--r--
historywindow moved to mainwindow. Started to get rid of Q3PtrList finally
     1 #include <qdatetime.h>
     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(Q3Canvas* c) : BranchObj (c)
    16 {
    17 //    cout << "Const MapCenterObj   canvas="<<c<<"\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 	// FIXME 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 	BranchObj *b;
    78 	for (b=branch.first(); b; b=branch.next() )
    79 		b->updateLink();
    80 }
    81 
    82 void MapCenterObj::updateRelPositions()
    83 {
    84 	if (repositionRequest) unsetAllRepositionRequests();
    85 
    86 	// update relative Positions of branches and floats
    87 	BranchObj *b;
    88 	for (b=branch.first(); b; b=branch.next() ) 
    89 	{
    90 		b->setRelPos();
    91 		b->setOrientation();
    92 	}
    93 	
    94 	for (int i=0; i<floatimage.size(); ++i)
    95 		floatimage.at(i)->setRelPos();
    96 
    97 	if (repositionRequest) reposition();
    98 }
    99 
   100 LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
   101 	{
   102 	BranchObj *bo;
   103 	LinkableMapObj *lmo;
   104 
   105 	// Search through child branches
   106 	for (bo=branch.first(); bo; bo=branch.next() )
   107 	{	
   108 		lmo = bo->findMapObj(p, excludeLMO);
   109 		if (lmo!= NULL) return lmo;
   110 	}
   111 	// is p in MapCenter?
   112 	if (inBox (p) && (this != excludeLMO) ) return this;
   113 
   114 	// Search float images
   115 	for (int i=0; i<floatimage.size(); ++i)
   116 		if (floatimage.at(i)->inBox(p) && (floatimage.at(i) != excludeLMO) && floatimage.at(i)->getParObj()!= excludeLMO) return floatimage.at(i);
   117 
   118 	// nothing found
   119 	return NULL;
   120 }
   121 
   122 QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
   123 {
   124     QString s,a;
   125 
   126 	// save area, if not scrolled
   127 	QString areaAttr=
   128 		attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
   129 		attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
   130 		attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
   131 		attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
   132 	
   133 	// Providing an ID for a branch makes export to XHTML easier
   134 	QString idAttr;
   135 	if (countXLinks()>0)
   136 		idAttr=attribut ("id",getSelectString());
   137 	else
   138 		idAttr="";
   139 
   140 	QString linkAttr=getLinkAttr();
   141 
   142     s=beginElement ("mapcenter" 
   143 		+getOrnAttr() 
   144 		+attribut("frameType",frame->getFrameTypeName()) 
   145 		+areaAttr 
   146 		+idAttr 
   147 		+getIncludeImageAttr() );
   148     incIndent();
   149     if (heading->getColor()!=QColor("black"))
   150 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   151     else	
   152 		a="";
   153     
   154 	// Save flags. If verbose is set (export to xml dir), also write
   155 	// the flags as picture
   156 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   157     s=s+valueElement("heading", getHeading(),a);
   158 
   159 	// add link to file in s
   160 	if (!note.isEmpty() )
   161 		s+=note.saveToDir();
   162 	
   163 	// Save branches
   164     BranchObj *bo;
   165     for (bo=branch.first(); bo; bo=branch.next() )
   166 		s+=bo->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 	XLinkObj *xlo;
   174     for (xlo=xlink.first(); xlo; xlo=xlink.next() )
   175 		s+=xlo->saveToDir();
   176 
   177     decIndent();
   178     s+=endElement   ("mapcenter");
   179     return s;
   180 }
   181 
   182 void MapCenterObj::setVersion (const QString &s)
   183 {
   184 	version=s;
   185 }
   186 
   187 void MapCenterObj::setAuthor (const QString &s)
   188 {
   189 	author=s;
   190 }
   191 
   192 QString MapCenterObj::getAuthor()
   193 {
   194 	return author;
   195 }
   196 
   197 void MapCenterObj::setComment (const QString &s)
   198 {
   199 	comment=s;
   200 }
   201 
   202 QString MapCenterObj::getComment ()
   203 {
   204 	return comment;
   205 }
   206 
   207 QString MapCenterObj::getDate ()
   208 {
   209 	return QDate::currentDate().toString ("yyyy-MM-dd");
   210 }
   211