mapcenterobj.cpp
author insilmaril
Mon, 11 Jul 2005 19:55:57 +0000
changeset 125 8cdfa8dda71e
parent 95 f688a9913724
child 164 d442a66e9121
permissions -rw-r--r--
Version 1.6.10: Updated documentation
     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(QCanvas* 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     init();
    31 }
    32 
    33 void MapCenterObj::init () 
    34 {
    35 	BranchObj::init();
    36     orientation=OrientUndef;
    37     absPos=QPoint (canvas->width()/2, canvas->height()/2);
    38 
    39 	// FIXME this should be done in TextObj later...
    40 	QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
    41 	heading->setFont(font);
    42 
    43 	depth=0;
    44 
    45 	frame->setFrameType (Rectangle);
    46 	move (absPos.x(), absPos.y() );
    47 }
    48 
    49 void MapCenterObj::move (double x, double y)
    50 {
    51 	BranchObj::move(x,y);
    52 	positionBBox();
    53 }
    54 
    55 void MapCenterObj::moveBy (double x, double y)
    56 {
    57 	BranchObj::moveBy(x,y);
    58 	positionBBox();
    59 }
    60 
    61 void MapCenterObj::moveAll (double x, double y)
    62 {
    63 	// Get rel. position
    64 	double dx=x-absPos.x();
    65 	double dy=y-absPos.y();
    66 
    67 	// Move myself and branches
    68 	moveAllBy (dx,dy);
    69 }
    70 
    71 void MapCenterObj::moveAllBy (double dx, double dy)
    72 {
    73 	// Move myself
    74 	moveBy(dx,dy);
    75 
    76 	positionBBox();
    77 }
    78 
    79 void MapCenterObj::updateLink()
    80 {
    81 	// set childPos to middle of MapCenterObj
    82 	childPos=QPoint(
    83 		absPos.x() + QSize(getSize() ).width()/2, 
    84 		absPos.y() + QSize(getSize() ).height()/2);
    85 	parPos=childPos;		
    86 	BranchObj *b;
    87 	for (b=branch.first(); b; b=branch.next() )
    88 		b->updateLink();
    89 }
    90 
    91 LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
    92 	{
    93 	BranchObj *bo;
    94 	LinkableMapObj *lmo;
    95 
    96 	// Search through child branches
    97 	for (bo=branch.first(); bo; bo=branch.next() )
    98 	{	
    99 		lmo = bo->findMapObj(p, excludeLMO);
   100 		
   101 		if (lmo!= NULL) 
   102 		{
   103 			return lmo;
   104 		}	
   105 	}
   106 	// is p in MapCenter?
   107 	if (inBBox (p) && (this != excludeLMO) ) return this;
   108 
   109 	// Search float images
   110 	FloatImageObj *foi;
   111 	for (foi=floatimage.first(); foi; foi=floatimage.next() )
   112 		if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
   113 
   114 	// nothing found
   115 	return NULL;
   116 }
   117 
   118 QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
   119 {
   120     QString s,a;
   121 
   122 	// save area, if not scrolled
   123 	QString areaAttr=
   124 		attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
   125 		attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
   126 		attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
   127 		attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
   128 	
   129     s=beginElement ("mapcenter" 
   130 		+attribut("absPosX",QString().setNum(absPos.x(),10))
   131 		+attribut("absPosY",QString().setNum(absPos.y(),10))
   132 		+attribut("frameType",frame->getFrameTypeName()) 
   133 		+areaAttr 
   134 		);
   135 		
   136     incIndent();
   137     if (heading->getColor()!=QColor("black"))
   138 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   139     else	
   140 		a="";
   141     
   142 	// Save flags. If verbose is set (export to xml dir), also write
   143 	// the flags as picture
   144 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   145     s=s+valueElement("heading", getHeading(),a);
   146 
   147 	// Reset the counters before saving
   148 	FloatImageObj (canvas).resetSaveCounter();
   149 
   150 	// add link to file in s
   151 	if (!note.isEmpty() )
   152 		s+=note.saveToDir();
   153 	
   154 	// Save branches
   155     BranchObj *bo;
   156     for (bo=branch.first(); bo; bo=branch.next() )
   157 		s+=bo->saveToDir(tmpdir,prefix, offset);
   158 
   159 	// Save FloatImages
   160 	FloatImageObj *fio;
   161 	for (fio=floatimage.first(); fio; fio=floatimage.next() )
   162 		s+=fio->saveToDir (tmpdir,prefix);
   163 
   164 	// Save XLinks
   165 	XLinkObj *xlo;
   166     for (xlo=xlink.first(); xlo; xlo=xlink.next() )
   167 		s+=xlo->saveToDir();
   168 
   169     decIndent();
   170     s+=endElement   ("mapcenter");
   171     return s;
   172 }
   173 
   174 void MapCenterObj::setVersion (const QString &s)
   175 {
   176 	version=s;
   177 }
   178 
   179 bool MapCenterObj::checkVersion ()
   180 {
   181 	// returns true, if vym is able to read file regarding 
   182 	// the version set with setVersion
   183 	QString s1=version.section (".",0,0);
   184 	QString s2=version.section (".",1,1);
   185 	QString s3=version.section (".",2,2);
   186 	bool ok;
   187 	int vv1 =QString(__VYM_VERSION__).section (".",0,0).toInt(&ok,10);
   188 	int vv2 =QString(__VYM_VERSION__).section (".",1,1).toInt(&ok,10);
   189 	int vv3 =QString(__VYM_VERSION__).section (".",2,2).toInt(&ok,10);
   190 	int mv1=0;
   191 	int mv2=0;
   192 	int mv3=0;
   193 	if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
   194 	if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
   195 	if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
   196 	
   197 	if (vv1 > mv1)
   198 		return true;
   199 	if (vv1 < mv1)
   200 		return false;
   201 	if (vv2 > mv2)
   202 		return true;
   203 	if (vv2 < mv2)
   204 		return false;
   205 	if (vv3 > mv3)
   206 		return true;
   207 	if (vv3 < mv3)
   208 		return false;
   209 	return true;	
   210 }
   211 
   212 void MapCenterObj::setAuthor (const QString &s)
   213 {
   214 	author=s;
   215 }
   216 
   217 QString MapCenterObj::getAuthor()
   218 {
   219 	return author;
   220 }
   221 
   222 void MapCenterObj::setComment (const QString &s)
   223 {
   224 	comment=s;
   225 }
   226 
   227 QString MapCenterObj::getComment ()
   228 {
   229 	return comment;
   230 }
   231 
   232 QString MapCenterObj::getDate ()
   233 {
   234 	return QDate::currentDate().toString ("yyyy-MM-dd");
   235 }
   236