1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/mapcenterobj.cpp Thu Jul 17 09:27:20 2008 +0000
1.3 @@ -0,0 +1,235 @@
1.4 +#include <qdatetime.h>
1.5 +
1.6 +#include "mapcenterobj.h"
1.7 +#include "floatimageobj.h"
1.8 +#include "mapeditor.h"
1.9 +
1.10 +/////////////////////////////////////////////////////////////////
1.11 +// MapCenterObj
1.12 +/////////////////////////////////////////////////////////////////
1.13 +MapCenterObj::MapCenterObj() : BranchObj ()
1.14 +{
1.15 +// cout << "Const MapCenterObj\n";
1.16 + init();
1.17 +}
1.18 +
1.19 +MapCenterObj::MapCenterObj(QCanvas* c) : BranchObj (c)
1.20 +{
1.21 +// cout << "Const MapCenterObj canvas="<<c<<"\n";
1.22 + init();
1.23 +}
1.24 +
1.25 +MapCenterObj::~MapCenterObj()
1.26 +{
1.27 +// cout << "Destr MapCenterObj\n";
1.28 +}
1.29 +
1.30 +void MapCenterObj::clear()
1.31 +{
1.32 + BranchObj::clear();
1.33 + init();
1.34 +}
1.35 +
1.36 +void MapCenterObj::init ()
1.37 +{
1.38 + orientation=OrientUndef;
1.39 + absPos=QPoint (canvas->width()/2, canvas->height()/2);
1.40 +
1.41 + // FIXME this should be done in TextObj later...
1.42 + QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");
1.43 + heading->setFont(font);
1.44 +
1.45 + branch.setAutoDelete (TRUE);
1.46 + floatimage.setAutoDelete (TRUE);
1.47 +
1.48 + move (absPos.x(), absPos.y() );
1.49 + depth=0;
1.50 +
1.51 + scrolled=false;
1.52 + tmpUnscrolled=false;
1.53 +
1.54 + frame->setFrameType (Rectangle);
1.55 +}
1.56 +
1.57 +void MapCenterObj::move (double x, double y)
1.58 +{
1.59 + BranchObj::move(x,y);
1.60 + positionBBox();
1.61 +}
1.62 +
1.63 +void MapCenterObj::moveBy (double x, double y)
1.64 +{
1.65 + BranchObj::moveBy(x,y);
1.66 + positionBBox();
1.67 +}
1.68 +
1.69 +void MapCenterObj::moveAll (double x, double y)
1.70 +{
1.71 + // Get rel. position
1.72 + double dx=x-absPos.x();
1.73 + double dy=y-absPos.y();
1.74 +
1.75 + // Move myself and branches
1.76 + moveAllBy (dx,dy);
1.77 +}
1.78 +
1.79 +void MapCenterObj::moveAllBy (double dx, double dy)
1.80 +{
1.81 + // Move myself
1.82 + moveBy(dx,dy);
1.83 +
1.84 + positionBBox();
1.85 +}
1.86 +
1.87 +void MapCenterObj::updateLink()
1.88 +{
1.89 + // set childPos to middle of MapCenterObj
1.90 + childPos=QPoint(
1.91 + absPos.x() + QSize(getSize() ).width()/2,
1.92 + absPos.y() + QSize(getSize() ).height()/2);
1.93 + parPos=childPos;
1.94 + BranchObj *b;
1.95 + for (b=branch.first(); b; b=branch.next() )
1.96 + b->updateLink();
1.97 +}
1.98 +
1.99 +LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
1.100 + {
1.101 + BranchObj *bo;
1.102 + LinkableMapObj *lmo;
1.103 +
1.104 + // Search through child branches
1.105 + for (bo=branch.first(); bo; bo=branch.next() )
1.106 + {
1.107 + lmo = bo->findMapObj(p, excludeLMO);
1.108 +
1.109 + if (lmo!= NULL)
1.110 + {
1.111 + return lmo;
1.112 + }
1.113 + }
1.114 + // is p in MapCenter?
1.115 + if (inBBox (p) && (this != excludeLMO) ) return this;
1.116 +
1.117 + // Search float images
1.118 + FloatImageObj *foi;
1.119 + for (foi=floatimage.first(); foi; foi=floatimage.next() )
1.120 + if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
1.121 +
1.122 + // nothing found
1.123 + return NULL;
1.124 +}
1.125 +
1.126 +QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
1.127 +{
1.128 + QString s,a;
1.129 +
1.130 + // save area, if not scrolled
1.131 + QString areaAttr=
1.132 + attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
1.133 + attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
1.134 + attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
1.135 + attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
1.136 +
1.137 + s=beginElement ("mapcenter"
1.138 + +attribut("absPosX",QString().setNum(absPos.x(),10))
1.139 + +attribut("absPosY",QString().setNum(absPos.y(),10))
1.140 + +attribut("frameType",frame->getFrameTypeName())
1.141 + +areaAttr
1.142 + );
1.143 +
1.144 + incIndent();
1.145 + if (heading->getColor()!=QColor("black"))
1.146 + a=attribut ("textColor",QColor(heading->getColor()).name() );
1.147 + else
1.148 + a="";
1.149 +
1.150 + // Save flags. If verbose is set (export to xml dir), also write
1.151 + // the flags as picture
1.152 + s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
1.153 + s=s+valueElement("heading", getHeading(),a);
1.154 +
1.155 + // Reset the counters before saving
1.156 + FloatImageObj (canvas).resetSaveCounter();
1.157 +
1.158 + // add link to file in s
1.159 + if (!note.isEmpty() )
1.160 + s+=note.saveToDir();
1.161 +
1.162 + // Save FloatImages
1.163 + FloatImageObj *fio;
1.164 + for (fio=floatimage.first(); fio; fio=floatimage.next() )
1.165 + s+=fio->saveToDir (tmpdir,prefix);
1.166 +
1.167 + // Save branches
1.168 + BranchObj *bo;
1.169 + for (bo=branch.first(); bo; bo=branch.next() )
1.170 + s+=bo->saveToDir(tmpdir,prefix, offset);
1.171 +
1.172 + decIndent();
1.173 + s+=endElement ("mapcenter");
1.174 + return s;
1.175 +}
1.176 +
1.177 +void MapCenterObj::setVersion (const QString &s)
1.178 +{
1.179 + version=s;
1.180 +}
1.181 +
1.182 +bool MapCenterObj::checkVersion ()
1.183 +{
1.184 + // returns true, if vym is able to read file regarding
1.185 + // the version set with setVersion
1.186 + QString s1=version.section (".",0,0);
1.187 + QString s2=version.section (".",1,1);
1.188 + QString s3=version.section (".",2,2);
1.189 + bool ok;
1.190 + int vv1 =QString(__VYM_VERSION__).section (".",0,0).toInt(&ok,10);
1.191 + int vv2 =QString(__VYM_VERSION__).section (".",1,1).toInt(&ok,10);
1.192 + int vv3 =QString(__VYM_VERSION__).section (".",2,2).toInt(&ok,10);
1.193 + int mv1=0;
1.194 + int mv2=0;
1.195 + int mv3=0;
1.196 + if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
1.197 + if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
1.198 + if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
1.199 +
1.200 + if (vv1 > mv1)
1.201 + return true;
1.202 + if (vv1 < mv1)
1.203 + return false;
1.204 + if (vv2 > mv2)
1.205 + return true;
1.206 + if (vv2 < mv2)
1.207 + return false;
1.208 + if (vv3 > mv3)
1.209 + return true;
1.210 + if (vv3 < mv3)
1.211 + return false;
1.212 + return true;
1.213 +}
1.214 +
1.215 +void MapCenterObj::setAuthor (const QString &s)
1.216 +{
1.217 + author=s;
1.218 +}
1.219 +
1.220 +QString MapCenterObj::getAuthor()
1.221 +{
1.222 + return author;
1.223 +}
1.224 +
1.225 +void MapCenterObj::setComment (const QString &s)
1.226 +{
1.227 + comment=s;
1.228 +}
1.229 +
1.230 +QString MapCenterObj::getComment ()
1.231 +{
1.232 + return comment;
1.233 +}
1.234 +
1.235 +QString MapCenterObj::getDate ()
1.236 +{
1.237 + return QDate::currentDate().toString ("yyyy-MM-dd");
1.238 +}