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