linkablemapobj.cpp
author insilmaril
Fri, 27 Nov 2009 15:00:51 +0000
changeset 812 62d4137bfb90
parent 798 d251c7b2de54
child 816 3086ee01554a
permissions -rw-r--r--
Select MapEditor after closing FindWidget
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@218
   131
void LinkableMapObj::setRelPos()
insilmaril@218
   132
{
insilmaril@218
   133
	if (parObj)
insilmaril@218
   134
	{	
insilmaril@395
   135
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@395
   136
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@218
   137
		parObj->calcBBoxSize();
insilmaril@494
   138
	}	
insilmaril@218
   139
}
insilmaril@218
   140
insilmaril@408
   141
void LinkableMapObj::setRelPos(const QPointF &p)
insilmaril@218
   142
{
insilmaril@218
   143
	relPos=p;
insilmaril@218
   144
	if (parObj)
insilmaril@388
   145
	{		
insilmaril@388
   146
		parObj->calcBBoxSize();
insilmaril@388
   147
		requestReposition();
insilmaril@395
   148
	}
insilmaril@218
   149
}
insilmaril@218
   150
insilmaril@408
   151
QPointF LinkableMapObj::getRelPos()
insilmaril@366
   152
{
insilmaril@408
   153
	if (!parObj) return QPointF();
insilmaril@366
   154
	return relPos;
insilmaril@366
   155
}
insilmaril@366
   156
insilmaril@408
   157
qreal LinkableMapObj::getTopPad()
insilmaril@175
   158
{
insilmaril@175
   159
	return topPad;
insilmaril@175
   160
}
insilmaril@175
   161
insilmaril@408
   162
qreal LinkableMapObj::getLeftPad()
insilmaril@175
   163
{
insilmaril@175
   164
	return leftPad;
insilmaril@175
   165
}
insilmaril@175
   166
insilmaril@408
   167
qreal LinkableMapObj::getRightPad()
insilmaril@175
   168
{
insilmaril@175
   169
	return rightPad;
insilmaril@175
   170
}
insilmaril@175
   171
insilmaril@786
   172
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle (TreeItem *parent)
insilmaril@0
   173
{
insilmaril@773
   174
	VymModel *model=treeItem->getModel();
insilmaril@721
   175
	if (!model)
insilmaril@721
   176
	{
insilmaril@721
   177
		qWarning ("LMO::getDefLinkStyle   model=NULL");
insilmaril@727
   178
		//return UndefinedStyle;
insilmaril@721
   179
	}
insilmaril@721
   180
	Style ls=model->getMapLinkStyle();
insilmaril@786
   181
	int depth=1+parent->depth();
insilmaril@727
   182
	if (depth==0) return UndefinedStyle;
insilmaril@0
   183
	switch (ls)
insilmaril@0
   184
	{
insilmaril@473
   185
		case Line: 
insilmaril@0
   186
			return ls;
insilmaril@0
   187
			break;
insilmaril@473
   188
		case Parabel:
insilmaril@0
   189
			return ls;
insilmaril@0
   190
			break;
insilmaril@473
   191
		case PolyLine:	
insilmaril@0
   192
			if (depth>1)
insilmaril@473
   193
				return Line;
insilmaril@0
   194
			else	
insilmaril@0
   195
				return ls;
insilmaril@0
   196
			break;
insilmaril@473
   197
		case PolyParabel:	
insilmaril@0
   198
			if (depth>1)
insilmaril@473
   199
				return Parabel;
insilmaril@0
   200
			else	
insilmaril@0
   201
				return ls;
insilmaril@0
   202
			break;
insilmaril@0
   203
		default: 
insilmaril@0
   204
			break;	
insilmaril@0
   205
	}	
insilmaril@473
   206
	return UndefinedStyle;
insilmaril@0
   207
}
insilmaril@0
   208
insilmaril@473
   209
void LinkableMapObj::setLinkStyle(Style newstyle)
insilmaril@0
   210
{
insilmaril@0
   211
	delLink();
insilmaril@0
   212
		
insilmaril@0
   213
	style=newstyle;
insilmaril@0
   214
insilmaril@773
   215
    if (parObj != NULL)
insilmaril@0
   216
    {
insilmaril@408
   217
		QGraphicsLineItem *cl;
insilmaril@0
   218
		switch (style)
insilmaril@0
   219
		{
insilmaril@473
   220
			case UndefinedStyle:
insilmaril@0
   221
				bottomline->hide();
insilmaril@0
   222
				break;
insilmaril@473
   223
			case Line: 
insilmaril@408
   224
				l = scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
   225
				l->setZValue(Z_LINK);
insilmaril@0
   226
				if (visible)
insilmaril@0
   227
					l->show();
insilmaril@0
   228
				else
insilmaril@0
   229
					l->hide();
insilmaril@0
   230
				break;
insilmaril@473
   231
			case Parabel:
insilmaril@408
   232
				for (int i=0;i<arcsegs;i++)
insilmaril@0
   233
				{
insilmaril@408
   234
					cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
insilmaril@408
   235
					cl->setZValue(Z_LINK);
insilmaril@0
   236
					if (visible)
insilmaril@0
   237
						cl->show();
insilmaril@0
   238
					else
insilmaril@0
   239
						cl->hide();
insilmaril@0
   240
					segment.append(cl);
insilmaril@0
   241
				}
insilmaril@0
   242
				pa0.resize (arcsegs+1);
insilmaril@0
   243
				break;
insilmaril@473
   244
			case PolyLine:	
insilmaril@408
   245
				p =scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   246
				p->setZValue(Z_LINK);
insilmaril@0
   247
				if (visible)
insilmaril@0
   248
					p->show();
insilmaril@0
   249
				else
insilmaril@0
   250
					p->hide();
insilmaril@0
   251
				pa0.resize (3);
insilmaril@0
   252
				break;
insilmaril@473
   253
			case PolyParabel:	
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 (arcsegs*2+2);
insilmaril@0
   261
				pa1.resize (arcsegs+1);
insilmaril@0
   262
				pa2.resize (arcsegs+1);
insilmaril@0
   263
				break;
insilmaril@0
   264
			default: 
insilmaril@0
   265
				break;	
insilmaril@0
   266
		}	
insilmaril@164
   267
	} 
insilmaril@0
   268
}
insilmaril@0
   269
insilmaril@473
   270
LinkableMapObj::Style LinkableMapObj::getLinkStyle()
insilmaril@0
   271
{
insilmaril@0
   272
	return style;
insilmaril@0
   273
}
insilmaril@0
   274
insilmaril@779
   275
void LinkableMapObj::setHideLinkUnselected()
insilmaril@160
   276
{
insilmaril@160
   277
	setVisibility (visible);
insilmaril@779
   278
	updateLinkGeometry();
insilmaril@160
   279
}
insilmaril@160
   280
insilmaril@473
   281
void LinkableMapObj::setLinkPos(Position lp)
insilmaril@0
   282
{
insilmaril@0
   283
	linkpos=lp;
insilmaril@0
   284
}
insilmaril@0
   285
insilmaril@473
   286
LinkableMapObj::Position LinkableMapObj::getLinkPos()
insilmaril@0
   287
{
insilmaril@0
   288
	return linkpos;
insilmaril@0
   289
}
insilmaril@0
   290
insilmaril@0
   291
void LinkableMapObj::setLinkColor()
insilmaril@0
   292
{
insilmaril@721
   293
	// Overloaded in BranchObj and children
insilmaril@0
   294
	// here only set default color
insilmaril@773
   295
	VymModel *model=treeItem->getModel();
insilmaril@721
   296
	if (model)
insilmaril@721
   297
		setLinkColor (model->getMapDefLinkColor());
insilmaril@0
   298
}
insilmaril@0
   299
insilmaril@0
   300
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   301
{
insilmaril@0
   302
	linkcolor=col;
insilmaril@408
   303
	pen.setColor(col);
insilmaril@408
   304
    bottomline->setPen( pen );
insilmaril@0
   305
	switch (style)
insilmaril@0
   306
	{
insilmaril@473
   307
		case Line:
insilmaril@408
   308
			l->setPen( pen);
insilmaril@0
   309
			break;	
insilmaril@473
   310
		case Parabel:	
insilmaril@406
   311
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   312
				segment.at(i)->setPen( pen);
insilmaril@0
   313
			break;
insilmaril@473
   314
		case PolyLine:
insilmaril@0
   315
			p->setBrush( QBrush(col));
insilmaril@497
   316
			p->setPen( pen);
insilmaril@0
   317
			break;
insilmaril@473
   318
		case PolyParabel:	
insilmaril@0
   319
			p->setBrush( QBrush(col));
insilmaril@497
   320
			p->setPen( pen);
insilmaril@0
   321
			break;
insilmaril@0
   322
		default:
insilmaril@0
   323
			break;
insilmaril@755
   324
	} 
insilmaril@0
   325
}
insilmaril@0
   326
insilmaril@0
   327
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   328
{
insilmaril@0
   329
	return linkcolor;
insilmaril@0
   330
}
insilmaril@0
   331
insilmaril@0
   332
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   333
{
insilmaril@0
   334
	MapObj::setVisibility (v);
insilmaril@779
   335
	updateVisibility();
insilmaril@779
   336
}
insilmaril@779
   337
insilmaril@779
   338
void LinkableMapObj::setOrientation()
insilmaril@779
   339
{
insilmaril@779
   340
	Orientation orientOld=orientation;
insilmaril@779
   341
insilmaril@779
   342
	if (!parObj) 
insilmaril@779
   343
	{
insilmaril@779
   344
		orientation=UndefinedOrientation;
insilmaril@779
   345
		return;
insilmaril@779
   346
	}
insilmaril@779
   347
		
insilmaril@779
   348
    // Set orientation, first look for orientation of parent
insilmaril@779
   349
    if (parObj->getOrientation() != UndefinedOrientation ) 
insilmaril@779
   350
		// use the orientation of the parent:
insilmaril@779
   351
		orientation=parObj->getOrientation();
insilmaril@779
   352
    else
insilmaril@779
   353
    {
insilmaril@779
   354
		// calc orientation depending on position rel to parent
insilmaril@779
   355
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@779
   356
			orientation=LeftOfCenter; 
insilmaril@779
   357
		else
insilmaril@779
   358
			orientation=RightOfCenter;
insilmaril@779
   359
    }
insilmaril@779
   360
	if (orientOld!=orientation) requestReposition();
insilmaril@779
   361
}
insilmaril@779
   362
insilmaril@779
   363
void LinkableMapObj::updateVisibility()
insilmaril@779
   364
{
insilmaril@160
   365
	bool visnow=visible;
insilmaril@260
   366
insilmaril@779
   367
	if (((MapItem*)treeItem)->getHideLinkUnselected()
insilmaril@779
   368
		&& treeItem->getModel()->getSelectedLMO() !=this)
insilmaril@160
   369
		visnow=false;
insilmaril@160
   370
insilmaril@160
   371
	if (visnow) 
insilmaril@0
   372
	{
insilmaril@798
   373
		if (useBottomline)
insilmaril@798
   374
			bottomline->show();
insilmaril@798
   375
		else	
insilmaril@798
   376
			bottomline->hide();
insilmaril@798
   377
insilmaril@160
   378
		switch (style)
insilmaril@0
   379
		{
insilmaril@473
   380
			case Line:
insilmaril@160
   381
				if (l) l->show();
insilmaril@160
   382
				break;
insilmaril@473
   383
			case Parabel:	
insilmaril@406
   384
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   385
					segment.at(i)->show();
insilmaril@160
   386
				break;	
insilmaril@473
   387
			case PolyLine:
insilmaril@779
   388
				if (!p) cout << "LMO::updateVis p==0 (PolyLine)\n"; //FIXME-3
insilmaril@160
   389
				if (p) p->show();
insilmaril@160
   390
				break;
insilmaril@473
   391
			case PolyParabel:	
insilmaril@779
   392
				if (!p) cout << "LMO::updateVis p==0 (PolyParabel) "<<treeItem->getHeading().toStdString()<<endl; //FIXME-3
insilmaril@160
   393
				if (p) p->show();
insilmaril@160
   394
				break;
insilmaril@160
   395
			default:
insilmaril@160
   396
				break;
insilmaril@160
   397
		}
insilmaril@0
   398
	} else 
insilmaril@0
   399
	{
insilmaril@0
   400
		bottomline->hide();
insilmaril@160
   401
		switch (style)
insilmaril@0
   402
		{
insilmaril@473
   403
			case Line:
insilmaril@160
   404
				if (l) l->hide();
insilmaril@160
   405
				break;
insilmaril@473
   406
			case Parabel:	
insilmaril@406
   407
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   408
					segment.at(i)->hide();
insilmaril@160
   409
				break;	
insilmaril@473
   410
			case PolyLine:
insilmaril@160
   411
				if (p) p->hide();
insilmaril@160
   412
				break;
insilmaril@473
   413
			case PolyParabel:	
insilmaril@160
   414
				if (p) p->hide();
insilmaril@160
   415
				break;
insilmaril@160
   416
			default:
insilmaril@160
   417
				break;
insilmaril@160
   418
		}
insilmaril@0
   419
	}	
insilmaril@0
   420
}
insilmaril@0
   421
insilmaril@779
   422
void LinkableMapObj::updateLinkGeometry()
insilmaril@0
   423
{
insilmaril@0
   424
    // needs:
insilmaril@0
   425
    //	childPos of parent
insilmaril@0
   426
    //	orient   of parent
insilmaril@0
   427
    //	style
insilmaril@0
   428
    // 
insilmaril@0
   429
    // sets:
insilmaril@0
   430
    //	orientation
insilmaril@225
   431
    //	childPos	(by calling setDockPos())
insilmaril@225
   432
    //	parPos		(by calling setDockPos())
insilmaril@175
   433
	//  bottomlineY
insilmaril@0
   434
    //	drawing of the link itself
insilmaril@0
   435
insilmaril@779
   436
	// updateLinkGeometry is called from move, but called from constructor we don't
insilmaril@0
   437
	// have parents yet...
insilmaril@775
   438
insilmaril@785
   439
//cout <<"LMO::updateLinkGeometry: "<<treeItem->getHeadingStd()<<"  "<<parObj<<endl;
insilmaril@775
   440
	if (!parObj)	
insilmaril@775
   441
	{
insilmaril@775
   442
		// If I am a mapcenter, set childPos to middle of MapCenterObj
insilmaril@775
   443
		childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
insilmaril@775
   444
		childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
insilmaril@775
   445
		parPos=childPos;		
insilmaril@775
   446
		// Redraw links to children
insilmaril@775
   447
		for (int i=0; i<treeItem->branchCount(); ++i)
insilmaril@779
   448
			treeItem->getBranchObjNum(i)->updateLinkGeometry();
insilmaril@775
   449
		return;	
insilmaril@775
   450
	}
insilmaril@775
   451
insilmaril@473
   452
	if (style==UndefinedStyle) return;	
insilmaril@0
   453
insilmaril@0
   454
	switch (linkpos)
insilmaril@0
   455
	{
insilmaril@473
   456
		case Middle:
insilmaril@442
   457
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   458
			break;
insilmaril@473
   459
		case Bottom:
insilmaril@785
   460
			//bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@785
   461
			bottomlineY=bbox.bottom()-botPad;
insilmaril@0
   462
			break;
insilmaril@0
   463
	}
insilmaril@0
   464
	
insilmaril@0
   465
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   466
	if (!link2ParPos)
insilmaril@0
   467
	{
insilmaril@408
   468
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   469
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   470
	} else	
insilmaril@0
   471
	{
insilmaril@408
   472
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   473
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   474
	} 
insilmaril@0
   475
insilmaril@388
   476
	setDockPos(); // Call overloaded method
insilmaril@393
   477
	setOrientation();
insilmaril@0
   478
insilmaril@0
   479
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   480
	double p1y=parPos.y();
insilmaril@0
   481
insilmaril@0
   482
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   483
	double vy=p2y - p1y;
insilmaril@0
   484
insilmaril@0
   485
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@408
   486
	bottomline->setLine (QLine (qRound(childPos.x()),
insilmaril@104
   487
		qRound(childPos.y()),
insilmaril@104
   488
		qRound(p1x),
insilmaril@408
   489
		qRound(p1y) ));
insilmaril@0
   490
insilmaril@0
   491
	double a;	// angle
insilmaril@0
   492
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   493
		a=M_PI_2;
insilmaril@0
   494
	else
insilmaril@0
   495
		a=atan( vy / vx );
insilmaril@0
   496
	// "turning point" for drawing polygonal links
insilmaril@408
   497
	QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   498
	
insilmaril@0
   499
    // Draw the link
insilmaril@0
   500
	switch (style)
insilmaril@0
   501
	{
insilmaril@473
   502
		case Line:
insilmaril@408
   503
			l->setLine( QLine(qRound (parPos.x()),
insilmaril@104
   504
				qRound(parPos.y()),
insilmaril@104
   505
				qRound(p2x),
insilmaril@408
   506
				qRound(p2y) ));
insilmaril@0
   507
			break;	
insilmaril@473
   508
		case Parabel:	
insilmaril@0
   509
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@406
   510
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   511
				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
   512
			break;
insilmaril@473
   513
		case PolyLine:
insilmaril@408
   514
			pa0.clear();
insilmaril@408
   515
			pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@408
   516
			pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@408
   517
			pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@408
   518
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   519
			break;
insilmaril@473
   520
		case PolyParabel:	
insilmaril@0
   521
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   522
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@408
   523
			pa0.clear();
insilmaril@406
   524
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   525
				pa0 << QPointF (pa1.at(i));
insilmaril@408
   526
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   527
				pa0 << QPointF (pa2.at(arcsegs-i));
insilmaril@408
   528
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   529
			break;
insilmaril@0
   530
		default:
insilmaril@0
   531
			break;
insilmaril@779
   532
	} 
insilmaril@0
   533
}
insilmaril@0
   534
	
insilmaril@0
   535
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   536
{
insilmaril@0
   537
    return parObj;
insilmaril@0
   538
}
insilmaril@0
   539
insilmaril@408
   540
QPointF LinkableMapObj::getChildPos()
insilmaril@0
   541
{
insilmaril@0
   542
    return childPos;
insilmaril@0
   543
}
insilmaril@0
   544
insilmaril@408
   545
QPointF LinkableMapObj::getParPos()
insilmaril@0
   546
{
insilmaril@0
   547
    return parPos;
insilmaril@0
   548
}
insilmaril@0
   549
insilmaril@473
   550
LinkableMapObj::Orientation LinkableMapObj::getOrientation()
insilmaril@0
   551
{
insilmaril@0
   552
    return orientation;
insilmaril@0
   553
}
insilmaril@0
   554
insilmaril@408
   555
QPointF LinkableMapObj::getRandPos()
insilmaril@0
   556
{
insilmaril@0
   557
	// Choose a random position with given distance to parent:
insilmaril@0
   558
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@408
   559
    return QPointF ( (int)( + 150*cos (a)),
insilmaril@0
   560
                    (int)( + 150*sin (a)));
insilmaril@0
   561
}
insilmaril@0
   562
insilmaril@0
   563
void LinkableMapObj::reposition()
insilmaril@0
   564
{
insilmaril@0
   565
}
insilmaril@0
   566
insilmaril@785
   567
void LinkableMapObj::requestReposition()	//FIXME-3 needed?
insilmaril@0
   568
{
insilmaril@0
   569
	if (!repositionRequest)
insilmaril@0
   570
	{
insilmaril@0
   571
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   572
		// been done yet
insilmaril@0
   573
		repositionRequest=true;
insilmaril@0
   574
		if (parObj) parObj->requestReposition();
insilmaril@0
   575
	}
insilmaril@0
   576
}
insilmaril@0
   577
insilmaril@0
   578
void LinkableMapObj::forceReposition()
insilmaril@0
   579
{
insilmaril@0
   580
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   581
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   582
	// which could collect requests for a reposition.
insilmaril@0
   583
	// Then we have to call forceReposition()
insilmaril@0
   584
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   585
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   586
	// the end, thus check first:
insilmaril@0
   587
insilmaril@773
   588
	VymModel *model=treeItem->getModel();
insilmaril@724
   589
	if (model->isRepositionBlocked()) return;	
insilmaril@0
   590
	
insilmaril@724
   591
	// Pass on the request to parent objects, if this hasn't been done yet
insilmaril@0
   592
	if (parObj) 
insilmaril@0
   593
		parObj->forceReposition(); 
insilmaril@0
   594
	else 
insilmaril@83
   595
		reposition(); 
insilmaril@83
   596
}
insilmaril@0
   597
insilmaril@0
   598
bool LinkableMapObj::repositionRequested()
insilmaril@0
   599
{
insilmaril@0
   600
	return repositionRequest;
insilmaril@0
   601
}
insilmaril@0
   602
insilmaril@408
   603
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   604
insilmaril@0
   605
{
insilmaril@0
   606
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   607
	double vy=p2y - p1y;
insilmaril@0
   608
insilmaril@0
   609
	double dx;				// delta x during calculation of parabel
insilmaril@0
   610
	
insilmaril@0
   611
	double pnx;				// next point
insilmaril@0
   612
	double pny;
insilmaril@0
   613
	double m;
insilmaril@0
   614
insilmaril@0
   615
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   616
		m=0;
insilmaril@0
   617
	else	
insilmaril@0
   618
		m=(vy / (vx*vx));
insilmaril@0
   619
	dx=vx/(arcsegs);
insilmaril@408
   620
	ya.clear();
insilmaril@579
   621
	ya<<QPointF (p1x,p1y);
insilmaril@408
   622
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   623
	{	
insilmaril@0
   624
		pnx=p1x+dx;
insilmaril@0
   625
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@579
   626
		ya<<QPointF (pnx,pny);
insilmaril@0
   627
		p1x=pnx;
insilmaril@0
   628
		p1y=pny;
insilmaril@0
   629
	}	
insilmaril@0
   630
}
insilmaril@0
   631