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