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