linkablemapobj.cpp
author insilmaril
Mon, 15 Mar 2010 11:49:42 +0000
changeset 835 31841b366d5e
parent 823 0bba81dde1bc
child 836 62d621e3e550
permissions -rw-r--r--
Fixes for autoLayout (later)
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@790
    14
/* FIXME-3
insilmaril@0
    15
LinkableMapObj::LinkableMapObj():MapObj()
insilmaril@0
    16
{
insilmaril@0
    17
  //  cout << "Const LinkableMapObj ()\n";
insilmaril@0
    18
    init ();
insilmaril@0
    19
}
insilmaril@790
    20
*/
insilmaril@0
    21
insilmaril@790
    22
LinkableMapObj::LinkableMapObj(QGraphicsScene* s, TreeItem *ti) :MapObj(s,ti)
insilmaril@0
    23
{
insilmaril@790
    24
//    cout << "Const LinkableMapObj s="<<s<<"  ti="<<ti<<"  treeItem="<<treeItem<<endl;
insilmaril@0
    25
    init ();
insilmaril@0
    26
}
insilmaril@0
    27
insilmaril@408
    28
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
insilmaril@0
    29
{
insilmaril@0
    30
    copy (lmo);
insilmaril@0
    31
}
insilmaril@0
    32
insilmaril@0
    33
LinkableMapObj::~LinkableMapObj()
insilmaril@0
    34
{
insilmaril@791
    35
	//cout << "Destructor LMO\n";
insilmaril@0
    36
    delete (bottomline);
insilmaril@0
    37
	delLink();
insilmaril@0
    38
}
insilmaril@0
    39
insilmaril@0
    40
void LinkableMapObj::delLink()
insilmaril@0
    41
{
insilmaril@798
    42
	//bottomline->hide();
insilmaril@0
    43
	switch (style)
insilmaril@0
    44
	{
insilmaril@473
    45
		case Line:
insilmaril@0
    46
			delete (l);
insilmaril@0
    47
			break;
insilmaril@473
    48
		case Parabel:
insilmaril@406
    49
			while (!segment.isEmpty()) delete segment.takeFirst();
insilmaril@0
    50
			break;
insilmaril@473
    51
		case PolyLine:
insilmaril@0
    52
			delete (p);
insilmaril@0
    53
			break;
insilmaril@473
    54
		case PolyParabel:
insilmaril@0
    55
			delete (p);
insilmaril@0
    56
			break;
insilmaril@0
    57
		default:
insilmaril@0
    58
			break;
insilmaril@0
    59
	}		
insilmaril@0
    60
}
insilmaril@0
    61
insilmaril@0
    62
void LinkableMapObj::init ()
insilmaril@0
    63
{
insilmaril@0
    64
    parObj=NULL;
insilmaril@0
    65
    parObjTmpBuf=NULL;
insilmaril@798
    66
	tmpParent=false;
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@727
    71
	p=NULL;
insilmaril@473
    72
    orientation=UndefinedOrientation;
insilmaril@0
    73
    linkwidth=20;		
insilmaril@0
    74
	thickness_start=8;
insilmaril@473
    75
    style=UndefinedStyle;
insilmaril@473
    76
	linkpos=Bottom;
insilmaril@0
    77
    arcsegs=13;
insilmaril@0
    78
    
insilmaril@412
    79
// TODO instead of linkcolor pen.color() could be used	all around
insilmaril@408
    80
	pen.setWidth (1);
insilmaril@408
    81
	pen.setColor (linkcolor);
insilmaril@408
    82
	pen.setCapStyle ( Qt::RoundCap );
insilmaril@798
    83
insilmaril@798
    84
	useBottomline=true;
insilmaril@408
    85
	bottomline=scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
    86
    bottomline->setZValue(Z_LINK);
insilmaril@0
    87
    bottomline->show();
insilmaril@0
    88
insilmaril@175
    89
	topPad=botPad=leftPad=rightPad=0;
insilmaril@175
    90
insilmaril@0
    91
	repositionRequest=false;
insilmaril@218
    92
insilmaril@218
    93
	// Rel Positions
insilmaril@408
    94
	relPos=QPointF(0,0);
insilmaril@250
    95
	useRelPos=false;
insilmaril@0
    96
}
insilmaril@0
    97
insilmaril@0
    98
void LinkableMapObj::copy (LinkableMapObj* other)
insilmaril@0
    99
{
insilmaril@0
   100
    MapObj::copy(other);
insilmaril@0
   101
	bboxTotal=other->bboxTotal;
insilmaril@0
   102
    setLinkStyle(other->style);
insilmaril@0
   103
    setLinkColor (other->linkcolor);
insilmaril@218
   104
	relPos=other->relPos;
insilmaril@726
   105
	treeItem=other->treeItem;
insilmaril@726
   106
}
insilmaril@726
   107
insilmaril@0
   108
void LinkableMapObj::setParObj(LinkableMapObj* o)
insilmaril@0
   109
{
insilmaril@0
   110
    parObj=o;
insilmaril@0
   111
}
insilmaril@0
   112
insilmaril@746
   113
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)	// FIXME-3 make pure virtual
insilmaril@0
   114
{
insilmaril@0
   115
}
insilmaril@0
   116
insilmaril@746
   117
void LinkableMapObj::unsetParObjTmp()	// FIXME-3 make pure virtual
insilmaril@0
   118
{
insilmaril@0
   119
}
insilmaril@0
   120
insilmaril@164
   121
bool LinkableMapObj::hasParObjTmp()
insilmaril@164
   122
{
insilmaril@798
   123
	return tmpParent;
insilmaril@164
   124
}
insilmaril@164
   125
insilmaril@218
   126
void LinkableMapObj::setUseRelPos (const bool &b)
insilmaril@218
   127
{
insilmaril@218
   128
	useRelPos=b;
insilmaril@218
   129
}
insilmaril@218
   130
insilmaril@835
   131
bool LinkableMapObj::getUseRelPos ()
insilmaril@835
   132
{
insilmaril@835
   133
	return useRelPos;
insilmaril@835
   134
}
insilmaril@835
   135
insilmaril@218
   136
void LinkableMapObj::setRelPos()
insilmaril@218
   137
{
insilmaril@218
   138
	if (parObj)
insilmaril@218
   139
	{	
insilmaril@395
   140
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@395
   141
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@218
   142
		parObj->calcBBoxSize();
insilmaril@494
   143
	}	
insilmaril@218
   144
}
insilmaril@218
   145
insilmaril@408
   146
void LinkableMapObj::setRelPos(const QPointF &p)
insilmaril@218
   147
{
insilmaril@218
   148
	relPos=p;
insilmaril@218
   149
	if (parObj)
insilmaril@388
   150
	{		
insilmaril@388
   151
		parObj->calcBBoxSize();
insilmaril@388
   152
		requestReposition();
insilmaril@395
   153
	}
insilmaril@218
   154
}
insilmaril@218
   155
insilmaril@408
   156
QPointF LinkableMapObj::getRelPos()
insilmaril@366
   157
{
insilmaril@835
   158
	if (!parObj) 
insilmaril@835
   159
	{
insilmaril@835
   160
		qWarning("LMO::getRelPos parObj==0");
insilmaril@835
   161
		return QPointF();
insilmaril@835
   162
	}
insilmaril@366
   163
	return relPos;
insilmaril@366
   164
}
insilmaril@366
   165
insilmaril@408
   166
qreal LinkableMapObj::getTopPad()
insilmaril@175
   167
{
insilmaril@175
   168
	return topPad;
insilmaril@175
   169
}
insilmaril@175
   170
insilmaril@408
   171
qreal LinkableMapObj::getLeftPad()
insilmaril@175
   172
{
insilmaril@175
   173
	return leftPad;
insilmaril@175
   174
}
insilmaril@175
   175
insilmaril@408
   176
qreal LinkableMapObj::getRightPad()
insilmaril@175
   177
{
insilmaril@175
   178
	return rightPad;
insilmaril@175
   179
}
insilmaril@175
   180
insilmaril@786
   181
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle (TreeItem *parent)
insilmaril@0
   182
{
insilmaril@773
   183
	VymModel *model=treeItem->getModel();
insilmaril@721
   184
	if (!model)
insilmaril@721
   185
	{
insilmaril@721
   186
		qWarning ("LMO::getDefLinkStyle   model=NULL");
insilmaril@727
   187
		//return UndefinedStyle;
insilmaril@721
   188
	}
insilmaril@721
   189
	Style ls=model->getMapLinkStyle();
insilmaril@786
   190
	int depth=1+parent->depth();
insilmaril@727
   191
	if (depth==0) return UndefinedStyle;
insilmaril@0
   192
	switch (ls)
insilmaril@0
   193
	{
insilmaril@473
   194
		case Line: 
insilmaril@0
   195
			return ls;
insilmaril@0
   196
			break;
insilmaril@473
   197
		case Parabel:
insilmaril@0
   198
			return ls;
insilmaril@0
   199
			break;
insilmaril@473
   200
		case PolyLine:	
insilmaril@0
   201
			if (depth>1)
insilmaril@473
   202
				return Line;
insilmaril@0
   203
			else	
insilmaril@0
   204
				return ls;
insilmaril@0
   205
			break;
insilmaril@473
   206
		case PolyParabel:	
insilmaril@0
   207
			if (depth>1)
insilmaril@473
   208
				return Parabel;
insilmaril@0
   209
			else	
insilmaril@0
   210
				return ls;
insilmaril@0
   211
			break;
insilmaril@0
   212
		default: 
insilmaril@0
   213
			break;	
insilmaril@0
   214
	}	
insilmaril@473
   215
	return UndefinedStyle;
insilmaril@0
   216
}
insilmaril@0
   217
insilmaril@473
   218
void LinkableMapObj::setLinkStyle(Style newstyle)
insilmaril@0
   219
{
insilmaril@0
   220
	delLink();
insilmaril@0
   221
		
insilmaril@0
   222
	style=newstyle;
insilmaril@0
   223
insilmaril@773
   224
    if (parObj != NULL)
insilmaril@0
   225
    {
insilmaril@408
   226
		QGraphicsLineItem *cl;
insilmaril@0
   227
		switch (style)
insilmaril@0
   228
		{
insilmaril@473
   229
			case UndefinedStyle:
insilmaril@0
   230
				bottomline->hide();
insilmaril@0
   231
				break;
insilmaril@473
   232
			case Line: 
insilmaril@408
   233
				l = scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
   234
				l->setZValue(Z_LINK);
insilmaril@0
   235
				if (visible)
insilmaril@0
   236
					l->show();
insilmaril@0
   237
				else
insilmaril@0
   238
					l->hide();
insilmaril@0
   239
				break;
insilmaril@473
   240
			case Parabel:
insilmaril@408
   241
				for (int i=0;i<arcsegs;i++)
insilmaril@0
   242
				{
insilmaril@408
   243
					cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
insilmaril@408
   244
					cl->setZValue(Z_LINK);
insilmaril@0
   245
					if (visible)
insilmaril@0
   246
						cl->show();
insilmaril@0
   247
					else
insilmaril@0
   248
						cl->hide();
insilmaril@0
   249
					segment.append(cl);
insilmaril@0
   250
				}
insilmaril@0
   251
				pa0.resize (arcsegs+1);
insilmaril@0
   252
				break;
insilmaril@473
   253
			case PolyLine:	
insilmaril@408
   254
				p =scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   255
				p->setZValue(Z_LINK);
insilmaril@0
   256
				if (visible)
insilmaril@0
   257
					p->show();
insilmaril@0
   258
				else
insilmaril@0
   259
					p->hide();
insilmaril@0
   260
				pa0.resize (3);
insilmaril@0
   261
				break;
insilmaril@473
   262
			case PolyParabel:	
insilmaril@408
   263
				p = scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   264
				p->setZValue(Z_LINK);
insilmaril@0
   265
				if (visible)
insilmaril@0
   266
					p->show();
insilmaril@0
   267
				else
insilmaril@0
   268
					p->hide();
insilmaril@0
   269
				pa0.resize (arcsegs*2+2);
insilmaril@0
   270
				pa1.resize (arcsegs+1);
insilmaril@0
   271
				pa2.resize (arcsegs+1);
insilmaril@0
   272
				break;
insilmaril@0
   273
			default: 
insilmaril@0
   274
				break;	
insilmaril@0
   275
		}	
insilmaril@164
   276
	} 
insilmaril@0
   277
}
insilmaril@0
   278
insilmaril@473
   279
LinkableMapObj::Style LinkableMapObj::getLinkStyle()
insilmaril@0
   280
{
insilmaril@0
   281
	return style;
insilmaril@0
   282
}
insilmaril@0
   283
insilmaril@473
   284
void LinkableMapObj::setLinkPos(Position lp)
insilmaril@0
   285
{
insilmaril@0
   286
	linkpos=lp;
insilmaril@0
   287
}
insilmaril@0
   288
insilmaril@473
   289
LinkableMapObj::Position LinkableMapObj::getLinkPos()
insilmaril@0
   290
{
insilmaril@0
   291
	return linkpos;
insilmaril@0
   292
}
insilmaril@0
   293
insilmaril@0
   294
void LinkableMapObj::setLinkColor()
insilmaril@0
   295
{
insilmaril@721
   296
	// Overloaded in BranchObj and children
insilmaril@0
   297
	// here only set default color
insilmaril@773
   298
	VymModel *model=treeItem->getModel();
insilmaril@721
   299
	if (model)
insilmaril@721
   300
		setLinkColor (model->getMapDefLinkColor());
insilmaril@0
   301
}
insilmaril@0
   302
insilmaril@0
   303
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   304
{
insilmaril@0
   305
	linkcolor=col;
insilmaril@408
   306
	pen.setColor(col);
insilmaril@408
   307
    bottomline->setPen( pen );
insilmaril@0
   308
	switch (style)
insilmaril@0
   309
	{
insilmaril@473
   310
		case Line:
insilmaril@408
   311
			l->setPen( pen);
insilmaril@0
   312
			break;	
insilmaril@473
   313
		case Parabel:	
insilmaril@406
   314
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   315
				segment.at(i)->setPen( pen);
insilmaril@0
   316
			break;
insilmaril@473
   317
		case PolyLine:
insilmaril@0
   318
			p->setBrush( QBrush(col));
insilmaril@497
   319
			p->setPen( pen);
insilmaril@0
   320
			break;
insilmaril@473
   321
		case PolyParabel:	
insilmaril@0
   322
			p->setBrush( QBrush(col));
insilmaril@497
   323
			p->setPen( pen);
insilmaril@0
   324
			break;
insilmaril@0
   325
		default:
insilmaril@0
   326
			break;
insilmaril@755
   327
	} 
insilmaril@0
   328
}
insilmaril@0
   329
insilmaril@0
   330
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   331
{
insilmaril@0
   332
	return linkcolor;
insilmaril@0
   333
}
insilmaril@0
   334
insilmaril@0
   335
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   336
{
insilmaril@0
   337
	MapObj::setVisibility (v);
insilmaril@779
   338
	updateVisibility();
insilmaril@779
   339
}
insilmaril@779
   340
insilmaril@779
   341
void LinkableMapObj::setOrientation()
insilmaril@779
   342
{
insilmaril@779
   343
	Orientation orientOld=orientation;
insilmaril@779
   344
insilmaril@779
   345
	if (!parObj) 
insilmaril@779
   346
	{
insilmaril@779
   347
		orientation=UndefinedOrientation;
insilmaril@779
   348
		return;
insilmaril@779
   349
	}
insilmaril@779
   350
		
insilmaril@779
   351
    // Set orientation, first look for orientation of parent
insilmaril@779
   352
    if (parObj->getOrientation() != UndefinedOrientation ) 
insilmaril@779
   353
		// use the orientation of the parent:
insilmaril@779
   354
		orientation=parObj->getOrientation();
insilmaril@779
   355
    else
insilmaril@779
   356
    {
insilmaril@779
   357
		// calc orientation depending on position rel to parent
insilmaril@779
   358
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@779
   359
			orientation=LeftOfCenter; 
insilmaril@779
   360
		else
insilmaril@779
   361
			orientation=RightOfCenter;
insilmaril@779
   362
    }
insilmaril@779
   363
	if (orientOld!=orientation) requestReposition();
insilmaril@779
   364
}
insilmaril@779
   365
insilmaril@779
   366
void LinkableMapObj::updateVisibility()
insilmaril@779
   367
{
insilmaril@160
   368
	bool visnow=visible;
insilmaril@260
   369
insilmaril@779
   370
	if (((MapItem*)treeItem)->getHideLinkUnselected()
insilmaril@779
   371
		&& treeItem->getModel()->getSelectedLMO() !=this)
insilmaril@160
   372
		visnow=false;
insilmaril@160
   373
insilmaril@160
   374
	if (visnow) 
insilmaril@0
   375
	{
insilmaril@798
   376
		if (useBottomline)
insilmaril@798
   377
			bottomline->show();
insilmaril@798
   378
		else	
insilmaril@798
   379
			bottomline->hide();
insilmaril@798
   380
insilmaril@160
   381
		switch (style)
insilmaril@0
   382
		{
insilmaril@473
   383
			case Line:
insilmaril@160
   384
				if (l) l->show();
insilmaril@160
   385
				break;
insilmaril@473
   386
			case Parabel:	
insilmaril@406
   387
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   388
					segment.at(i)->show();
insilmaril@160
   389
				break;	
insilmaril@473
   390
			case PolyLine:
insilmaril@779
   391
				if (!p) cout << "LMO::updateVis p==0 (PolyLine)\n"; //FIXME-3
insilmaril@160
   392
				if (p) p->show();
insilmaril@160
   393
				break;
insilmaril@473
   394
			case PolyParabel:	
insilmaril@779
   395
				if (!p) cout << "LMO::updateVis p==0 (PolyParabel) "<<treeItem->getHeading().toStdString()<<endl; //FIXME-3
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@779
   425
void LinkableMapObj::updateLinkGeometry()
insilmaril@0
   426
{
insilmaril@0
   427
    // needs:
insilmaril@0
   428
    //	childPos of parent
insilmaril@0
   429
    //	orient   of parent
insilmaril@0
   430
    //	style
insilmaril@0
   431
    // 
insilmaril@0
   432
    // sets:
insilmaril@0
   433
    //	orientation
insilmaril@225
   434
    //	childPos	(by calling setDockPos())
insilmaril@225
   435
    //	parPos		(by calling setDockPos())
insilmaril@175
   436
	//  bottomlineY
insilmaril@0
   437
    //	drawing of the link itself
insilmaril@0
   438
insilmaril@779
   439
	// updateLinkGeometry is called from move, but called from constructor we don't
insilmaril@0
   440
	// have parents yet...
insilmaril@775
   441
insilmaril@816
   442
	//cout <<"LMO::updateLinkGeometry: "<<treeItem->getHeadingStd()<<"  "<<parObj<<endl;
insilmaril@775
   443
	if (!parObj)	
insilmaril@775
   444
	{
insilmaril@775
   445
		// If I am a mapcenter, set childPos to middle of MapCenterObj
insilmaril@775
   446
		childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
insilmaril@775
   447
		childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
insilmaril@775
   448
		parPos=childPos;		
insilmaril@775
   449
		// Redraw links to children
insilmaril@775
   450
		for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@779
   451
			treeItem->getBranchObjNum(i)->updateLinkGeometry();
insilmaril@775
   452
		return;	
insilmaril@775
   453
	}
insilmaril@775
   454
insilmaril@473
   455
	if (style==UndefinedStyle) return;	
insilmaril@0
   456
insilmaril@0
   457
	switch (linkpos)
insilmaril@0
   458
	{
insilmaril@473
   459
		case Middle:
insilmaril@442
   460
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   461
			break;
insilmaril@473
   462
		case Bottom:
insilmaril@785
   463
			//bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@785
   464
			bottomlineY=bbox.bottom()-botPad;
insilmaril@0
   465
			break;
insilmaril@0
   466
	}
insilmaril@0
   467
	
insilmaril@0
   468
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   469
	if (!link2ParPos)
insilmaril@0
   470
	{
insilmaril@408
   471
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   472
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   473
	} else	
insilmaril@0
   474
	{
insilmaril@408
   475
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   476
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   477
	} 
insilmaril@0
   478
insilmaril@388
   479
	setDockPos(); // Call overloaded method
insilmaril@393
   480
	setOrientation();
insilmaril@0
   481
insilmaril@0
   482
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   483
	double p1y=parPos.y();
insilmaril@0
   484
insilmaril@0
   485
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   486
	double vy=p2y - p1y;
insilmaril@0
   487
insilmaril@0
   488
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@408
   489
	bottomline->setLine (QLine (qRound(childPos.x()),
insilmaril@104
   490
		qRound(childPos.y()),
insilmaril@104
   491
		qRound(p1x),
insilmaril@408
   492
		qRound(p1y) ));
insilmaril@0
   493
insilmaril@0
   494
	double a;	// angle
insilmaril@0
   495
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   496
		a=M_PI_2;
insilmaril@0
   497
	else
insilmaril@0
   498
		a=atan( vy / vx );
insilmaril@0
   499
	// "turning point" for drawing polygonal links
insilmaril@408
   500
	QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   501
	
insilmaril@0
   502
    // Draw the link
insilmaril@0
   503
	switch (style)
insilmaril@0
   504
	{
insilmaril@473
   505
		case Line:
insilmaril@408
   506
			l->setLine( QLine(qRound (parPos.x()),
insilmaril@104
   507
				qRound(parPos.y()),
insilmaril@104
   508
				qRound(p2x),
insilmaril@408
   509
				qRound(p2y) ));
insilmaril@0
   510
			break;	
insilmaril@473
   511
		case Parabel:	
insilmaril@0
   512
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@406
   513
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   514
				segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
insilmaril@0
   515
			break;
insilmaril@473
   516
		case PolyLine:
insilmaril@408
   517
			pa0.clear();
insilmaril@408
   518
			pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@408
   519
			pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@408
   520
			pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@408
   521
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   522
			break;
insilmaril@473
   523
		case PolyParabel:	
insilmaril@0
   524
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   525
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@408
   526
			pa0.clear();
insilmaril@406
   527
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   528
				pa0 << QPointF (pa1.at(i));
insilmaril@408
   529
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   530
				pa0 << QPointF (pa2.at(arcsegs-i));
insilmaril@408
   531
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   532
			break;
insilmaril@0
   533
		default:
insilmaril@0
   534
			break;
insilmaril@779
   535
	} 
insilmaril@0
   536
}
insilmaril@0
   537
	
insilmaril@0
   538
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   539
{
insilmaril@0
   540
    return parObj;
insilmaril@0
   541
}
insilmaril@0
   542
insilmaril@408
   543
QPointF LinkableMapObj::getChildPos()
insilmaril@0
   544
{
insilmaril@0
   545
    return childPos;
insilmaril@0
   546
}
insilmaril@0
   547
insilmaril@408
   548
QPointF LinkableMapObj::getParPos()
insilmaril@0
   549
{
insilmaril@0
   550
    return parPos;
insilmaril@0
   551
}
insilmaril@0
   552
insilmaril@473
   553
LinkableMapObj::Orientation LinkableMapObj::getOrientation()
insilmaril@0
   554
{
insilmaril@0
   555
    return orientation;
insilmaril@0
   556
}
insilmaril@0
   557
insilmaril@408
   558
QPointF LinkableMapObj::getRandPos()
insilmaril@0
   559
{
insilmaril@0
   560
	// Choose a random position with given distance to parent:
insilmaril@0
   561
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@408
   562
    return QPointF ( (int)( + 150*cos (a)),
insilmaril@0
   563
                    (int)( + 150*sin (a)));
insilmaril@0
   564
}
insilmaril@0
   565
insilmaril@0
   566
void LinkableMapObj::reposition()
insilmaril@0
   567
{
insilmaril@0
   568
}
insilmaril@0
   569
insilmaril@785
   570
void LinkableMapObj::requestReposition()	//FIXME-3 needed?
insilmaril@0
   571
{
insilmaril@0
   572
	if (!repositionRequest)
insilmaril@0
   573
	{
insilmaril@0
   574
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   575
		// been done yet
insilmaril@0
   576
		repositionRequest=true;
insilmaril@0
   577
		if (parObj) parObj->requestReposition();
insilmaril@0
   578
	}
insilmaril@0
   579
}
insilmaril@0
   580
insilmaril@0
   581
void LinkableMapObj::forceReposition()
insilmaril@0
   582
{
insilmaril@0
   583
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   584
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   585
	// which could collect requests for a reposition.
insilmaril@0
   586
	// Then we have to call forceReposition()
insilmaril@0
   587
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   588
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   589
	// the end, thus check first:
insilmaril@0
   590
insilmaril@773
   591
	VymModel *model=treeItem->getModel();
insilmaril@724
   592
	if (model->isRepositionBlocked()) return;	
insilmaril@0
   593
	
insilmaril@724
   594
	// Pass on the request to parent objects, if this hasn't been done yet
insilmaril@0
   595
	if (parObj) 
insilmaril@0
   596
		parObj->forceReposition(); 
insilmaril@0
   597
	else 
insilmaril@83
   598
		reposition(); 
insilmaril@83
   599
}
insilmaril@0
   600
insilmaril@0
   601
bool LinkableMapObj::repositionRequested()
insilmaril@0
   602
{
insilmaril@0
   603
	return repositionRequest;
insilmaril@0
   604
}
insilmaril@0
   605
insilmaril@408
   606
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   607
insilmaril@0
   608
{
insilmaril@0
   609
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   610
	double vy=p2y - p1y;
insilmaril@0
   611
insilmaril@0
   612
	double dx;				// delta x during calculation of parabel
insilmaril@0
   613
	
insilmaril@0
   614
	double pnx;				// next point
insilmaril@0
   615
	double pny;
insilmaril@0
   616
	double m;
insilmaril@0
   617
insilmaril@0
   618
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   619
		m=0;
insilmaril@0
   620
	else	
insilmaril@0
   621
		m=(vy / (vx*vx));
insilmaril@0
   622
	dx=vx/(arcsegs);
insilmaril@408
   623
	ya.clear();
insilmaril@579
   624
	ya<<QPointF (p1x,p1y);
insilmaril@408
   625
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   626
	{	
insilmaril@0
   627
		pnx=p1x+dx;
insilmaril@0
   628
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@579
   629
		ya<<QPointF (pnx,pny);
insilmaril@0
   630
		p1x=pnx;
insilmaril@0
   631
		p1y=pny;
insilmaril@0
   632
	}	
insilmaril@0
   633
}
insilmaril@0
   634