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