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