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