mapcenterobj.cpp
author insilmaril
Tue, 07 Mar 2006 11:32:00 +0000
changeset 228 654ad4b03c5a
parent 181 bd530b01f77f
child 239 bdeb503d2b7f
permissions -rw-r--r--
Added xsl for Taskjuggler Export by Matt
     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 	QString urlAttr;
   130 	if (!url.isEmpty())
   131 		urlAttr=attribut ("url",url);
   132 	QString vymLinkAttr;
   133 	if (!vymLink.isEmpty())
   134 		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   135 
   136     s=beginElement ("mapcenter" 
   137 		+attribut("absPosX",QString().setNum(absPos.x(),10))
   138 		+attribut("absPosY",QString().setNum(absPos.y(),10))
   139 		+vymLinkAttr
   140 		+urlAttr
   141 		+linkAttr
   142 		+idAttr
   143 		+attribut("frameType",frame->getFrameTypeName()) 
   144 		+areaAttr 
   145 		);
   146 		
   147     incIndent();
   148     if (heading->getColor()!=QColor("black"))
   149 		a=attribut ("textColor",QColor(heading->getColor()).name() );
   150     else	
   151 		a="";
   152     
   153 	// Save flags. If verbose is set (export to xml dir), also write
   154 	// the flags as picture
   155 	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
   156     s=s+valueElement("heading", getHeading(),a);
   157 
   158 	// add link to file in s
   159 	if (!note.isEmpty() )
   160 		s+=note.saveToDir();
   161 	
   162 	// Save branches
   163     BranchObj *bo;
   164     for (bo=branch.first(); bo; bo=branch.next() )
   165 		s+=bo->saveToDir(tmpdir,prefix, offset);
   166 
   167 	// Save FloatImages
   168 	FloatImageObj *fio;
   169 	for (fio=floatimage.first(); fio; fio=floatimage.next() )
   170 		s+=fio->saveToDir (tmpdir,prefix,offset);
   171 
   172 	// Save XLinks
   173 	XLinkObj *xlo;
   174     for (xlo=xlink.first(); xlo; xlo=xlink.next() )
   175 		s+=xlo->saveToDir();
   176 
   177     decIndent();
   178     s+=endElement   ("mapcenter");
   179     return s;
   180 }
   181 
   182 void MapCenterObj::setVersion (const QString &s)
   183 {
   184 	version=s;
   185 }
   186 
   187 bool MapCenterObj::checkVersion ()
   188 {
   189 	// returns true, if vym is able to read file regarding 
   190 	// the version set with setVersion
   191 	QString s1=version.section (".",0,0);
   192 	QString s2=version.section (".",1,1);
   193 	QString s3=version.section (".",2,2);
   194 	bool ok;
   195 	int vv1 =QString(__VYM_VERSION).section (".",0,0).toInt(&ok,10);
   196 	int vv2 =QString(__VYM_VERSION).section (".",1,1).toInt(&ok,10);
   197 	int vv3 =QString(__VYM_VERSION).section (".",2,2).toInt(&ok,10);
   198 	int mv1=0;
   199 	int mv2=0;
   200 	int mv3=0;
   201 	if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
   202 	if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
   203 	if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
   204 	
   205 	if (vv1 > mv1)
   206 		return true;
   207 	if (vv1 < mv1)
   208 		return false;
   209 	if (vv2 > mv2)
   210 		return true;
   211 	if (vv2 < mv2)
   212 		return false;
   213 	if (vv3 > mv3)
   214 		return true;
   215 	if (vv3 < mv3)
   216 		return false;
   217 	return true;	
   218 }
   219 
   220 void MapCenterObj::setAuthor (const QString &s)
   221 {
   222 	author=s;
   223 }
   224 
   225 QString MapCenterObj::getAuthor()
   226 {
   227 	return author;
   228 }
   229 
   230 void MapCenterObj::setComment (const QString &s)
   231 {
   232 	comment=s;
   233 }
   234 
   235 QString MapCenterObj::getComment ()
   236 {
   237 	return comment;
   238 }
   239 
   240 QString MapCenterObj::getDate ()
   241 {
   242 	return QDate::currentDate().toString ("yyyy-MM-dd");
   243 }
   244