mapcenterobj.cpp
author insilmaril
Tue, 24 Jan 2006 15:09:49 +0000
changeset 193 544a64d7cbac
parent 181 bd530b01f77f
child 239 bdeb503d2b7f
permissions -rw-r--r--
Introduced basic export to Open Document format
insilmaril@0
     1
#include <qdatetime.h>
insilmaril@0
     2
insilmaril@0
     3
#include "mapcenterobj.h"
insilmaril@0
     4
#include "floatimageobj.h"
insilmaril@0
     5
#include "mapeditor.h"
insilmaril@0
     6
insilmaril@0
     7
/////////////////////////////////////////////////////////////////
insilmaril@0
     8
// MapCenterObj
insilmaril@0
     9
/////////////////////////////////////////////////////////////////
insilmaril@0
    10
MapCenterObj::MapCenterObj() : BranchObj ()
insilmaril@0
    11
{
insilmaril@0
    12
//    cout << "Const MapCenterObj\n";
insilmaril@0
    13
    init();
insilmaril@0
    14
}
insilmaril@0
    15
insilmaril@0
    16
MapCenterObj::MapCenterObj(QCanvas* c) : BranchObj (c)
insilmaril@0
    17
{
insilmaril@0
    18
//    cout << "Const MapCenterObj   canvas="<<c<<"\n";
insilmaril@0
    19
    init();
insilmaril@0
    20
}
insilmaril@0
    21
insilmaril@0
    22
MapCenterObj::~MapCenterObj() 
insilmaril@0
    23
{
insilmaril@0
    24
//    cout << "Destr MapCenterObj\n";
insilmaril@0
    25
}	
insilmaril@0
    26
insilmaril@0
    27
void MapCenterObj::clear() 
insilmaril@0
    28
{
insilmaril@0
    29
	BranchObj::clear();
insilmaril@0
    30
}
insilmaril@0
    31
insilmaril@0
    32
void MapCenterObj::init () 
insilmaril@0
    33
{
insilmaril@83
    34
	BranchObj::init();
insilmaril@0
    35
    orientation=OrientUndef;
insilmaril@0
    36
insilmaril@0
    37
	// FIXME this should be done in TextObj later...
insilmaril@164
    38
	//QFont font ("Sans Serif,16,-1,5,50,0,0,0,0,0");		
insilmaril@164
    39
	//heading->setFont(font);
insilmaril@164
    40
	depth=0;
insilmaril@164
    41
	setDefAttr(MovedBranch);
insilmaril@0
    42
insilmaril@0
    43
	frame->setFrameType (Rectangle);
insilmaril@0
    44
}
insilmaril@0
    45
insilmaril@0
    46
void MapCenterObj::move (double x, double y)
insilmaril@0
    47
{
insilmaril@0
    48
	BranchObj::move(x,y);
insilmaril@0
    49
}
insilmaril@0
    50
insilmaril@0
    51
void MapCenterObj::moveBy (double x, double y)
insilmaril@0
    52
{
insilmaril@169
    53
	BranchObj::moveBy(x,y);
insilmaril@0
    54
	positionBBox();
insilmaril@0
    55
}
insilmaril@0
    56
insilmaril@0
    57
void MapCenterObj::moveAll (double x, double y)
insilmaril@0
    58
{
insilmaril@0
    59
	// Get rel. position
insilmaril@0
    60
	double dx=x-absPos.x();
insilmaril@0
    61
	double dy=y-absPos.y();
insilmaril@0
    62
insilmaril@0
    63
	// Move myself and branches
insilmaril@0
    64
	moveAllBy (dx,dy);
insilmaril@0
    65
}
insilmaril@0
    66
insilmaril@0
    67
void MapCenterObj::moveAllBy (double dx, double dy)
insilmaril@0
    68
{
insilmaril@0
    69
	// Move myself
insilmaril@0
    70
	moveBy(dx,dy);
insilmaril@0
    71
insilmaril@0
    72
	positionBBox();
insilmaril@0
    73
}
insilmaril@0
    74
insilmaril@0
    75
void MapCenterObj::updateLink()
insilmaril@0
    76
{
insilmaril@0
    77
	// set childPos to middle of MapCenterObj
insilmaril@169
    78
	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
insilmaril@169
    79
	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
insilmaril@0
    80
	parPos=childPos;		
insilmaril@0
    81
	BranchObj *b;
insilmaril@0
    82
	for (b=branch.first(); b; b=branch.next() )
insilmaril@0
    83
		b->updateLink();
insilmaril@0
    84
}
insilmaril@0
    85
insilmaril@0
    86
LinkableMapObj* MapCenterObj::findMapObj(QPoint p, LinkableMapObj *excludeLMO)
insilmaril@0
    87
	{
insilmaril@0
    88
	BranchObj *bo;
insilmaril@0
    89
	LinkableMapObj *lmo;
insilmaril@0
    90
insilmaril@0
    91
	// Search through child branches
insilmaril@0
    92
	for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@0
    93
	{	
insilmaril@0
    94
		lmo = bo->findMapObj(p, excludeLMO);
insilmaril@169
    95
		if (lmo!= NULL) return lmo;
insilmaril@0
    96
	}
insilmaril@0
    97
	// is p in MapCenter?
insilmaril@169
    98
	if (inBox (p) && (this != excludeLMO) ) return this;
insilmaril@0
    99
insilmaril@0
   100
	// Search float images
insilmaril@0
   101
	FloatImageObj *foi;
insilmaril@0
   102
	for (foi=floatimage.first(); foi; foi=floatimage.next() )
insilmaril@169
   103
		if (foi->inBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
insilmaril@0
   104
insilmaril@0
   105
	// nothing found
insilmaril@0
   106
	return NULL;
insilmaril@0
   107
}
insilmaril@0
   108
insilmaril@0
   109
QString MapCenterObj::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPoint &offset)
insilmaril@0
   110
{
insilmaril@0
   111
    QString s,a;
insilmaril@0
   112
insilmaril@0
   113
	// save area, if not scrolled
insilmaril@0
   114
	QString areaAttr=
insilmaril@0
   115
		attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
insilmaril@0
   116
		attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
insilmaril@0
   117
		attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
insilmaril@0
   118
		attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
insilmaril@0
   119
	
insilmaril@169
   120
	// Providing an ID for a branch makes export to XHTML easier
insilmaril@169
   121
	QString idAttr;
insilmaril@169
   122
	if (countXLinks()>0)
insilmaril@169
   123
		idAttr=attribut ("id",getSelectString());
insilmaril@169
   124
	else
insilmaril@169
   125
		idAttr="";
insilmaril@169
   126
insilmaril@169
   127
	QString linkAttr=getLinkAttr();
insilmaril@169
   128
insilmaril@169
   129
	QString urlAttr;
insilmaril@169
   130
	if (!url.isEmpty())
insilmaril@169
   131
		urlAttr=attribut ("url",url);
insilmaril@169
   132
	QString vymLinkAttr;
insilmaril@169
   133
	if (!vymLink.isEmpty())
insilmaril@169
   134
		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
insilmaril@169
   135
insilmaril@0
   136
    s=beginElement ("mapcenter" 
insilmaril@0
   137
		+attribut("absPosX",QString().setNum(absPos.x(),10))
insilmaril@0
   138
		+attribut("absPosY",QString().setNum(absPos.y(),10))
insilmaril@169
   139
		+vymLinkAttr
insilmaril@169
   140
		+urlAttr
insilmaril@169
   141
		+linkAttr
insilmaril@169
   142
		+idAttr
insilmaril@0
   143
		+attribut("frameType",frame->getFrameTypeName()) 
insilmaril@0
   144
		+areaAttr 
insilmaril@0
   145
		);
insilmaril@0
   146
		
insilmaril@0
   147
    incIndent();
insilmaril@0
   148
    if (heading->getColor()!=QColor("black"))
insilmaril@0
   149
		a=attribut ("textColor",QColor(heading->getColor()).name() );
insilmaril@0
   150
    else	
insilmaril@0
   151
		a="";
insilmaril@0
   152
    
insilmaril@0
   153
	// Save flags. If verbose is set (export to xml dir), also write
insilmaril@0
   154
	// the flags as picture
insilmaril@0
   155
	s+=standardFlags->saveToDir(tmpdir+"/flags", "/standardFlag-", verbose);
insilmaril@0
   156
    s=s+valueElement("heading", getHeading(),a);
insilmaril@0
   157
insilmaril@0
   158
	// add link to file in s
insilmaril@0
   159
	if (!note.isEmpty() )
insilmaril@0
   160
		s+=note.saveToDir();
insilmaril@0
   161
	
insilmaril@95
   162
	// Save branches
insilmaril@95
   163
    BranchObj *bo;
insilmaril@95
   164
    for (bo=branch.first(); bo; bo=branch.next() )
insilmaril@95
   165
		s+=bo->saveToDir(tmpdir,prefix, offset);
insilmaril@95
   166
insilmaril@0
   167
	// Save FloatImages
insilmaril@0
   168
	FloatImageObj *fio;
insilmaril@0
   169
	for (fio=floatimage.first(); fio; fio=floatimage.next() )
insilmaril@166
   170
		s+=fio->saveToDir (tmpdir,prefix,offset);
insilmaril@0
   171
insilmaril@95
   172
	// Save XLinks
insilmaril@95
   173
	XLinkObj *xlo;
insilmaril@95
   174
    for (xlo=xlink.first(); xlo; xlo=xlink.next() )
insilmaril@95
   175
		s+=xlo->saveToDir();
insilmaril@0
   176
insilmaril@0
   177
    decIndent();
insilmaril@0
   178
    s+=endElement   ("mapcenter");
insilmaril@0
   179
    return s;
insilmaril@0
   180
}
insilmaril@0
   181
insilmaril@0
   182
void MapCenterObj::setVersion (const QString &s)
insilmaril@0
   183
{
insilmaril@0
   184
	version=s;
insilmaril@0
   185
}
insilmaril@0
   186
insilmaril@0
   187
bool MapCenterObj::checkVersion ()
insilmaril@0
   188
{
insilmaril@0
   189
	// returns true, if vym is able to read file regarding 
insilmaril@0
   190
	// the version set with setVersion
insilmaril@0
   191
	QString s1=version.section (".",0,0);
insilmaril@0
   192
	QString s2=version.section (".",1,1);
insilmaril@0
   193
	QString s3=version.section (".",2,2);
insilmaril@0
   194
	bool ok;
insilmaril@181
   195
	int vv1 =QString(__VYM_VERSION).section (".",0,0).toInt(&ok,10);
insilmaril@181
   196
	int vv2 =QString(__VYM_VERSION).section (".",1,1).toInt(&ok,10);
insilmaril@181
   197
	int vv3 =QString(__VYM_VERSION).section (".",2,2).toInt(&ok,10);
insilmaril@0
   198
	int mv1=0;
insilmaril@0
   199
	int mv2=0;
insilmaril@0
   200
	int mv3=0;
insilmaril@0
   201
	if (!s1.isEmpty() ) mv1=s1.toInt(&ok,10);
insilmaril@0
   202
	if (!s2.isEmpty() ) mv2=s2.toInt(&ok,10);
insilmaril@0
   203
	if (!s3.isEmpty() ) mv3=s3.toInt(&ok,10);
insilmaril@0
   204
	
insilmaril@0
   205
	if (vv1 > mv1)
insilmaril@0
   206
		return true;
insilmaril@0
   207
	if (vv1 < mv1)
insilmaril@0
   208
		return false;
insilmaril@0
   209
	if (vv2 > mv2)
insilmaril@0
   210
		return true;
insilmaril@0
   211
	if (vv2 < mv2)
insilmaril@0
   212
		return false;
insilmaril@0
   213
	if (vv3 > mv3)
insilmaril@0
   214
		return true;
insilmaril@0
   215
	if (vv3 < mv3)
insilmaril@0
   216
		return false;
insilmaril@0
   217
	return true;	
insilmaril@0
   218
}
insilmaril@0
   219
insilmaril@0
   220
void MapCenterObj::setAuthor (const QString &s)
insilmaril@0
   221
{
insilmaril@0
   222
	author=s;
insilmaril@0
   223
}
insilmaril@0
   224
insilmaril@0
   225
QString MapCenterObj::getAuthor()
insilmaril@0
   226
{
insilmaril@0
   227
	return author;
insilmaril@0
   228
}
insilmaril@0
   229
insilmaril@0
   230
void MapCenterObj::setComment (const QString &s)
insilmaril@0
   231
{
insilmaril@0
   232
	comment=s;
insilmaril@0
   233
}
insilmaril@0
   234
insilmaril@0
   235
QString MapCenterObj::getComment ()
insilmaril@0
   236
{
insilmaril@0
   237
	return comment;
insilmaril@0
   238
}
insilmaril@0
   239
insilmaril@0
   240
QString MapCenterObj::getDate ()
insilmaril@0
   241
{
insilmaril@0
   242
	return QDate::currentDate().toString ("yyyy-MM-dd");
insilmaril@0
   243
}
insilmaril@83
   244