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