linkablemapobj.cpp
author insilmaril
Mon, 04 Aug 2008 13:35:54 +0000
changeset 724 cf14046909cd
parent 723 11f9124c1cca
child 726 7f43b93242aa
permissions -rw-r--r--
Adding/moving MCO works again
insilmaril@721
     1
#include <iostream>
insilmaril@139
     2
#include <math.h>
insilmaril@139
     3
insilmaril@0
     4
#include "linkablemapobj.h"
insilmaril@0
     5
#include "branchobj.h"
insilmaril@721
     6
#include "vymmodel.h"
insilmaril@721
     7
insilmaril@721
     8
using namespace std;
insilmaril@0
     9
insilmaril@0
    10
/////////////////////////////////////////////////////////////////
insilmaril@0
    11
// LinkableMapObj
insilmaril@0
    12
/////////////////////////////////////////////////////////////////
insilmaril@0
    13
insilmaril@0
    14
LinkableMapObj::LinkableMapObj():MapObj()
insilmaril@0
    15
{
insilmaril@0
    16
  //  cout << "Const LinkableMapObj ()\n";
insilmaril@0
    17
    init ();
insilmaril@0
    18
}
insilmaril@0
    19
insilmaril@408
    20
LinkableMapObj::LinkableMapObj(QGraphicsScene* s) :MapObj(s)
insilmaril@0
    21
{
insilmaril@408
    22
//    cout << "Const LinkableMapObj (s)\n";
insilmaril@0
    23
    init ();
insilmaril@0
    24
}
insilmaril@0
    25
insilmaril@408
    26
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
insilmaril@0
    27
{
insilmaril@0
    28
    copy (lmo);
insilmaril@0
    29
}
insilmaril@0
    30
insilmaril@0
    31
LinkableMapObj::~LinkableMapObj()
insilmaril@0
    32
{
insilmaril@0
    33
    delete (bottomline);
insilmaril@0
    34
	delLink();
insilmaril@0
    35
}
insilmaril@0
    36
insilmaril@0
    37
void LinkableMapObj::delLink()
insilmaril@0
    38
{
insilmaril@0
    39
	switch (style)
insilmaril@0
    40
	{
insilmaril@473
    41
		case Line:
insilmaril@0
    42
			delete (l);
insilmaril@0
    43
			break;
insilmaril@473
    44
		case Parabel:
insilmaril@406
    45
			while (!segment.isEmpty()) delete segment.takeFirst();
insilmaril@0
    46
			break;
insilmaril@473
    47
		case PolyLine:
insilmaril@0
    48
			delete (p);
insilmaril@0
    49
			break;
insilmaril@473
    50
		case PolyParabel:
insilmaril@0
    51
			delete (p);
insilmaril@0
    52
			break;
insilmaril@0
    53
		default:
insilmaril@0
    54
			break;
insilmaril@0
    55
	}		
insilmaril@0
    56
}
insilmaril@0
    57
insilmaril@0
    58
void LinkableMapObj::init ()
insilmaril@0
    59
{
insilmaril@721
    60
	model=NULL;
insilmaril@721
    61
insilmaril@0
    62
    depth=-1;	
insilmaril@164
    63
	mapEditor=NULL;
insilmaril@0
    64
    childObj=NULL;
insilmaril@0
    65
    parObj=NULL;
insilmaril@0
    66
    parObjTmpBuf=NULL;
insilmaril@408
    67
    parPos=QPointF(0,0);
insilmaril@408
    68
    childPos=QPointF(0,0);
insilmaril@0
    69
	link2ParPos=false;
insilmaril@0
    70
    l=NULL;
insilmaril@473
    71
    orientation=UndefinedOrientation;
insilmaril@0
    72
    linkwidth=20;		
insilmaril@0
    73
	thickness_start=8;
insilmaril@473
    74
    style=UndefinedStyle;
insilmaril@473
    75
	linkpos=Bottom;
insilmaril@0
    76
    arcsegs=13;
insilmaril@0
    77
    
insilmaril@412
    78
// TODO instead of linkcolor pen.color() could be used	all around
insilmaril@408
    79
	pen.setWidth (1);
insilmaril@408
    80
	pen.setColor (linkcolor);
insilmaril@408
    81
	pen.setCapStyle ( Qt::RoundCap );
insilmaril@408
    82
	bottomline=scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
    83
    bottomline->setZValue(Z_LINK);
insilmaril@0
    84
    bottomline->show();
insilmaril@0
    85
insilmaril@0
    86
    // Prepare showing the selection of a MapObj
insilmaril@0
    87
    selected=false;
insilmaril@0
    88
insilmaril@160
    89
	hideLinkUnselected=false;
insilmaril@160
    90
insilmaril@175
    91
	topPad=botPad=leftPad=rightPad=0;
insilmaril@175
    92
insilmaril@0
    93
	repositionRequest=false;
insilmaril@218
    94
insilmaril@218
    95
	// Rel Positions
insilmaril@408
    96
	relPos=QPointF(0,0);
insilmaril@250
    97
	useRelPos=false;
insilmaril@218
    98
	useOrientation=true;
insilmaril@531
    99
insilmaril@531
   100
	// Reset ID
insilmaril@594
   101
	objID="";
insilmaril@0
   102
}
insilmaril@0
   103
insilmaril@0
   104
void LinkableMapObj::copy (LinkableMapObj* other)
insilmaril@0
   105
{
insilmaril@0
   106
    MapObj::copy(other);
insilmaril@721
   107
	model=other->model;
insilmaril@0
   108
	bboxTotal=other->bboxTotal;
insilmaril@0
   109
    setLinkStyle(other->style);
insilmaril@0
   110
    setLinkColor (other->linkcolor);
insilmaril@218
   111
	relPos=other->relPos;
insilmaril@218
   112
	useOrientation=other->useOrientation;
insilmaril@594
   113
	objID=other->objID;
insilmaril@0
   114
}
insilmaril@0
   115
insilmaril@721
   116
void LinkableMapObj::setModel (VymModel *vm)
insilmaril@721
   117
{
insilmaril@721
   118
	model=vm;
insilmaril@721
   119
}
insilmaril@721
   120
insilmaril@721
   121
VymModel* LinkableMapObj::getModel()
insilmaril@721
   122
{
insilmaril@721
   123
	return model;
insilmaril@721
   124
}
insilmaril@721
   125
insilmaril@0
   126
void LinkableMapObj::setChildObj(LinkableMapObj* o)
insilmaril@0
   127
{
insilmaril@0
   128
    childObj=o;
insilmaril@0
   129
}
insilmaril@0
   130
insilmaril@0
   131
void LinkableMapObj::setParObj(LinkableMapObj* o)
insilmaril@0
   132
{
insilmaril@0
   133
    parObj=o;
insilmaril@0
   134
	mapEditor=parObj->getMapEditor();
insilmaril@723
   135
	model=parObj->getModel();	
insilmaril@0
   136
}
insilmaril@0
   137
insilmaril@721
   138
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)	// FIXME make pure virtual
insilmaril@0
   139
{
insilmaril@0
   140
}
insilmaril@0
   141
insilmaril@721
   142
void LinkableMapObj::unsetParObjTmp()	// FIXME make pure virtual
insilmaril@0
   143
{
insilmaril@0
   144
}
insilmaril@0
   145
insilmaril@164
   146
bool LinkableMapObj::hasParObjTmp()
insilmaril@164
   147
{
insilmaril@164
   148
	if (parObjTmpBuf) return true;
insilmaril@164
   149
	return false;
insilmaril@164
   150
}
insilmaril@164
   151
insilmaril@218
   152
void LinkableMapObj::setUseRelPos (const bool &b)
insilmaril@218
   153
{
insilmaril@218
   154
	useRelPos=b;
insilmaril@218
   155
}
insilmaril@218
   156
insilmaril@218
   157
void LinkableMapObj::setRelPos()
insilmaril@218
   158
{
insilmaril@218
   159
	if (parObj)
insilmaril@218
   160
	{	
insilmaril@395
   161
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@395
   162
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@218
   163
		parObj->calcBBoxSize();
insilmaril@494
   164
	}	
insilmaril@218
   165
}
insilmaril@218
   166
insilmaril@408
   167
void LinkableMapObj::setRelPos(const QPointF &p)
insilmaril@218
   168
{
insilmaril@218
   169
	relPos=p;
insilmaril@218
   170
	if (parObj)
insilmaril@388
   171
	{		
insilmaril@388
   172
		parObj->calcBBoxSize();
insilmaril@388
   173
		requestReposition();
insilmaril@395
   174
	}
insilmaril@218
   175
}
insilmaril@218
   176
insilmaril@408
   177
QPointF LinkableMapObj::getRelPos()
insilmaril@366
   178
{
insilmaril@408
   179
	if (!parObj) return QPointF();
insilmaril@366
   180
	return relPos;
insilmaril@366
   181
}
insilmaril@366
   182
insilmaril@408
   183
qreal LinkableMapObj::getTopPad()
insilmaril@175
   184
{
insilmaril@175
   185
	return topPad;
insilmaril@175
   186
}
insilmaril@175
   187
insilmaril@408
   188
qreal LinkableMapObj::getLeftPad()
insilmaril@175
   189
{
insilmaril@175
   190
	return leftPad;
insilmaril@175
   191
}
insilmaril@175
   192
insilmaril@408
   193
qreal LinkableMapObj::getRightPad()
insilmaril@175
   194
{
insilmaril@175
   195
	return rightPad;
insilmaril@175
   196
}
insilmaril@175
   197
insilmaril@473
   198
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle ()
insilmaril@0
   199
{
insilmaril@721
   200
	if (!model)
insilmaril@721
   201
	{
insilmaril@721
   202
		qWarning ("LMO::getDefLinkStyle   model=NULL");
insilmaril@721
   203
		return UndefinedStyle;
insilmaril@721
   204
	}
insilmaril@721
   205
	Style ls=model->getMapLinkStyle();
insilmaril@0
   206
	switch (ls)
insilmaril@0
   207
	{
insilmaril@473
   208
		case Line: 
insilmaril@0
   209
			return ls;
insilmaril@0
   210
			break;
insilmaril@473
   211
		case Parabel:
insilmaril@0
   212
			return ls;
insilmaril@0
   213
			break;
insilmaril@473
   214
		case PolyLine:	
insilmaril@0
   215
			if (depth>1)
insilmaril@473
   216
				return Line;
insilmaril@0
   217
			else	
insilmaril@0
   218
				return ls;
insilmaril@0
   219
			break;
insilmaril@473
   220
		case PolyParabel:	
insilmaril@0
   221
			if (depth>1)
insilmaril@473
   222
				return Parabel;
insilmaril@0
   223
			else	
insilmaril@0
   224
				return ls;
insilmaril@0
   225
			break;
insilmaril@0
   226
		default: 
insilmaril@0
   227
			break;	
insilmaril@0
   228
	}	
insilmaril@473
   229
	return UndefinedStyle;
insilmaril@0
   230
}
insilmaril@0
   231
insilmaril@473
   232
void LinkableMapObj::setLinkStyle(Style newstyle)
insilmaril@0
   233
{
insilmaril@83
   234
	//if (newstyle=style) return;
insilmaril@0
   235
	delLink();
insilmaril@0
   236
		
insilmaril@0
   237
	style=newstyle;
insilmaril@0
   238
insilmaril@0
   239
    if (childObj!=NULL && parObj != NULL)
insilmaril@0
   240
    {
insilmaril@408
   241
		QGraphicsLineItem *cl;
insilmaril@0
   242
		switch (style)
insilmaril@0
   243
		{
insilmaril@473
   244
			case UndefinedStyle:
insilmaril@0
   245
				bottomline->hide();
insilmaril@0
   246
				break;
insilmaril@473
   247
			case Line: 
insilmaril@408
   248
				l = scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
   249
				l->setZValue(Z_LINK);
insilmaril@0
   250
				if (visible)
insilmaril@0
   251
					l->show();
insilmaril@0
   252
				else
insilmaril@0
   253
					l->hide();
insilmaril@0
   254
				break;
insilmaril@473
   255
			case Parabel:
insilmaril@408
   256
				for (int i=0;i<arcsegs;i++)
insilmaril@0
   257
				{
insilmaril@408
   258
					cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
insilmaril@408
   259
					cl->setZValue(Z_LINK);
insilmaril@0
   260
					if (visible)
insilmaril@0
   261
						cl->show();
insilmaril@0
   262
					else
insilmaril@0
   263
						cl->hide();
insilmaril@0
   264
					segment.append(cl);
insilmaril@0
   265
				}
insilmaril@0
   266
				pa0.resize (arcsegs+1);
insilmaril@0
   267
				break;
insilmaril@473
   268
			case PolyLine:	
insilmaril@408
   269
				p =scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   270
				p->setZValue(Z_LINK);
insilmaril@0
   271
				if (visible)
insilmaril@0
   272
					p->show();
insilmaril@0
   273
				else
insilmaril@0
   274
					p->hide();
insilmaril@0
   275
				pa0.resize (3);
insilmaril@0
   276
				break;
insilmaril@473
   277
			case PolyParabel:	
insilmaril@408
   278
				p = scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   279
				p->setZValue(Z_LINK);
insilmaril@0
   280
				if (visible)
insilmaril@0
   281
					p->show();
insilmaril@0
   282
				else
insilmaril@0
   283
					p->hide();
insilmaril@0
   284
				pa0.resize (arcsegs*2+2);
insilmaril@0
   285
				pa1.resize (arcsegs+1);
insilmaril@0
   286
				pa2.resize (arcsegs+1);
insilmaril@0
   287
				break;
insilmaril@0
   288
			default: 
insilmaril@0
   289
				break;	
insilmaril@0
   290
		}	
insilmaril@164
   291
	} 
insilmaril@0
   292
}
insilmaril@0
   293
insilmaril@473
   294
LinkableMapObj::Style LinkableMapObj::getLinkStyle()
insilmaril@0
   295
{
insilmaril@0
   296
	return style;
insilmaril@0
   297
}
insilmaril@0
   298
insilmaril@160
   299
void LinkableMapObj::setHideLinkUnselected(bool b)
insilmaril@160
   300
{
insilmaril@160
   301
	hideLinkUnselected=b;
insilmaril@160
   302
	setVisibility (visible);
insilmaril@160
   303
	updateLink();
insilmaril@160
   304
}
insilmaril@160
   305
insilmaril@160
   306
bool LinkableMapObj::getHideLinkUnselected()
insilmaril@160
   307
{
insilmaril@160
   308
	return hideLinkUnselected;
insilmaril@160
   309
}
insilmaril@160
   310
insilmaril@473
   311
void LinkableMapObj::setLinkPos(Position lp)
insilmaril@0
   312
{
insilmaril@0
   313
	linkpos=lp;
insilmaril@0
   314
}
insilmaril@0
   315
insilmaril@473
   316
LinkableMapObj::Position LinkableMapObj::getLinkPos()
insilmaril@0
   317
{
insilmaril@0
   318
	return linkpos;
insilmaril@0
   319
}
insilmaril@0
   320
insilmaril@531
   321
void LinkableMapObj::setID (const QString &s)
insilmaril@531
   322
{
insilmaril@594
   323
	objID=s;
insilmaril@531
   324
}
insilmaril@531
   325
insilmaril@531
   326
QString LinkableMapObj::getID()
insilmaril@531
   327
{
insilmaril@594
   328
	return objID;
insilmaril@531
   329
}
insilmaril@0
   330
insilmaril@0
   331
void LinkableMapObj::setLinkColor()
insilmaril@0
   332
{
insilmaril@721
   333
	// Overloaded in BranchObj and children
insilmaril@0
   334
	// here only set default color
insilmaril@721
   335
	if (model)
insilmaril@721
   336
		setLinkColor (model->getMapDefLinkColor());
insilmaril@0
   337
}
insilmaril@0
   338
insilmaril@0
   339
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   340
{
insilmaril@0
   341
	linkcolor=col;
insilmaril@408
   342
	pen.setColor(col);
insilmaril@408
   343
    bottomline->setPen( pen );
insilmaril@0
   344
	switch (style)
insilmaril@0
   345
	{
insilmaril@473
   346
		case Line:
insilmaril@408
   347
			l->setPen( pen);
insilmaril@0
   348
			break;	
insilmaril@473
   349
		case Parabel:	
insilmaril@406
   350
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   351
				segment.at(i)->setPen( pen);
insilmaril@0
   352
			break;
insilmaril@473
   353
		case PolyLine:
insilmaril@0
   354
			p->setBrush( QBrush(col));
insilmaril@497
   355
			p->setPen( pen);
insilmaril@0
   356
			break;
insilmaril@473
   357
		case PolyParabel:	
insilmaril@0
   358
			p->setBrush( QBrush(col));
insilmaril@497
   359
			p->setPen( pen);
insilmaril@0
   360
			break;
insilmaril@0
   361
		default:
insilmaril@0
   362
			break;
insilmaril@0
   363
	} // switch (style)	
insilmaril@0
   364
}
insilmaril@0
   365
insilmaril@0
   366
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   367
{
insilmaril@0
   368
	return linkcolor;
insilmaril@0
   369
}
insilmaril@0
   370
insilmaril@0
   371
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   372
{
insilmaril@0
   373
	MapObj::setVisibility (v);
insilmaril@160
   374
	bool visnow=visible;
insilmaril@260
   375
insilmaril@260
   376
	// We can hide the link, while object is not selected
insilmaril@160
   377
	if (hideLinkUnselected && !selected)
insilmaril@160
   378
		visnow=false;
insilmaril@160
   379
insilmaril@160
   380
	if (visnow) 
insilmaril@0
   381
	{
insilmaril@0
   382
		bottomline->show();
insilmaril@160
   383
		switch (style)
insilmaril@0
   384
		{
insilmaril@473
   385
			case Line:
insilmaril@160
   386
				if (l) l->show();
insilmaril@160
   387
				break;
insilmaril@473
   388
			case Parabel:	
insilmaril@406
   389
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   390
					segment.at(i)->show();
insilmaril@160
   391
				break;	
insilmaril@473
   392
			case PolyLine:
insilmaril@160
   393
				if (p) p->show();
insilmaril@160
   394
				break;
insilmaril@473
   395
			case PolyParabel:	
insilmaril@160
   396
				if (p) p->show();
insilmaril@160
   397
				break;
insilmaril@160
   398
			default:
insilmaril@160
   399
				break;
insilmaril@160
   400
		}
insilmaril@0
   401
	} else 
insilmaril@0
   402
	{
insilmaril@0
   403
		bottomline->hide();
insilmaril@160
   404
		switch (style)
insilmaril@0
   405
		{
insilmaril@473
   406
			case Line:
insilmaril@160
   407
				if (l) l->hide();
insilmaril@160
   408
				break;
insilmaril@473
   409
			case Parabel:	
insilmaril@406
   410
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   411
					segment.at(i)->hide();
insilmaril@160
   412
				break;	
insilmaril@473
   413
			case PolyLine:
insilmaril@160
   414
				if (p) p->hide();
insilmaril@160
   415
				break;
insilmaril@473
   416
			case PolyParabel:	
insilmaril@160
   417
				if (p) p->hide();
insilmaril@160
   418
				break;
insilmaril@160
   419
			default:
insilmaril@160
   420
				break;
insilmaril@160
   421
		}
insilmaril@0
   422
	}	
insilmaril@0
   423
}
insilmaril@0
   424
insilmaril@388
   425
void LinkableMapObj::setOrientation()
insilmaril@388
   426
{
insilmaril@473
   427
	Orientation orientOld=orientation;
insilmaril@388
   428
insilmaril@388
   429
	if (!parObj) 
insilmaril@388
   430
	{
insilmaril@473
   431
		orientation=UndefinedOrientation;
insilmaril@388
   432
		return;
insilmaril@388
   433
	}
insilmaril@388
   434
		
insilmaril@388
   435
    // Set orientation, first look for orientation of parent
insilmaril@473
   436
    if (parObj->getOrientation() != UndefinedOrientation ) 
insilmaril@388
   437
		// use the orientation of the parent:
insilmaril@388
   438
		orientation=parObj->getOrientation();
insilmaril@388
   439
    else
insilmaril@388
   440
    {
insilmaril@388
   441
		// calc orientation depending on position rel to parent
insilmaril@408
   442
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@473
   443
			orientation=LeftOfCenter; 
insilmaril@388
   444
		else
insilmaril@473
   445
			orientation=RightOfCenter;
insilmaril@388
   446
    }
insilmaril@388
   447
	if (orientOld!=orientation) requestReposition();
insilmaril@388
   448
}
insilmaril@388
   449
insilmaril@0
   450
void LinkableMapObj::updateLink()
insilmaril@0
   451
{
insilmaril@0
   452
    // needs:
insilmaril@0
   453
    //	childPos of parent
insilmaril@0
   454
    //	orient   of parent
insilmaril@0
   455
    //	style
insilmaril@0
   456
    // 
insilmaril@0
   457
    // sets:
insilmaril@0
   458
    //	orientation
insilmaril@225
   459
    //	childPos	(by calling setDockPos())
insilmaril@225
   460
    //	parPos		(by calling setDockPos())
insilmaril@175
   461
	//  bottomlineY
insilmaril@0
   462
    //	drawing of the link itself
insilmaril@0
   463
insilmaril@0
   464
	// updateLink is called from move, but called from constructor we don't
insilmaril@0
   465
	// have parents yet...
insilmaril@473
   466
	if (style==UndefinedStyle) return;	
insilmaril@0
   467
insilmaril@0
   468
	switch (linkpos)
insilmaril@0
   469
	{
insilmaril@473
   470
		case Middle:
insilmaril@442
   471
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   472
			break;
insilmaril@473
   473
		case Bottom:
insilmaril@225
   474
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   475
			break;
insilmaril@0
   476
	}
insilmaril@0
   477
	
insilmaril@0
   478
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   479
	if (!link2ParPos)
insilmaril@0
   480
	{
insilmaril@408
   481
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   482
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   483
	} else	
insilmaril@0
   484
	{
insilmaril@408
   485
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   486
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   487
	} 
insilmaril@0
   488
insilmaril@388
   489
	setDockPos(); // Call overloaded method
insilmaril@393
   490
	setOrientation();
insilmaril@0
   491
insilmaril@0
   492
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   493
	double p1y=parPos.y();
insilmaril@0
   494
insilmaril@0
   495
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   496
	double vy=p2y - p1y;
insilmaril@0
   497
insilmaril@0
   498
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@427
   499
	//bottomline->prepareGeometryChange();
insilmaril@408
   500
	bottomline->setLine (QLine (qRound(childPos.x()),
insilmaril@104
   501
		qRound(childPos.y()),
insilmaril@104
   502
		qRound(p1x),
insilmaril@408
   503
		qRound(p1y) ));
insilmaril@0
   504
insilmaril@0
   505
	double a;	// angle
insilmaril@0
   506
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   507
		a=M_PI_2;
insilmaril@0
   508
	else
insilmaril@0
   509
		a=atan( vy / vx );
insilmaril@0
   510
	// "turning point" for drawing polygonal links
insilmaril@408
   511
	QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   512
	
insilmaril@0
   513
    // Draw the link
insilmaril@0
   514
	switch (style)
insilmaril@0
   515
	{
insilmaril@473
   516
		case Line:
insilmaril@427
   517
			//l->prepareGeometryChange();
insilmaril@408
   518
			l->setLine( QLine(qRound (parPos.x()),
insilmaril@104
   519
				qRound(parPos.y()),
insilmaril@104
   520
				qRound(p2x),
insilmaril@408
   521
				qRound(p2y) ));
insilmaril@0
   522
			break;	
insilmaril@473
   523
		case Parabel:	
insilmaril@0
   524
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@406
   525
			for (int i=0; i<segment.size(); ++i)
insilmaril@427
   526
			{
insilmaril@427
   527
				//segment.at(i)->prepareGeometryChange();
insilmaril@408
   528
				segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
insilmaril@427
   529
			}	
insilmaril@0
   530
			break;
insilmaril@473
   531
		case PolyLine:
insilmaril@408
   532
			pa0.clear();
insilmaril@408
   533
			pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@408
   534
			pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@408
   535
			pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@427
   536
			//p->prepareGeometryChange();
insilmaril@408
   537
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   538
			break;
insilmaril@473
   539
		case PolyParabel:	
insilmaril@0
   540
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   541
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@408
   542
			pa0.clear();
insilmaril@406
   543
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   544
				pa0 << QPointF (pa1.at(i));
insilmaril@408
   545
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   546
				pa0 << QPointF (pa2.at(arcsegs-i));
insilmaril@427
   547
			//p->prepareGeometryChange();
insilmaril@408
   548
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   549
			break;
insilmaril@0
   550
		default:
insilmaril@0
   551
			break;
insilmaril@0
   552
	} // switch (style)	
insilmaril@0
   553
}
insilmaril@0
   554
	
insilmaril@0
   555
LinkableMapObj* LinkableMapObj::getChildObj()
insilmaril@0
   556
{
insilmaril@0
   557
    return childObj;
insilmaril@0
   558
}
insilmaril@0
   559
insilmaril@0
   560
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   561
{
insilmaril@0
   562
    return parObj;
insilmaril@0
   563
}
insilmaril@0
   564
insilmaril@106
   565
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
insilmaril@95
   566
{
insilmaril@95
   567
	LinkableMapObj *lmo=this;
insilmaril@95
   568
	QString part;
insilmaril@95
   569
	QString typ;
insilmaril@95
   570
	QString num;
insilmaril@95
   571
	while (!s.isEmpty() )
insilmaril@95
   572
	{
insilmaril@95
   573
		part=s.section(",",0,0);
insilmaril@95
   574
		typ=part.left (3);
insilmaril@95
   575
		num=part.right(part.length() - 3);
insilmaril@95
   576
		if (typ=="mc:")
insilmaril@95
   577
		{
insilmaril@95
   578
			if (depth>0)
insilmaril@95
   579
				return false;	// in a subtree there is no center
insilmaril@95
   580
			else
insilmaril@95
   581
				break;
insilmaril@95
   582
		} else
insilmaril@95
   583
			if (typ=="bo:")
insilmaril@644
   584
				lmo=((BranchObj*)lmo)->getBranchNum (num.toInt());
insilmaril@95
   585
			else
insilmaril@95
   586
				if (typ=="fi:")
insilmaril@644
   587
					lmo=((BranchObj*)lmo)->getFloatImageNum (num.toUInt());
insilmaril@95
   588
		if (!lmo) break;
insilmaril@95
   589
		
insilmaril@95
   590
		if (s.contains(","))
insilmaril@95
   591
			s=s.right(s.length() - part.length() -1 );
insilmaril@95
   592
		else	
insilmaril@95
   593
			break;
insilmaril@95
   594
	}
insilmaril@95
   595
	return lmo;
insilmaril@95
   596
}
insilmaril@95
   597
insilmaril@408
   598
QPointF LinkableMapObj::getChildPos()
insilmaril@0
   599
{
insilmaril@0
   600
    return childPos;
insilmaril@0
   601
}
insilmaril@0
   602
insilmaril@408
   603
QPointF LinkableMapObj::getParPos()
insilmaril@0
   604
{
insilmaril@0
   605
    return parPos;
insilmaril@0
   606
}
insilmaril@0
   607
insilmaril@218
   608
void LinkableMapObj::setUseOrientation (const bool &b)
insilmaril@218
   609
{	
insilmaril@218
   610
	if (useOrientation!=b)
insilmaril@218
   611
	{
insilmaril@218
   612
		useOrientation=b;
insilmaril@218
   613
		requestReposition();
insilmaril@218
   614
	}	
insilmaril@218
   615
}
insilmaril@218
   616
insilmaril@473
   617
LinkableMapObj::Orientation LinkableMapObj::getOrientation()
insilmaril@0
   618
{
insilmaril@0
   619
    return orientation;
insilmaril@0
   620
}
insilmaril@0
   621
insilmaril@0
   622
int LinkableMapObj::getDepth()
insilmaril@0
   623
{
insilmaril@0
   624
    return depth;
insilmaril@0
   625
}
insilmaril@0
   626
insilmaril@0
   627
void LinkableMapObj::setMapEditor (MapEditor *me)
insilmaril@0
   628
{
insilmaril@0
   629
	mapEditor=me;
insilmaril@721
   630
	model=mapEditor->getModel();
insilmaril@0
   631
}
insilmaril@0
   632
insilmaril@0
   633
MapEditor* LinkableMapObj::getMapEditor ()
insilmaril@0
   634
{
insilmaril@0
   635
	return mapEditor;
insilmaril@0
   636
}
insilmaril@0
   637
insilmaril@408
   638
QPointF LinkableMapObj::getRandPos()
insilmaril@0
   639
{
insilmaril@0
   640
	// Choose a random position with given distance to parent:
insilmaril@0
   641
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@408
   642
    return QPointF ( (int)( + 150*cos (a)),
insilmaril@0
   643
                    (int)( + 150*sin (a)));
insilmaril@0
   644
}
insilmaril@0
   645
insilmaril@0
   646
void LinkableMapObj::reposition()
insilmaril@0
   647
{
insilmaril@0
   648
}
insilmaril@0
   649
insilmaril@0
   650
void LinkableMapObj::requestReposition()
insilmaril@0
   651
{
insilmaril@0
   652
	if (!repositionRequest)
insilmaril@0
   653
	{
insilmaril@0
   654
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   655
		// been done yet
insilmaril@0
   656
		repositionRequest=true;
insilmaril@0
   657
		if (parObj) parObj->requestReposition();
insilmaril@0
   658
	}
insilmaril@0
   659
}
insilmaril@0
   660
insilmaril@0
   661
void LinkableMapObj::forceReposition()
insilmaril@0
   662
{
insilmaril@0
   663
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   664
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   665
	// which could collect requests for a reposition.
insilmaril@0
   666
	// Then we have to call forceReposition()
insilmaril@0
   667
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   668
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   669
	// the end, thus check first:
insilmaril@0
   670
insilmaril@724
   671
	if (model->isRepositionBlocked()) return;	
insilmaril@0
   672
	
insilmaril@724
   673
	// Pass on the request to parent objects, if this hasn't been done yet
insilmaril@0
   674
	if (parObj) 
insilmaril@0
   675
		parObj->forceReposition(); 
insilmaril@0
   676
	else 
insilmaril@83
   677
		reposition(); 
insilmaril@83
   678
}
insilmaril@0
   679
insilmaril@0
   680
bool LinkableMapObj::repositionRequested()
insilmaril@0
   681
{
insilmaril@0
   682
	return repositionRequest;
insilmaril@0
   683
}
insilmaril@0
   684
insilmaril@0
   685
insilmaril@0
   686
void LinkableMapObj::select()
insilmaril@0
   687
{
insilmaril@473
   688
	// select and unselect are still needed to
insilmaril@473
   689
	// handle hiding of links
insilmaril@0
   690
    selected=true;
insilmaril@261
   691
	setVisibility (visible);
insilmaril@0
   692
}
insilmaril@0
   693
insilmaril@0
   694
insilmaril@0
   695
void LinkableMapObj::unselect()
insilmaril@0
   696
{
insilmaril@0
   697
    selected=false;
insilmaril@261
   698
	// Maybe we have to hide the link:
insilmaril@261
   699
	setVisibility (visible);
insilmaril@0
   700
}
insilmaril@0
   701
insilmaril@408
   702
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   703
insilmaril@0
   704
{
insilmaril@0
   705
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   706
	double vy=p2y - p1y;
insilmaril@0
   707
insilmaril@0
   708
	double dx;				// delta x during calculation of parabel
insilmaril@0
   709
	
insilmaril@0
   710
	double pnx;				// next point
insilmaril@0
   711
	double pny;
insilmaril@0
   712
	double m;
insilmaril@0
   713
insilmaril@0
   714
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   715
		m=0;
insilmaril@0
   716
	else	
insilmaril@0
   717
		m=(vy / (vx*vx));
insilmaril@0
   718
	dx=vx/(arcsegs);
insilmaril@408
   719
	ya.clear();
insilmaril@579
   720
	ya<<QPointF (p1x,p1y);
insilmaril@408
   721
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   722
	{	
insilmaril@0
   723
		pnx=p1x+dx;
insilmaril@0
   724
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@579
   725
		ya<<QPointF (pnx,pny);
insilmaril@0
   726
		p1x=pnx;
insilmaril@0
   727
		p1y=pny;
insilmaril@0
   728
	}	
insilmaril@0
   729
}
insilmaril@0
   730
insilmaril@160
   731
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   732
{
insilmaril@160
   733
	if (hideLinkUnselected)
insilmaril@175
   734
		return attribut ("hideLink","true");
insilmaril@160
   735
	else
insilmaril@175
   736
		return attribut ("hideLink","false");
insilmaril@160
   737
	
insilmaril@160
   738
}
insilmaril@473
   739