1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#include <QDateTime>
#include "mapcenterobj.h"
#include "floatimageobj.h"
/////////////////////////////////////////////////////////////////
// MapCenterObj
/////////////////////////////////////////////////////////////////
MapCenterObj::MapCenterObj() : BranchObj ()
{
// cout << "Const MapCenterObj\n";
init();
}
MapCenterObj::MapCenterObj(QGraphicsScene* s) : BranchObj (s)
{
// cout << "Const MapCenterObj canvas="<<s<<"\n";
init();
}
MapCenterObj::~MapCenterObj()
{
// cout << "Destr MapCenterObj\n";
}
void MapCenterObj::clear()
{
BranchObj::clear();
}
void MapCenterObj::init ()
{
BranchObj::init();
orientation=LinkableMapObj::UndefinedOrientation;
// TODO this should be done in TextObj later...
//QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");
//heading->setFont(font);
depth=0;
setDefAttr(MovedBranch);
frame->setFrameType (FrameObj::Rectangle);
}
void MapCenterObj::move (double x, double y)
{
BranchObj::move(x,y);
}
void MapCenterObj::moveBy (double x, double y)
{
BranchObj::moveBy(x,y);
}
void MapCenterObj::moveAll (double x, double y)
{
// Get rel. position
double dx=x-absPos.x();
double dy=y-absPos.y();
// Move myself and branches
moveAllBy (dx,dy);
}
void MapCenterObj::moveAllBy (double dx, double dy)
{
// Move myself and childs
BranchObj::moveBy(dx,dy);
}
void MapCenterObj::updateLink()
{
// set childPos to middle of MapCenterObj
childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
parPos=childPos;
for (int i=0; i<branch.size(); ++i)
branch.at(i)->updateLink();
}
void MapCenterObj::updateRelPositions()
{
if (repositionRequest) unsetAllRepositionRequests();
// update relative Positions of branches and floats
for (int i=0; i<branch.size(); ++i)
{
branch.at(i)->setRelPos();
branch.at(i)->setOrientation();
}
for (int i=0; i<floatimage.size(); ++i)
floatimage.at(i)->setRelPos();
if (repositionRequest) reposition();
}
LinkableMapObj* MapCenterObj::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
{
LinkableMapObj *lmo;
// Search through child branches
for (int i=0; i<branch.size(); ++i)
{
lmo = branch.at(i)->findMapObj(p, excludeLMO);
if (lmo!= NULL) return lmo;
}
// is p in MapCenter?
if (inBox (p) && (this != excludeLMO) ) return this;
// Search float images
for (int i=0; i<floatimage.size(); ++i)
if (floatimage.at(i)->inBox(p) && (floatimage.at(i) != excludeLMO) && floatimage.at(i)->getParObj()!= excludeLMO) return floatimage.at(i);
// nothing found
return NULL;
}
QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
{
QString s,a;
// save area, if not scrolled
QString areaAttr=
attribut("x1",QString().setNum(absPos.x()-offset.x())) +
attribut("y1",QString().setNum(absPos.y()-offset.y())) +
attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
// Providing an ID for a branch makes export to XHTML easier
QString idAttr;
if (countXLinks()>0)
idAttr=attribut ("id",getSelectString());
else
idAttr="";
QString linkAttr=getLinkAttr();
s=beginElement ("mapcenter"
+getOrnAttr()
+areaAttr
+idAttr
+getIncludeImageAttr() );
incIndent();
if (heading->getColor()!=QColor("black"))
a=attribut ("textColor",QColor(heading->getColor()).name() );
else
a="";
// Save flags. If verbose is set (export to xml dir), also write
// the flags as picture
s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
// Save heading
s+=valueElement("heading", getHeading(),a);
// Save frame
s+=frame->saveToDir ();
// add link to file in s
if (!note.isEmpty() )
s+=note.saveToDir();
// Save branches
for (int i=0; i<branch.size(); ++i)
s+=branch.at(i)->saveToDir(tmpdir,prefix, offset);
// Save FloatImages
for (int i=0; i<floatimage.size(); ++i)
s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
// Save XLinks
for (int i=0;i<xlink.size(); ++i)
s+=xlink.at(i)->saveToDir();
decIndent();
s+=endElement ("mapcenter");
return s;
}
void MapCenterObj::setVersion (const QString &s)
{
version=s;
}
void MapCenterObj::setAuthor (const QString &s)
{
author=s;
}
QString MapCenterObj::getAuthor()
{
return author;
}
void MapCenterObj::setComment (const QString &s)
{
comment=s;
}
QString MapCenterObj::getComment ()
{
return comment;
}
QString MapCenterObj::getDate ()
{
return QDate::currentDate().toString ("yyyy-MM-dd");
}
|