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