linkablemapobj.cpp
author insilmaril
Wed, 31 May 2006 12:27:38 +0000
changeset 334 df4fdaa07527
parent 261 790e3eff9980
child 366 e95081c21da2
permissions -rw-r--r--
1.7.18
insilmaril@139
     1
#include <math.h>
insilmaril@139
     2
insilmaril@0
     3
#include "linkablemapobj.h"
insilmaril@0
     4
#include "branchobj.h"
insilmaril@0
     5
#include "mapeditor.h"
insilmaril@0
     6
insilmaril@0
     7
#include "version.h"
insilmaril@0
     8
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@0
    20
LinkableMapObj::LinkableMapObj(QCanvas* c) :MapObj(c)
insilmaril@0
    21
{
insilmaril@0
    22
//    cout << "Const LinkableMapObj\n";
insilmaril@0
    23
    init ();
insilmaril@0
    24
}
insilmaril@0
    25
insilmaril@0
    26
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
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
    delete (selbox);
insilmaril@0
    35
	delete (frame);
insilmaril@0
    36
	delLink();
insilmaril@0
    37
}
insilmaril@0
    38
insilmaril@0
    39
void LinkableMapObj::delLink()
insilmaril@0
    40
{
insilmaril@0
    41
	switch (style)
insilmaril@0
    42
	{
insilmaril@0
    43
		case StyleLine:
insilmaril@0
    44
			delete (l);
insilmaril@0
    45
			break;
insilmaril@0
    46
		case StyleParabel:
insilmaril@0
    47
			segment.clear();
insilmaril@0
    48
			break;
insilmaril@0
    49
		case StylePolyLine:
insilmaril@0
    50
			delete (p);
insilmaril@0
    51
			delete (l);
insilmaril@0
    52
			break;
insilmaril@0
    53
		case StylePolyParabel:
insilmaril@0
    54
			delete (p);
insilmaril@0
    55
			segment.clear();
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
    depth=-1;	
insilmaril@164
    65
	mapEditor=NULL;
insilmaril@0
    66
    childObj=NULL;
insilmaril@0
    67
    parObj=NULL;
insilmaril@0
    68
    parObjTmpBuf=NULL;
insilmaril@0
    69
    parPos=QPoint(0,0);
insilmaril@0
    70
    childPos=QPoint(0,0);
insilmaril@0
    71
	link2ParPos=false;
insilmaril@0
    72
    l=NULL;
insilmaril@0
    73
    orientation=OrientUndef;
insilmaril@0
    74
    linkwidth=20;		
insilmaril@0
    75
	thickness_start=8;
insilmaril@0
    76
    style=StyleUndef;
insilmaril@0
    77
	linkpos=LinkBottom;
insilmaril@0
    78
    segment.setAutoDelete (TRUE);
insilmaril@0
    79
    arcsegs=13;
insilmaril@0
    80
	QPointArray pa(arcsegs*2+2);
insilmaril@0
    81
    
insilmaril@0
    82
    bottomline=new QCanvasLine(canvas);
insilmaril@0
    83
    bottomline->setPen( QPen(linkcolor, 1) );
insilmaril@0
    84
    bottomline->setZ(Z_LINK);
insilmaril@0
    85
    bottomline->show();
insilmaril@0
    86
insilmaril@0
    87
    // Prepare showing the selection of a MapObj
insilmaril@0
    88
    selbox = new QCanvasRectangle (canvas);
insilmaril@0
    89
    selbox->setZ(Z_SELBOX);
insilmaril@0
    90
    selbox->setBrush( QColor(255,255,0) );
insilmaril@0
    91
    selbox->setPen( QPen(QColor(255,255,0) ));
insilmaril@0
    92
    selbox->hide();
insilmaril@0
    93
    selected=false;
insilmaril@0
    94
insilmaril@160
    95
	hideLinkUnselected=false;
insilmaril@160
    96
insilmaril@175
    97
	topPad=botPad=leftPad=rightPad=0;
insilmaril@175
    98
insilmaril@0
    99
	// initialize frame
insilmaril@0
   100
	frame = new FrameObj (canvas);
insilmaril@0
   101
	
insilmaril@0
   102
	repositionRequest=false;
insilmaril@218
   103
insilmaril@218
   104
	// Rel Positions
insilmaril@218
   105
	relPos=QPoint(0,0);
insilmaril@250
   106
	useRelPos=false;
insilmaril@218
   107
	useOrientation=true;
insilmaril@0
   108
}
insilmaril@0
   109
insilmaril@0
   110
void LinkableMapObj::copy (LinkableMapObj* other)
insilmaril@0
   111
{
insilmaril@0
   112
    MapObj::copy(other);
insilmaril@0
   113
	bboxTotal=other->bboxTotal;
insilmaril@0
   114
    setLinkStyle(other->style);
insilmaril@0
   115
    setLinkColor (other->linkcolor);
insilmaril@218
   116
	relPos=other->relPos;
insilmaril@218
   117
	useOrientation=other->useOrientation;
insilmaril@218
   118
insilmaril@0
   119
}
insilmaril@0
   120
insilmaril@0
   121
void LinkableMapObj::setChildObj(LinkableMapObj* o)
insilmaril@0
   122
{
insilmaril@0
   123
    childObj=o;
insilmaril@0
   124
}
insilmaril@0
   125
insilmaril@0
   126
void LinkableMapObj::setParObj(LinkableMapObj* o)
insilmaril@0
   127
{
insilmaril@0
   128
    parObj=o;
insilmaril@0
   129
	mapEditor=parObj->getMapEditor();
insilmaril@0
   130
}
insilmaril@0
   131
insilmaril@0
   132
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
insilmaril@0
   133
{
insilmaril@0
   134
}
insilmaril@0
   135
insilmaril@0
   136
void LinkableMapObj::unsetParObjTmp()
insilmaril@0
   137
{
insilmaril@0
   138
}
insilmaril@0
   139
insilmaril@164
   140
bool LinkableMapObj::hasParObjTmp()
insilmaril@164
   141
{
insilmaril@164
   142
	if (parObjTmpBuf) return true;
insilmaril@164
   143
	return false;
insilmaril@164
   144
}
insilmaril@164
   145
insilmaril@218
   146
void LinkableMapObj::setUseRelPos (const bool &b)
insilmaril@218
   147
{
insilmaril@218
   148
	useRelPos=b;
insilmaril@218
   149
}
insilmaril@218
   150
insilmaril@218
   151
void LinkableMapObj::setRelPos()
insilmaril@218
   152
{
insilmaril@218
   153
	if (parObj)
insilmaril@218
   154
	{	
insilmaril@225
   155
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@225
   156
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@225
   157
insilmaril@218
   158
		parObj->calcBBoxSize();
insilmaril@218
   159
		parObj->requestReposition();
insilmaril@218
   160
	}	
insilmaril@218
   161
}
insilmaril@218
   162
insilmaril@218
   163
void LinkableMapObj::setRelPos(const QPoint &p)
insilmaril@218
   164
{
insilmaril@218
   165
	relPos=p;
insilmaril@218
   166
	if (parObj)
insilmaril@218
   167
	{	parObj->calcBBoxSize();
insilmaril@218
   168
		parObj->requestReposition();
insilmaril@218
   169
	}	
insilmaril@218
   170
}
insilmaril@218
   171
insilmaril@175
   172
int LinkableMapObj::getTopPad()
insilmaril@175
   173
{
insilmaril@175
   174
	return topPad;
insilmaril@175
   175
}
insilmaril@175
   176
insilmaril@175
   177
int LinkableMapObj::getLeftPad()
insilmaril@175
   178
{
insilmaril@175
   179
	return leftPad;
insilmaril@175
   180
}
insilmaril@175
   181
insilmaril@175
   182
int LinkableMapObj::getRightPad()
insilmaril@175
   183
{
insilmaril@175
   184
	return rightPad;
insilmaril@175
   185
}
insilmaril@175
   186
insilmaril@0
   187
LinkStyle LinkableMapObj::getDefLinkStyle ()
insilmaril@0
   188
{
insilmaril@164
   189
	if (!mapEditor) return StyleUndef;
insilmaril@164
   190
insilmaril@0
   191
	LinkStyle ls=mapEditor->getLinkStyle();
insilmaril@0
   192
	switch (ls)
insilmaril@0
   193
	{
insilmaril@0
   194
		case StyleLine: 
insilmaril@0
   195
			return ls;
insilmaril@0
   196
			break;
insilmaril@0
   197
		case StyleParabel:
insilmaril@0
   198
			return ls;
insilmaril@0
   199
			break;
insilmaril@0
   200
		case StylePolyLine:	
insilmaril@0
   201
			if (depth>1)
insilmaril@0
   202
				return StyleLine;
insilmaril@0
   203
			else	
insilmaril@0
   204
				return ls;
insilmaril@0
   205
			break;
insilmaril@0
   206
		case StylePolyParabel:	
insilmaril@0
   207
			if (depth>1)
insilmaril@0
   208
				return StyleParabel;
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@0
   215
	return StyleUndef;
insilmaril@0
   216
}
insilmaril@0
   217
insilmaril@0
   218
void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
insilmaril@0
   219
{
insilmaril@83
   220
	//if (newstyle=style) return;
insilmaril@0
   221
	delLink();
insilmaril@0
   222
		
insilmaril@0
   223
	style=newstyle;
insilmaril@0
   224
insilmaril@0
   225
    if (childObj!=NULL && parObj != NULL)
insilmaril@0
   226
    {
insilmaril@0
   227
		int i;
insilmaril@0
   228
		QCanvasLine* cl;
insilmaril@0
   229
		switch (style)
insilmaril@0
   230
		{
insilmaril@0
   231
			case StyleUndef:
insilmaril@0
   232
				bottomline->hide();
insilmaril@0
   233
				break;
insilmaril@0
   234
			case StyleLine: 
insilmaril@0
   235
				l = new QCanvasLine(canvas);
insilmaril@0
   236
				l->setPen( QPen(linkcolor, 1) );
insilmaril@0
   237
				l->setZ(Z_LINK);
insilmaril@0
   238
				if (visible)
insilmaril@0
   239
					l->show();
insilmaril@0
   240
				else
insilmaril@0
   241
					l->hide();
insilmaril@0
   242
				break;
insilmaril@0
   243
			case StyleParabel:
insilmaril@0
   244
				for (i=0;i<arcsegs;i++)
insilmaril@0
   245
				{
insilmaril@0
   246
					cl = new QCanvasLine(canvas);
insilmaril@0
   247
					cl->setPen( QPen(linkcolor, 1) );
insilmaril@0
   248
					cl->setPoints( 0,0,i*10,100);
insilmaril@0
   249
					cl->setZ(Z_LINK);
insilmaril@0
   250
					if (visible)
insilmaril@0
   251
						cl->show();
insilmaril@0
   252
					else
insilmaril@0
   253
						cl->hide();
insilmaril@0
   254
					segment.append(cl);
insilmaril@0
   255
				}
insilmaril@0
   256
				pa0.resize (arcsegs+1);
insilmaril@0
   257
				break;
insilmaril@0
   258
			case StylePolyLine:	
insilmaril@0
   259
				p = new QCanvasPolygon(canvas);
insilmaril@0
   260
				p->setBrush( linkcolor );
insilmaril@0
   261
				p->setZ(Z_LINK);
insilmaril@0
   262
				if (visible)
insilmaril@0
   263
					p->show();
insilmaril@0
   264
				else
insilmaril@0
   265
					p->hide();
insilmaril@0
   266
				pa0.resize (3);
insilmaril@164
   267
				// TODO a bit awkward: draw the lines additionally to polygon, to avoid
insilmaril@0
   268
				// missing pixels, when polygon is extremly flat
insilmaril@0
   269
				l = new QCanvasLine(canvas);
insilmaril@0
   270
				l->setPen( QPen(linkcolor, 1) );
insilmaril@0
   271
				l->setZ(Z_LINK);
insilmaril@0
   272
				if (visible)
insilmaril@0
   273
					l->show();
insilmaril@0
   274
				else
insilmaril@0
   275
					l->hide();
insilmaril@0
   276
				break;
insilmaril@0
   277
			case StylePolyParabel:	
insilmaril@0
   278
				p = new QCanvasPolygon(canvas);
insilmaril@0
   279
				p->setBrush( linkcolor );
insilmaril@0
   280
				p->setZ(Z_LINK);
insilmaril@0
   281
				if (visible)
insilmaril@0
   282
					p->show();
insilmaril@0
   283
				else
insilmaril@0
   284
					p->hide();
insilmaril@0
   285
				pa0.resize (arcsegs*2+2);
insilmaril@0
   286
				pa1.resize (arcsegs+1);
insilmaril@0
   287
				pa2.resize (arcsegs+1);
insilmaril@0
   288
insilmaril@164
   289
				// TODO a bit awkward: draw the lines additionally 
insilmaril@0
   290
				// to polygon, to avoid missing pixels, 
insilmaril@0
   291
				// if polygon is extremly flat
insilmaril@0
   292
				for (i=0;i<arcsegs;i++)
insilmaril@0
   293
				{
insilmaril@0
   294
					cl = new QCanvasLine(canvas);
insilmaril@0
   295
					cl->setPen( QPen(linkcolor, 1) );
insilmaril@0
   296
					cl->setPoints( 0,0,i*10,100);
insilmaril@0
   297
					cl->setZ(Z_LINK);
insilmaril@0
   298
					if (visible)
insilmaril@0
   299
						cl->show();
insilmaril@0
   300
					else
insilmaril@0
   301
						cl->hide();
insilmaril@0
   302
					segment.append(cl);
insilmaril@0
   303
				}
insilmaril@0
   304
				break;
insilmaril@0
   305
			default: 
insilmaril@0
   306
				break;	
insilmaril@0
   307
		}	
insilmaril@164
   308
	} 
insilmaril@0
   309
}
insilmaril@0
   310
insilmaril@0
   311
LinkStyle LinkableMapObj::getLinkStyle()
insilmaril@0
   312
{
insilmaril@0
   313
	return style;
insilmaril@0
   314
}
insilmaril@0
   315
insilmaril@160
   316
void LinkableMapObj::setHideLinkUnselected(bool b)
insilmaril@160
   317
{
insilmaril@160
   318
	hideLinkUnselected=b;
insilmaril@160
   319
	setVisibility (visible);
insilmaril@160
   320
	updateLink();
insilmaril@160
   321
}
insilmaril@160
   322
insilmaril@160
   323
bool LinkableMapObj::getHideLinkUnselected()
insilmaril@160
   324
{
insilmaril@160
   325
	return hideLinkUnselected;
insilmaril@160
   326
}
insilmaril@160
   327
insilmaril@0
   328
void LinkableMapObj::setLinkPos(LinkPos lp)
insilmaril@0
   329
{
insilmaril@0
   330
	linkpos=lp;
insilmaril@0
   331
}
insilmaril@0
   332
insilmaril@0
   333
LinkPos LinkableMapObj::getLinkPos()
insilmaril@0
   334
{
insilmaril@0
   335
	return linkpos;
insilmaril@0
   336
}
insilmaril@0
   337
insilmaril@0
   338
insilmaril@0
   339
void LinkableMapObj::setLinkColor()
insilmaril@0
   340
{
insilmaril@0
   341
	// Overloaded in BranchObj and childs
insilmaril@0
   342
	// here only set default color
insilmaril@164
   343
	if (mapEditor)
insilmaril@164
   344
		setLinkColor (mapEditor->getDefLinkColor());
insilmaril@0
   345
}
insilmaril@0
   346
insilmaril@0
   347
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   348
{
insilmaril@0
   349
	linkcolor=col;
insilmaril@0
   350
    bottomline->setPen( QPen(linkcolor, 1) );
insilmaril@0
   351
	QCanvasLine *cl;
insilmaril@0
   352
	switch (style)
insilmaril@0
   353
	{
insilmaril@0
   354
		case StyleLine:
insilmaril@0
   355
			l->setPen( QPen(col,1));
insilmaril@0
   356
			break;	
insilmaril@0
   357
		case StyleParabel:	
insilmaril@0
   358
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   359
				cl->setPen( QPen(col,1));
insilmaril@0
   360
			break;
insilmaril@0
   361
		case StylePolyLine:
insilmaril@0
   362
			p->setBrush( QBrush(col));
insilmaril@0
   363
			l->setPen( QPen(col,1));
insilmaril@0
   364
			break;
insilmaril@0
   365
		case StylePolyParabel:	
insilmaril@0
   366
			p->setBrush( QBrush(col));
insilmaril@0
   367
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   368
				cl->setPen( QPen(col,1));
insilmaril@0
   369
			break;
insilmaril@0
   370
		default:
insilmaril@0
   371
			break;
insilmaril@0
   372
	} // switch (style)	
insilmaril@0
   373
}
insilmaril@0
   374
insilmaril@0
   375
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   376
{
insilmaril@0
   377
	return linkcolor;
insilmaril@0
   378
}
insilmaril@0
   379
insilmaril@0
   380
FrameType LinkableMapObj::getFrameType()
insilmaril@0
   381
{
insilmaril@0
   382
	return frame->getFrameType();
insilmaril@0
   383
}
insilmaril@0
   384
insilmaril@0
   385
void LinkableMapObj::setFrameType(const FrameType &t)
insilmaril@0
   386
{
insilmaril@0
   387
	frame->setFrameType(t);
insilmaril@0
   388
	calcBBoxSize();
insilmaril@0
   389
	positionBBox();
insilmaril@0
   390
	requestReposition();
insilmaril@0
   391
}
insilmaril@0
   392
insilmaril@0
   393
void LinkableMapObj::setFrameType(const QString &t)
insilmaril@0
   394
{
insilmaril@0
   395
	frame->setFrameType(t);
insilmaril@0
   396
	calcBBoxSize();
insilmaril@0
   397
	positionBBox();
insilmaril@0
   398
	requestReposition();
insilmaril@0
   399
}
insilmaril@0
   400
insilmaril@0
   401
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   402
{
insilmaril@160
   403
	QCanvasLine* cl;
insilmaril@0
   404
	MapObj::setVisibility (v);
insilmaril@160
   405
	bool visnow=visible;
insilmaril@260
   406
insilmaril@260
   407
	// We can hide the link, while object is not selected
insilmaril@160
   408
	if (hideLinkUnselected && !selected)
insilmaril@160
   409
		visnow=false;
insilmaril@160
   410
insilmaril@160
   411
	if (visnow) 
insilmaril@0
   412
	{
insilmaril@0
   413
		bottomline->show();
insilmaril@160
   414
		switch (style)
insilmaril@0
   415
		{
insilmaril@160
   416
			case StyleLine:
insilmaril@160
   417
				if (l) l->show();
insilmaril@160
   418
				break;
insilmaril@160
   419
			case StyleParabel:	
insilmaril@160
   420
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   421
					cl->show();
insilmaril@160
   422
				break;	
insilmaril@160
   423
			case StylePolyLine:
insilmaril@160
   424
				if (p) p->show();
insilmaril@160
   425
				if (l) l->show();
insilmaril@160
   426
				break;
insilmaril@160
   427
			case StylePolyParabel:	
insilmaril@160
   428
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   429
					cl->show();
insilmaril@160
   430
				if (p) p->show();
insilmaril@160
   431
				break;
insilmaril@160
   432
			default:
insilmaril@160
   433
				break;
insilmaril@160
   434
		}
insilmaril@0
   435
	} else 
insilmaril@0
   436
	{
insilmaril@0
   437
		bottomline->hide();
insilmaril@160
   438
		switch (style)
insilmaril@0
   439
		{
insilmaril@160
   440
			case StyleLine:
insilmaril@160
   441
				if (l) l->hide();
insilmaril@160
   442
				break;
insilmaril@160
   443
			case StyleParabel:	
insilmaril@160
   444
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   445
					cl->hide();
insilmaril@160
   446
				break;	
insilmaril@160
   447
			case StylePolyLine:
insilmaril@160
   448
				if (p) p->hide();
insilmaril@160
   449
				if (l) l->hide();
insilmaril@160
   450
				break;
insilmaril@160
   451
			case StylePolyParabel:	
insilmaril@160
   452
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   453
					cl->hide();
insilmaril@160
   454
				if (p) p->hide();
insilmaril@160
   455
				break;
insilmaril@160
   456
			default:
insilmaril@160
   457
				break;
insilmaril@160
   458
		}
insilmaril@0
   459
	}	
insilmaril@0
   460
}
insilmaril@0
   461
insilmaril@0
   462
void LinkableMapObj::updateLink()
insilmaril@0
   463
{
insilmaril@0
   464
    // needs:
insilmaril@0
   465
    //	childPos of parent
insilmaril@0
   466
    //	orient   of parent
insilmaril@0
   467
    //	style
insilmaril@0
   468
    // 
insilmaril@0
   469
    // sets:
insilmaril@0
   470
    //	orientation
insilmaril@225
   471
    //	childPos	(by calling setDockPos())
insilmaril@225
   472
    //	parPos		(by calling setDockPos())
insilmaril@175
   473
	//  bottomlineY
insilmaril@0
   474
    //	drawing of the link itself
insilmaril@0
   475
insilmaril@0
   476
	// updateLink is called from move, but called from constructor we don't
insilmaril@0
   477
	// have parents yet...
insilmaril@0
   478
	if (style==StyleUndef) return;	
insilmaril@0
   479
insilmaril@0
   480
	if (frame->getFrameType() == NoFrame)
insilmaril@0
   481
		linkpos=LinkBottom;
insilmaril@0
   482
	else	
insilmaril@0
   483
		linkpos=LinkMiddle;
insilmaril@0
   484
	switch (linkpos)
insilmaril@0
   485
	{
insilmaril@0
   486
		case LinkMiddle:
insilmaril@225
   487
			bottomlineY=bbox.top()+bbox.height() /2;	// draw link to middle (of frame)
insilmaril@0
   488
			break;
insilmaril@0
   489
		default :
insilmaril@225
   490
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   491
			break;
insilmaril@0
   492
	}
insilmaril@0
   493
	
insilmaril@0
   494
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   495
	if (!link2ParPos)
insilmaril@0
   496
	{
insilmaril@0
   497
		p2x=QPoint( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@0
   498
		p2y=QPoint( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   499
	} else	
insilmaril@0
   500
	{
insilmaril@0
   501
		p2x=QPoint( parObj->getParPos() ).x();	
insilmaril@0
   502
		p2y=QPoint( parObj->getParPos() ).y();
insilmaril@0
   503
	} 
insilmaril@0
   504
insilmaril@0
   505
	LinkOrient orientOld=orientation;
insilmaril@0
   506
insilmaril@0
   507
    // Set orientation, first look for orientation of parent
insilmaril@0
   508
    if (parObj->getOrientation() != OrientUndef ) 
insilmaril@0
   509
		// use the orientation of the parent:
insilmaril@0
   510
		orientation=parObj->getOrientation();
insilmaril@0
   511
    else
insilmaril@0
   512
    {
insilmaril@0
   513
		// calc orientation depending on position rel to mapCenter
insilmaril@0
   514
		if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
insilmaril@0
   515
			orientation=OrientLeftOfCenter; 
insilmaril@0
   516
		else
insilmaril@0
   517
			orientation=OrientRightOfCenter;
insilmaril@0
   518
    }
insilmaril@0
   519
insilmaril@0
   520
	if ((orientation!=orientOld) && (orientOld!= OrientUndef))
insilmaril@0
   521
	{
insilmaril@0
   522
		// Orientation just changed. Reorient this subbranch, because move is called
insilmaril@0
   523
		// before updateLink => Position is still the old one, which could lead to 
insilmaril@0
   524
		// linking of subranch to itself => segfault
insilmaril@0
   525
		//
insilmaril@0
   526
		// Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
insilmaril@0
   527
		// no need to reposition now
insilmaril@0
   528
		reposition();
insilmaril@0
   529
	}
insilmaril@0
   530
	
insilmaril@225
   531
	setDockPos();
insilmaril@0
   532
insilmaril@0
   533
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   534
	double p1y=parPos.y();
insilmaril@0
   535
insilmaril@0
   536
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   537
	double vy=p2y - p1y;
insilmaril@0
   538
insilmaril@0
   539
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@104
   540
	bottomline->setPoints (qRound(childPos.x()),
insilmaril@104
   541
		qRound(childPos.y()),
insilmaril@104
   542
		qRound(p1x),
insilmaril@104
   543
		qRound(p1y) );
insilmaril@0
   544
insilmaril@0
   545
	double a;	// angle
insilmaril@0
   546
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   547
		a=M_PI_2;
insilmaril@0
   548
	else
insilmaril@0
   549
		a=atan( vy / vx );
insilmaril@0
   550
	// "turning point" for drawing polygonal links
insilmaril@104
   551
	QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   552
	
insilmaril@0
   553
	QCanvasLine *cl;
insilmaril@0
   554
insilmaril@0
   555
	int i;
insilmaril@0
   556
insilmaril@0
   557
    // Draw the link
insilmaril@0
   558
	switch (style)
insilmaril@0
   559
	{
insilmaril@0
   560
		case StyleLine:
insilmaril@104
   561
			l->setPoints( qRound (parPos.x()),
insilmaril@104
   562
				qRound(parPos.y()),
insilmaril@104
   563
				qRound(p2x),
insilmaril@104
   564
				qRound(p2y) );
insilmaril@0
   565
			break;	
insilmaril@0
   566
		case StyleParabel:	
insilmaril@0
   567
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@0
   568
			i=0;
insilmaril@0
   569
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   570
			{	
insilmaril@0
   571
				cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
insilmaril@0
   572
				i++;
insilmaril@0
   573
			}
insilmaril@0
   574
			break;
insilmaril@0
   575
		case StylePolyLine:
insilmaril@104
   576
			pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@104
   577
			pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@104
   578
			pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@0
   579
			p->setPoints (pa0);
insilmaril@0
   580
			// here too, draw line to avoid missing pixels
insilmaril@104
   581
			l->setPoints( qRound (parPos.x()),
insilmaril@104
   582
				qRound(parPos.y()),
insilmaril@104
   583
				qRound(p2x),
insilmaril@104
   584
				qRound(p2y) );
insilmaril@0
   585
			break;
insilmaril@0
   586
		case StylePolyParabel:	
insilmaril@0
   587
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   588
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@0
   589
			for (i=0;i<=arcsegs;i++)
insilmaril@0
   590
			{
insilmaril@0
   591
				// Combine the arrays to a single one
insilmaril@0
   592
				pa0[i]=pa1[i];
insilmaril@0
   593
				pa0[i+arcsegs+1]=pa2[arcsegs-i];
insilmaril@0
   594
			}	
insilmaril@0
   595
			p->setPoints (pa0);
insilmaril@0
   596
			i=0;
insilmaril@0
   597
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   598
			{	
insilmaril@0
   599
				cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
insilmaril@0
   600
				i++;
insilmaril@0
   601
			}
insilmaril@0
   602
			break;
insilmaril@0
   603
		default:
insilmaril@0
   604
			break;
insilmaril@0
   605
	} // switch (style)	
insilmaril@0
   606
}
insilmaril@0
   607
	
insilmaril@0
   608
LinkableMapObj* LinkableMapObj::getChildObj()
insilmaril@0
   609
{
insilmaril@0
   610
    return childObj;
insilmaril@0
   611
}
insilmaril@0
   612
insilmaril@0
   613
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   614
{
insilmaril@0
   615
    return parObj;
insilmaril@0
   616
}
insilmaril@0
   617
insilmaril@106
   618
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
insilmaril@95
   619
{
insilmaril@95
   620
	LinkableMapObj *lmo=this;
insilmaril@95
   621
	QString part;
insilmaril@95
   622
	QString typ;
insilmaril@95
   623
	QString num;
insilmaril@95
   624
	while (!s.isEmpty() )
insilmaril@95
   625
	{
insilmaril@95
   626
		part=s.section(",",0,0);
insilmaril@95
   627
		typ=part.left (3);
insilmaril@95
   628
		num=part.right(part.length() - 3);
insilmaril@95
   629
		if (typ=="mc:")
insilmaril@95
   630
		{
insilmaril@95
   631
			if (depth>0)
insilmaril@95
   632
				return false;	// in a subtree there is no center
insilmaril@95
   633
			else
insilmaril@95
   634
				break;
insilmaril@95
   635
		} else
insilmaril@95
   636
			if (typ=="bo:")
insilmaril@95
   637
				lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
insilmaril@95
   638
			else
insilmaril@95
   639
				if (typ=="fi:")
insilmaril@95
   640
					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
insilmaril@95
   641
		if (!lmo) break;
insilmaril@95
   642
		
insilmaril@95
   643
		if (s.contains(","))
insilmaril@95
   644
			s=s.right(s.length() - part.length() -1 );
insilmaril@95
   645
		else	
insilmaril@95
   646
			break;
insilmaril@95
   647
	}
insilmaril@95
   648
	return lmo;
insilmaril@95
   649
}
insilmaril@95
   650
insilmaril@225
   651
void LinkableMapObj::setDockPos()
insilmaril@225
   652
{
insilmaril@225
   653
	cout <<"LMO::setDockPos()\n";
insilmaril@225
   654
}
insilmaril@225
   655
insilmaril@0
   656
QPoint LinkableMapObj::getChildPos()
insilmaril@0
   657
{
insilmaril@0
   658
    return childPos;
insilmaril@0
   659
}
insilmaril@0
   660
insilmaril@0
   661
QPoint LinkableMapObj::getParPos()
insilmaril@0
   662
{
insilmaril@0
   663
    return parPos;
insilmaril@0
   664
}
insilmaril@0
   665
insilmaril@0
   666
QPoint LinkableMapObj::getRelPos()
insilmaril@0
   667
{
insilmaril@225
   668
	return relPos;
insilmaril@225
   669
/* FIXME not needed? relPos was moved in 1.7.10 from
insilmaril@225
   670
   floatobj to linkablemapobj. Before we had:
insilmaril@225
   671
	
insilmaril@0
   672
	if (!parObj) return QPoint (0,0);
insilmaril@0
   673
    return QPoint(
insilmaril@0
   674
		absPos.x() - parObj->x(),
insilmaril@0
   675
		absPos.y() - parObj->y()
insilmaril@0
   676
	);
insilmaril@225
   677
*/	
insilmaril@0
   678
}
insilmaril@0
   679
insilmaril@218
   680
insilmaril@218
   681
void LinkableMapObj::setUseOrientation (const bool &b)
insilmaril@218
   682
{	
insilmaril@218
   683
	if (useOrientation!=b)
insilmaril@218
   684
	{
insilmaril@218
   685
		useOrientation=b;
insilmaril@218
   686
		requestReposition();
insilmaril@218
   687
	}	
insilmaril@218
   688
}
insilmaril@218
   689
insilmaril@0
   690
LinkOrient LinkableMapObj::getOrientation()
insilmaril@0
   691
{
insilmaril@0
   692
    return orientation;
insilmaril@0
   693
}
insilmaril@0
   694
insilmaril@0
   695
int LinkableMapObj::getDepth()
insilmaril@0
   696
{
insilmaril@0
   697
    return depth;
insilmaril@0
   698
}
insilmaril@0
   699
insilmaril@0
   700
void LinkableMapObj::setMapEditor (MapEditor *me)
insilmaril@0
   701
{
insilmaril@0
   702
	mapEditor=me;
insilmaril@0
   703
}
insilmaril@0
   704
insilmaril@0
   705
MapEditor* LinkableMapObj::getMapEditor ()
insilmaril@0
   706
{
insilmaril@0
   707
	return mapEditor;
insilmaril@0
   708
}
insilmaril@0
   709
insilmaril@0
   710
QPoint LinkableMapObj::getRandPos()
insilmaril@0
   711
{
insilmaril@0
   712
	// Choose a random position with given distance to parent:
insilmaril@0
   713
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@0
   714
    return QPoint ( (int)( + 150*cos (a)),
insilmaril@0
   715
                    (int)( + 150*sin (a)));
insilmaril@0
   716
}
insilmaril@0
   717
insilmaril@0
   718
void LinkableMapObj::alignRelativeTo (QPoint ref)
insilmaril@0
   719
{
insilmaril@166
   720
	// FIXME testing, seems not to be used right now...
insilmaril@95
   721
	cout << "LMO::alignRelTo   ref="<<ref<<endl;
insilmaril@0
   722
}
insilmaril@0
   723
insilmaril@0
   724
void LinkableMapObj::reposition()
insilmaril@0
   725
{
insilmaril@0
   726
	if (depth==0)
insilmaril@0
   727
	{
insilmaril@0
   728
		// only calculate the sizes once. If the deepest LMO changes its height,
insilmaril@0
   729
		// all upper LMOs have to change, too.
insilmaril@0
   730
		calcBBoxSizeWithChilds();
insilmaril@0
   731
insilmaril@0
   732
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
   733
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   734
	} else
insilmaril@0
   735
	{
insilmaril@0
   736
		// This is only important for moving branches:
insilmaril@0
   737
		// For editing a branch it isn't called...
insilmaril@0
   738
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
   739
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   740
	}
insilmaril@0
   741
}
insilmaril@0
   742
insilmaril@0
   743
void LinkableMapObj::requestReposition()
insilmaril@0
   744
{
insilmaril@0
   745
	if (!repositionRequest)
insilmaril@0
   746
	{
insilmaril@0
   747
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   748
		// been done yet
insilmaril@0
   749
		repositionRequest=true;
insilmaril@0
   750
		if (parObj) parObj->requestReposition();
insilmaril@0
   751
	}
insilmaril@0
   752
}
insilmaril@0
   753
insilmaril@0
   754
void LinkableMapObj::forceReposition()
insilmaril@0
   755
{
insilmaril@0
   756
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   757
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   758
	// which could collect requests for a reposition.
insilmaril@0
   759
	// Then we have to call forceReposition()
insilmaril@0
   760
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   761
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   762
	// the end, thus check first:
insilmaril@0
   763
insilmaril@139
   764
	if (mapEditor->isRepositionBlocked()) return;
insilmaril@0
   765
	
insilmaril@0
   766
	// Pass on the request to parental objects, if this hasn't been done yet
insilmaril@0
   767
	
insilmaril@0
   768
	if (parObj) 
insilmaril@0
   769
		parObj->forceReposition(); 
insilmaril@0
   770
	else 
insilmaril@83
   771
		reposition(); 
insilmaril@83
   772
}
insilmaril@0
   773
insilmaril@0
   774
bool LinkableMapObj::repositionRequested()
insilmaril@0
   775
{
insilmaril@0
   776
	return repositionRequest;
insilmaril@0
   777
}
insilmaril@0
   778
insilmaril@0
   779
insilmaril@0
   780
void LinkableMapObj::setSelBox()
insilmaril@0
   781
{
insilmaril@175
   782
    selbox->setX (clickBox.x() );
insilmaril@175
   783
    selbox->setY (clickBox.y() );
insilmaril@175
   784
    selbox->setSize (clickBox.width(), clickBox.height() );
insilmaril@0
   785
}
insilmaril@0
   786
insilmaril@0
   787
void LinkableMapObj::select()
insilmaril@0
   788
{
insilmaril@0
   789
	setSelBox();
insilmaril@0
   790
    selected=true;
insilmaril@0
   791
    selbox->show();
insilmaril@260
   792
// FIXME not needed?	
insilmaril@261
   793
	setVisibility (visible);
insilmaril@0
   794
}
insilmaril@0
   795
insilmaril@0
   796
insilmaril@0
   797
void LinkableMapObj::unselect()
insilmaril@0
   798
{
insilmaril@0
   799
    selected=false;
insilmaril@0
   800
    selbox->hide();
insilmaril@261
   801
	// Maybe we have to hide the link:
insilmaril@261
   802
	setVisibility (visible);
insilmaril@0
   803
}
insilmaril@0
   804
insilmaril@0
   805
void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   806
insilmaril@0
   807
{
insilmaril@0
   808
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   809
	double vy=p2y - p1y;
insilmaril@0
   810
insilmaril@0
   811
	double dx;				// delta x during calculation of parabel
insilmaril@0
   812
	
insilmaril@0
   813
	double pnx;				// next point
insilmaril@0
   814
	double pny;
insilmaril@0
   815
	double m;
insilmaril@0
   816
insilmaril@0
   817
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   818
		m=0;
insilmaril@0
   819
	else	
insilmaril@0
   820
		m=(vy / (vx*vx));
insilmaril@0
   821
	dx=vx/(arcsegs);
insilmaril@0
   822
	int i;
insilmaril@104
   823
	ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
insilmaril@0
   824
	for (i=1;i<=arcsegs;i++)
insilmaril@0
   825
	{	
insilmaril@0
   826
		pnx=p1x+dx;
insilmaril@0
   827
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@104
   828
		ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
insilmaril@0
   829
		p1x=pnx;
insilmaril@0
   830
		p1y=pny;
insilmaril@0
   831
	}	
insilmaril@0
   832
}
insilmaril@0
   833
insilmaril@160
   834
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   835
{
insilmaril@160
   836
	if (hideLinkUnselected)
insilmaril@175
   837
		return attribut ("hideLink","true");
insilmaril@160
   838
	else
insilmaril@175
   839
		return attribut ("hideLink","false");
insilmaril@160
   840
	
insilmaril@160
   841
}