linkablemapobj.cpp
author insilmaril
Mon Jul 27 12:53:17 2009 +0000 (2009-07-27)
changeset 783 85dec6a8c12c
parent 779 1fb50e79661c
child 785 5987f9f15bac
permissions -rw-r--r--
Playing with dbus, fixed name of TW translation file
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@0
    60
    parObj=NULL;
insilmaril@0
    61
    parObjTmpBuf=NULL;
insilmaril@408
    62
    parPos=QPointF(0,0);
insilmaril@408
    63
    childPos=QPointF(0,0);
insilmaril@0
    64
	link2ParPos=false;
insilmaril@0
    65
    l=NULL;
insilmaril@727
    66
	p=NULL;
insilmaril@473
    67
    orientation=UndefinedOrientation;
insilmaril@0
    68
    linkwidth=20;		
insilmaril@0
    69
	thickness_start=8;
insilmaril@473
    70
    style=UndefinedStyle;
insilmaril@473
    71
	linkpos=Bottom;
insilmaril@0
    72
    arcsegs=13;
insilmaril@0
    73
    
insilmaril@412
    74
// TODO instead of linkcolor pen.color() could be used	all around
insilmaril@408
    75
	pen.setWidth (1);
insilmaril@408
    76
	pen.setColor (linkcolor);
insilmaril@408
    77
	pen.setCapStyle ( Qt::RoundCap );
insilmaril@408
    78
	bottomline=scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
    79
    bottomline->setZValue(Z_LINK);
insilmaril@0
    80
    bottomline->show();
insilmaril@0
    81
insilmaril@175
    82
	topPad=botPad=leftPad=rightPad=0;
insilmaril@175
    83
insilmaril@0
    84
	repositionRequest=false;
insilmaril@218
    85
insilmaril@218
    86
	// Rel Positions
insilmaril@408
    87
	relPos=QPointF(0,0);
insilmaril@250
    88
	useRelPos=false;
insilmaril@531
    89
insilmaril@726
    90
	// Crossreference to treemodel
insilmaril@726
    91
	treeItem=NULL;
insilmaril@0
    92
}
insilmaril@0
    93
insilmaril@0
    94
void LinkableMapObj::copy (LinkableMapObj* other)
insilmaril@0
    95
{
insilmaril@0
    96
    MapObj::copy(other);
insilmaril@0
    97
	bboxTotal=other->bboxTotal;
insilmaril@0
    98
    setLinkStyle(other->style);
insilmaril@0
    99
    setLinkColor (other->linkcolor);
insilmaril@218
   100
	relPos=other->relPos;
insilmaril@726
   101
	treeItem=other->treeItem;
insilmaril@726
   102
}
insilmaril@726
   103
insilmaril@726
   104
void LinkableMapObj::setTreeItem (TreeItem *ti)
insilmaril@726
   105
{
insilmaril@726
   106
	treeItem=ti;
insilmaril@726
   107
}
insilmaril@726
   108
insilmaril@753
   109
TreeItem* LinkableMapObj::getTreeItem () const
insilmaril@726
   110
{
insilmaril@726
   111
	return treeItem;
insilmaril@0
   112
}
insilmaril@0
   113
insilmaril@0
   114
void LinkableMapObj::setParObj(LinkableMapObj* o)
insilmaril@0
   115
{
insilmaril@0
   116
    parObj=o;
insilmaril@0
   117
}
insilmaril@0
   118
insilmaril@746
   119
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)	// FIXME-3 make pure virtual
insilmaril@0
   120
{
insilmaril@0
   121
}
insilmaril@0
   122
insilmaril@746
   123
void LinkableMapObj::unsetParObjTmp()	// FIXME-3 make pure virtual
insilmaril@0
   124
{
insilmaril@0
   125
}
insilmaril@0
   126
insilmaril@164
   127
bool LinkableMapObj::hasParObjTmp()
insilmaril@164
   128
{
insilmaril@164
   129
	if (parObjTmpBuf) return true;
insilmaril@164
   130
	return false;
insilmaril@164
   131
}
insilmaril@164
   132
insilmaril@218
   133
void LinkableMapObj::setUseRelPos (const bool &b)
insilmaril@218
   134
{
insilmaril@218
   135
	useRelPos=b;
insilmaril@218
   136
}
insilmaril@218
   137
insilmaril@218
   138
void LinkableMapObj::setRelPos()
insilmaril@218
   139
{
insilmaril@218
   140
	if (parObj)
insilmaril@218
   141
	{	
insilmaril@395
   142
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@395
   143
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@218
   144
		parObj->calcBBoxSize();
insilmaril@494
   145
	}	
insilmaril@218
   146
}
insilmaril@218
   147
insilmaril@408
   148
void LinkableMapObj::setRelPos(const QPointF &p)
insilmaril@218
   149
{
insilmaril@218
   150
	relPos=p;
insilmaril@218
   151
	if (parObj)
insilmaril@388
   152
	{		
insilmaril@388
   153
		parObj->calcBBoxSize();
insilmaril@388
   154
		requestReposition();
insilmaril@395
   155
	}
insilmaril@218
   156
}
insilmaril@218
   157
insilmaril@408
   158
QPointF LinkableMapObj::getRelPos()
insilmaril@366
   159
{
insilmaril@408
   160
	if (!parObj) return QPointF();
insilmaril@366
   161
	return relPos;
insilmaril@366
   162
}
insilmaril@366
   163
insilmaril@408
   164
qreal LinkableMapObj::getTopPad()
insilmaril@175
   165
{
insilmaril@175
   166
	return topPad;
insilmaril@175
   167
}
insilmaril@175
   168
insilmaril@408
   169
qreal LinkableMapObj::getLeftPad()
insilmaril@175
   170
{
insilmaril@175
   171
	return leftPad;
insilmaril@175
   172
}
insilmaril@175
   173
insilmaril@408
   174
qreal LinkableMapObj::getRightPad()
insilmaril@175
   175
{
insilmaril@175
   176
	return rightPad;
insilmaril@175
   177
}
insilmaril@175
   178
insilmaril@473
   179
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle ()
insilmaril@0
   180
{
insilmaril@773
   181
	VymModel *model=treeItem->getModel();
insilmaril@721
   182
	if (!model)
insilmaril@721
   183
	{
insilmaril@721
   184
		qWarning ("LMO::getDefLinkStyle   model=NULL");
insilmaril@727
   185
		//return UndefinedStyle;
insilmaril@721
   186
	}
insilmaril@721
   187
	Style ls=model->getMapLinkStyle();
insilmaril@755
   188
	int depth=treeItem->depth();
insilmaril@727
   189
	if (depth==0) return UndefinedStyle;
insilmaril@0
   190
	switch (ls)
insilmaril@0
   191
	{
insilmaril@473
   192
		case Line: 
insilmaril@0
   193
			return ls;
insilmaril@0
   194
			break;
insilmaril@473
   195
		case Parabel:
insilmaril@0
   196
			return ls;
insilmaril@0
   197
			break;
insilmaril@473
   198
		case PolyLine:	
insilmaril@0
   199
			if (depth>1)
insilmaril@473
   200
				return Line;
insilmaril@0
   201
			else	
insilmaril@0
   202
				return ls;
insilmaril@0
   203
			break;
insilmaril@473
   204
		case PolyParabel:	
insilmaril@0
   205
			if (depth>1)
insilmaril@473
   206
				return Parabel;
insilmaril@0
   207
			else	
insilmaril@0
   208
				return ls;
insilmaril@0
   209
			break;
insilmaril@0
   210
		default: 
insilmaril@0
   211
			break;	
insilmaril@0
   212
	}	
insilmaril@473
   213
	return UndefinedStyle;
insilmaril@0
   214
}
insilmaril@0
   215
insilmaril@473
   216
void LinkableMapObj::setLinkStyle(Style newstyle)
insilmaril@0
   217
{
insilmaril@746
   218
	//if (newstyle=style) return; FIXME-3
insilmaril@0
   219
	delLink();
insilmaril@0
   220
		
insilmaril@0
   221
	style=newstyle;
insilmaril@0
   222
insilmaril@773
   223
    if (parObj != NULL)
insilmaril@0
   224
    {
insilmaril@408
   225
		QGraphicsLineItem *cl;
insilmaril@0
   226
		switch (style)
insilmaril@0
   227
		{
insilmaril@473
   228
			case UndefinedStyle:
insilmaril@0
   229
				bottomline->hide();
insilmaril@0
   230
				break;
insilmaril@473
   231
			case Line: 
insilmaril@408
   232
				l = scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
   233
				l->setZValue(Z_LINK);
insilmaril@0
   234
				if (visible)
insilmaril@0
   235
					l->show();
insilmaril@0
   236
				else
insilmaril@0
   237
					l->hide();
insilmaril@0
   238
				break;
insilmaril@473
   239
			case Parabel:
insilmaril@408
   240
				for (int i=0;i<arcsegs;i++)
insilmaril@0
   241
				{
insilmaril@408
   242
					cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
insilmaril@408
   243
					cl->setZValue(Z_LINK);
insilmaril@0
   244
					if (visible)
insilmaril@0
   245
						cl->show();
insilmaril@0
   246
					else
insilmaril@0
   247
						cl->hide();
insilmaril@0
   248
					segment.append(cl);
insilmaril@0
   249
				}
insilmaril@0
   250
				pa0.resize (arcsegs+1);
insilmaril@0
   251
				break;
insilmaril@473
   252
			case PolyLine:	
insilmaril@408
   253
				p =scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   254
				p->setZValue(Z_LINK);
insilmaril@0
   255
				if (visible)
insilmaril@0
   256
					p->show();
insilmaril@0
   257
				else
insilmaril@0
   258
					p->hide();
insilmaril@0
   259
				pa0.resize (3);
insilmaril@0
   260
				break;
insilmaril@473
   261
			case PolyParabel:	
insilmaril@408
   262
				p = scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   263
				p->setZValue(Z_LINK);
insilmaril@0
   264
				if (visible)
insilmaril@0
   265
					p->show();
insilmaril@0
   266
				else
insilmaril@0
   267
					p->hide();
insilmaril@0
   268
				pa0.resize (arcsegs*2+2);
insilmaril@0
   269
				pa1.resize (arcsegs+1);
insilmaril@0
   270
				pa2.resize (arcsegs+1);
insilmaril@0
   271
				break;
insilmaril@0
   272
			default: 
insilmaril@0
   273
				break;	
insilmaril@0
   274
		}	
insilmaril@164
   275
	} 
insilmaril@0
   276
}
insilmaril@0
   277
insilmaril@473
   278
LinkableMapObj::Style LinkableMapObj::getLinkStyle()
insilmaril@0
   279
{
insilmaril@0
   280
	return style;
insilmaril@0
   281
}
insilmaril@0
   282
insilmaril@779
   283
void LinkableMapObj::setHideLinkUnselected()
insilmaril@160
   284
{
insilmaril@160
   285
	setVisibility (visible);
insilmaril@779
   286
	updateLinkGeometry();
insilmaril@160
   287
}
insilmaril@160
   288
insilmaril@473
   289
void LinkableMapObj::setLinkPos(Position lp)
insilmaril@0
   290
{
insilmaril@0
   291
	linkpos=lp;
insilmaril@0
   292
}
insilmaril@0
   293
insilmaril@473
   294
LinkableMapObj::Position LinkableMapObj::getLinkPos()
insilmaril@0
   295
{
insilmaril@0
   296
	return linkpos;
insilmaril@0
   297
}
insilmaril@0
   298
insilmaril@0
   299
void LinkableMapObj::setLinkColor()
insilmaril@0
   300
{
insilmaril@721
   301
	// Overloaded in BranchObj and children
insilmaril@0
   302
	// here only set default color
insilmaril@773
   303
	VymModel *model=treeItem->getModel();
insilmaril@721
   304
	if (model)
insilmaril@721
   305
		setLinkColor (model->getMapDefLinkColor());
insilmaril@0
   306
}
insilmaril@0
   307
insilmaril@0
   308
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   309
{
insilmaril@0
   310
	linkcolor=col;
insilmaril@408
   311
	pen.setColor(col);
insilmaril@408
   312
    bottomline->setPen( pen );
insilmaril@0
   313
	switch (style)
insilmaril@0
   314
	{
insilmaril@473
   315
		case Line:
insilmaril@408
   316
			l->setPen( pen);
insilmaril@0
   317
			break;	
insilmaril@473
   318
		case Parabel:	
insilmaril@406
   319
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   320
				segment.at(i)->setPen( pen);
insilmaril@0
   321
			break;
insilmaril@473
   322
		case PolyLine:
insilmaril@0
   323
			p->setBrush( QBrush(col));
insilmaril@497
   324
			p->setPen( pen);
insilmaril@0
   325
			break;
insilmaril@473
   326
		case PolyParabel:	
insilmaril@0
   327
			p->setBrush( QBrush(col));
insilmaril@497
   328
			p->setPen( pen);
insilmaril@0
   329
			break;
insilmaril@0
   330
		default:
insilmaril@0
   331
			break;
insilmaril@755
   332
	} 
insilmaril@0
   333
}
insilmaril@0
   334
insilmaril@0
   335
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   336
{
insilmaril@0
   337
	return linkcolor;
insilmaril@0
   338
}
insilmaril@0
   339
insilmaril@0
   340
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   341
{
insilmaril@0
   342
	MapObj::setVisibility (v);
insilmaril@779
   343
	updateVisibility();
insilmaril@779
   344
}
insilmaril@779
   345
insilmaril@779
   346
void LinkableMapObj::setOrientation()
insilmaril@779
   347
{
insilmaril@779
   348
	Orientation orientOld=orientation;
insilmaril@779
   349
insilmaril@779
   350
	if (!parObj) 
insilmaril@779
   351
	{
insilmaril@779
   352
		orientation=UndefinedOrientation;
insilmaril@779
   353
		return;
insilmaril@779
   354
	}
insilmaril@779
   355
		
insilmaril@779
   356
    // Set orientation, first look for orientation of parent
insilmaril@779
   357
    if (parObj->getOrientation() != UndefinedOrientation ) 
insilmaril@779
   358
		// use the orientation of the parent:
insilmaril@779
   359
		orientation=parObj->getOrientation();
insilmaril@779
   360
    else
insilmaril@779
   361
    {
insilmaril@779
   362
		// calc orientation depending on position rel to parent
insilmaril@779
   363
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@779
   364
			orientation=LeftOfCenter; 
insilmaril@779
   365
		else
insilmaril@779
   366
			orientation=RightOfCenter;
insilmaril@779
   367
    }
insilmaril@779
   368
	if (orientOld!=orientation) requestReposition();
insilmaril@779
   369
}
insilmaril@779
   370
insilmaril@779
   371
void LinkableMapObj::updateVisibility()
insilmaril@779
   372
{
insilmaril@160
   373
	bool visnow=visible;
insilmaril@260
   374
insilmaril@779
   375
	if (((MapItem*)treeItem)->getHideLinkUnselected()
insilmaril@779
   376
		&& treeItem->getModel()->getSelectedLMO() !=this)
insilmaril@160
   377
		visnow=false;
insilmaril@160
   378
insilmaril@160
   379
	if (visnow) 
insilmaril@0
   380
	{
insilmaril@0
   381
		bottomline->show();
insilmaril@160
   382
		switch (style)
insilmaril@0
   383
		{
insilmaril@473
   384
			case Line:
insilmaril@160
   385
				if (l) l->show();
insilmaril@160
   386
				break;
insilmaril@473
   387
			case Parabel:	
insilmaril@406
   388
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   389
					segment.at(i)->show();
insilmaril@160
   390
				break;	
insilmaril@473
   391
			case PolyLine:
insilmaril@779
   392
				if (!p) cout << "LMO::updateVis p==0 (PolyLine)\n"; //FIXME-3
insilmaril@160
   393
				if (p) p->show();
insilmaril@160
   394
				break;
insilmaril@473
   395
			case PolyParabel:	
insilmaril@779
   396
				if (!p) cout << "LMO::updateVis p==0 (PolyParabel) "<<treeItem->getHeading().toStdString()<<endl; //FIXME-3
insilmaril@160
   397
				if (p) p->show();
insilmaril@160
   398
				break;
insilmaril@160
   399
			default:
insilmaril@160
   400
				break;
insilmaril@160
   401
		}
insilmaril@0
   402
	} else 
insilmaril@0
   403
	{
insilmaril@0
   404
		bottomline->hide();
insilmaril@160
   405
		switch (style)
insilmaril@0
   406
		{
insilmaril@473
   407
			case Line:
insilmaril@160
   408
				if (l) l->hide();
insilmaril@160
   409
				break;
insilmaril@473
   410
			case Parabel:	
insilmaril@406
   411
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   412
					segment.at(i)->hide();
insilmaril@160
   413
				break;	
insilmaril@473
   414
			case PolyLine:
insilmaril@160
   415
				if (p) p->hide();
insilmaril@160
   416
				break;
insilmaril@473
   417
			case PolyParabel:	
insilmaril@160
   418
				if (p) p->hide();
insilmaril@160
   419
				break;
insilmaril@160
   420
			default:
insilmaril@160
   421
				break;
insilmaril@160
   422
		}
insilmaril@0
   423
	}	
insilmaril@0
   424
}
insilmaril@0
   425
insilmaril@779
   426
void LinkableMapObj::updateLinkGeometry()
insilmaril@0
   427
{
insilmaril@0
   428
    // needs:
insilmaril@0
   429
    //	childPos of parent
insilmaril@0
   430
    //	orient   of parent
insilmaril@0
   431
    //	style
insilmaril@0
   432
    // 
insilmaril@0
   433
    // sets:
insilmaril@0
   434
    //	orientation
insilmaril@225
   435
    //	childPos	(by calling setDockPos())
insilmaril@225
   436
    //	parPos		(by calling setDockPos())
insilmaril@175
   437
	//  bottomlineY
insilmaril@0
   438
    //	drawing of the link itself
insilmaril@0
   439
insilmaril@779
   440
	// updateLinkGeometry is called from move, but called from constructor we don't
insilmaril@0
   441
	// have parents yet...
insilmaril@775
   442
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@225
   463
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   464
			break;
insilmaril@0
   465
	}
insilmaril@0
   466
	
insilmaril@0
   467
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   468
	if (!link2ParPos)
insilmaril@0
   469
	{
insilmaril@408
   470
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   471
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   472
	} else	
insilmaril@0
   473
	{
insilmaril@408
   474
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   475
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   476
	} 
insilmaril@0
   477
insilmaril@388
   478
	setDockPos(); // Call overloaded method
insilmaril@393
   479
	setOrientation();
insilmaril@0
   480
insilmaril@0
   481
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   482
	double p1y=parPos.y();
insilmaril@0
   483
insilmaril@0
   484
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   485
	double vy=p2y - p1y;
insilmaril@0
   486
insilmaril@0
   487
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@427
   488
	//bottomline->prepareGeometryChange();
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@0
   570
void LinkableMapObj::requestReposition()
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