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