linkablemapobj.cpp
author insilmaril
Wed, 15 Mar 2006 13:53:53 +0000
changeset 250 0e994bf2346b
parent 225 d5c70aaca22d
child 260 69d648a0a15b
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@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@160
   406
	if (hideLinkUnselected && !selected)
insilmaril@160
   407
		visnow=false;
insilmaril@160
   408
insilmaril@160
   409
	if (visnow) 
insilmaril@0
   410
	{
insilmaril@0
   411
		bottomline->show();
insilmaril@160
   412
		switch (style)
insilmaril@0
   413
		{
insilmaril@160
   414
			case StyleLine:
insilmaril@160
   415
				if (l) l->show();
insilmaril@160
   416
				break;
insilmaril@160
   417
			case StyleParabel:	
insilmaril@160
   418
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   419
					cl->show();
insilmaril@160
   420
				break;	
insilmaril@160
   421
			case StylePolyLine:
insilmaril@160
   422
				if (p) p->show();
insilmaril@160
   423
				if (l) l->show();
insilmaril@160
   424
				break;
insilmaril@160
   425
			case StylePolyParabel:	
insilmaril@160
   426
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   427
					cl->show();
insilmaril@160
   428
				if (p) p->show();
insilmaril@160
   429
				break;
insilmaril@160
   430
			default:
insilmaril@160
   431
				break;
insilmaril@160
   432
		}
insilmaril@0
   433
	} else 
insilmaril@0
   434
	{
insilmaril@0
   435
		bottomline->hide();
insilmaril@160
   436
		switch (style)
insilmaril@0
   437
		{
insilmaril@160
   438
			case StyleLine:
insilmaril@160
   439
				if (l) l->hide();
insilmaril@160
   440
				break;
insilmaril@160
   441
			case StyleParabel:	
insilmaril@160
   442
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   443
					cl->hide();
insilmaril@160
   444
				break;	
insilmaril@160
   445
			case StylePolyLine:
insilmaril@160
   446
				if (p) p->hide();
insilmaril@160
   447
				if (l) l->hide();
insilmaril@160
   448
				break;
insilmaril@160
   449
			case StylePolyParabel:	
insilmaril@160
   450
				for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@160
   451
					cl->hide();
insilmaril@160
   452
				if (p) p->hide();
insilmaril@160
   453
				break;
insilmaril@160
   454
			default:
insilmaril@160
   455
				break;
insilmaril@160
   456
		}
insilmaril@0
   457
	}	
insilmaril@0
   458
}
insilmaril@0
   459
insilmaril@0
   460
void LinkableMapObj::updateLink()
insilmaril@0
   461
{
insilmaril@0
   462
    // needs:
insilmaril@0
   463
    //	childPos of parent
insilmaril@0
   464
    //	orient   of parent
insilmaril@0
   465
    //	style
insilmaril@0
   466
    // 
insilmaril@0
   467
    // sets:
insilmaril@0
   468
    //	orientation
insilmaril@225
   469
    //	childPos	(by calling setDockPos())
insilmaril@225
   470
    //	parPos		(by calling setDockPos())
insilmaril@175
   471
	//  bottomlineY
insilmaril@0
   472
    //	drawing of the link itself
insilmaril@0
   473
insilmaril@0
   474
	// updateLink is called from move, but called from constructor we don't
insilmaril@0
   475
	// have parents yet...
insilmaril@0
   476
	if (style==StyleUndef) return;	
insilmaril@0
   477
insilmaril@0
   478
	if (frame->getFrameType() == NoFrame)
insilmaril@0
   479
		linkpos=LinkBottom;
insilmaril@0
   480
	else	
insilmaril@0
   481
		linkpos=LinkMiddle;
insilmaril@0
   482
	switch (linkpos)
insilmaril@0
   483
	{
insilmaril@0
   484
		case LinkMiddle:
insilmaril@225
   485
			bottomlineY=bbox.top()+bbox.height() /2;	// draw link to middle (of frame)
insilmaril@0
   486
			break;
insilmaril@0
   487
		default :
insilmaril@225
   488
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   489
			break;
insilmaril@0
   490
	}
insilmaril@0
   491
	
insilmaril@0
   492
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   493
	if (!link2ParPos)
insilmaril@0
   494
	{
insilmaril@0
   495
		p2x=QPoint( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@0
   496
		p2y=QPoint( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   497
	} else	
insilmaril@0
   498
	{
insilmaril@0
   499
		p2x=QPoint( parObj->getParPos() ).x();	
insilmaril@0
   500
		p2y=QPoint( parObj->getParPos() ).y();
insilmaril@0
   501
	} 
insilmaril@0
   502
insilmaril@0
   503
	LinkOrient orientOld=orientation;
insilmaril@0
   504
insilmaril@0
   505
    // Set orientation, first look for orientation of parent
insilmaril@0
   506
    if (parObj->getOrientation() != OrientUndef ) 
insilmaril@0
   507
		// use the orientation of the parent:
insilmaril@0
   508
		orientation=parObj->getOrientation();
insilmaril@0
   509
    else
insilmaril@0
   510
    {
insilmaril@0
   511
		// calc orientation depending on position rel to mapCenter
insilmaril@0
   512
		if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
insilmaril@0
   513
			orientation=OrientLeftOfCenter; 
insilmaril@0
   514
		else
insilmaril@0
   515
			orientation=OrientRightOfCenter;
insilmaril@0
   516
    }
insilmaril@0
   517
insilmaril@0
   518
	if ((orientation!=orientOld) && (orientOld!= OrientUndef))
insilmaril@0
   519
	{
insilmaril@0
   520
		// Orientation just changed. Reorient this subbranch, because move is called
insilmaril@0
   521
		// before updateLink => Position is still the old one, which could lead to 
insilmaril@0
   522
		// linking of subranch to itself => segfault
insilmaril@0
   523
		//
insilmaril@0
   524
		// Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
insilmaril@0
   525
		// no need to reposition now
insilmaril@0
   526
		reposition();
insilmaril@0
   527
	}
insilmaril@0
   528
	
insilmaril@225
   529
	setDockPos();
insilmaril@0
   530
insilmaril@0
   531
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   532
	double p1y=parPos.y();
insilmaril@0
   533
insilmaril@0
   534
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   535
	double vy=p2y - p1y;
insilmaril@0
   536
insilmaril@0
   537
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@104
   538
	bottomline->setPoints (qRound(childPos.x()),
insilmaril@104
   539
		qRound(childPos.y()),
insilmaril@104
   540
		qRound(p1x),
insilmaril@104
   541
		qRound(p1y) );
insilmaril@0
   542
insilmaril@0
   543
	double a;	// angle
insilmaril@0
   544
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   545
		a=M_PI_2;
insilmaril@0
   546
	else
insilmaril@0
   547
		a=atan( vy / vx );
insilmaril@0
   548
	// "turning point" for drawing polygonal links
insilmaril@104
   549
	QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   550
	
insilmaril@0
   551
	QCanvasLine *cl;
insilmaril@0
   552
insilmaril@0
   553
	int i;
insilmaril@0
   554
insilmaril@0
   555
    // Draw the link
insilmaril@0
   556
	switch (style)
insilmaril@0
   557
	{
insilmaril@0
   558
		case StyleLine:
insilmaril@104
   559
			l->setPoints( qRound (parPos.x()),
insilmaril@104
   560
				qRound(parPos.y()),
insilmaril@104
   561
				qRound(p2x),
insilmaril@104
   562
				qRound(p2y) );
insilmaril@0
   563
			break;	
insilmaril@0
   564
		case StyleParabel:	
insilmaril@0
   565
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@0
   566
			i=0;
insilmaril@0
   567
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   568
			{	
insilmaril@0
   569
				cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
insilmaril@0
   570
				i++;
insilmaril@0
   571
			}
insilmaril@0
   572
			break;
insilmaril@0
   573
		case StylePolyLine:
insilmaril@104
   574
			pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@104
   575
			pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@104
   576
			pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@0
   577
			p->setPoints (pa0);
insilmaril@0
   578
			// here too, draw line to avoid missing pixels
insilmaril@104
   579
			l->setPoints( qRound (parPos.x()),
insilmaril@104
   580
				qRound(parPos.y()),
insilmaril@104
   581
				qRound(p2x),
insilmaril@104
   582
				qRound(p2y) );
insilmaril@0
   583
			break;
insilmaril@0
   584
		case StylePolyParabel:	
insilmaril@0
   585
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   586
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@0
   587
			for (i=0;i<=arcsegs;i++)
insilmaril@0
   588
			{
insilmaril@0
   589
				// Combine the arrays to a single one
insilmaril@0
   590
				pa0[i]=pa1[i];
insilmaril@0
   591
				pa0[i+arcsegs+1]=pa2[arcsegs-i];
insilmaril@0
   592
			}	
insilmaril@0
   593
			p->setPoints (pa0);
insilmaril@0
   594
			i=0;
insilmaril@0
   595
			for (cl=segment.first(); cl; cl=segment.next() )
insilmaril@0
   596
			{	
insilmaril@0
   597
				cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
insilmaril@0
   598
				i++;
insilmaril@0
   599
			}
insilmaril@0
   600
			break;
insilmaril@0
   601
		default:
insilmaril@0
   602
			break;
insilmaril@0
   603
	} // switch (style)	
insilmaril@0
   604
}
insilmaril@0
   605
	
insilmaril@0
   606
LinkableMapObj* LinkableMapObj::getChildObj()
insilmaril@0
   607
{
insilmaril@0
   608
    return childObj;
insilmaril@0
   609
}
insilmaril@0
   610
insilmaril@0
   611
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   612
{
insilmaril@0
   613
    return parObj;
insilmaril@0
   614
}
insilmaril@0
   615
insilmaril@106
   616
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
insilmaril@95
   617
{
insilmaril@95
   618
	LinkableMapObj *lmo=this;
insilmaril@95
   619
	QString part;
insilmaril@95
   620
	QString typ;
insilmaril@95
   621
	QString num;
insilmaril@95
   622
	while (!s.isEmpty() )
insilmaril@95
   623
	{
insilmaril@95
   624
		part=s.section(",",0,0);
insilmaril@95
   625
		typ=part.left (3);
insilmaril@95
   626
		num=part.right(part.length() - 3);
insilmaril@95
   627
		if (typ=="mc:")
insilmaril@95
   628
		{
insilmaril@95
   629
			if (depth>0)
insilmaril@95
   630
				return false;	// in a subtree there is no center
insilmaril@95
   631
			else
insilmaril@95
   632
				break;
insilmaril@95
   633
		} else
insilmaril@95
   634
			if (typ=="bo:")
insilmaril@95
   635
				lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
insilmaril@95
   636
			else
insilmaril@95
   637
				if (typ=="fi:")
insilmaril@95
   638
					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
insilmaril@95
   639
		if (!lmo) break;
insilmaril@95
   640
		
insilmaril@95
   641
		if (s.contains(","))
insilmaril@95
   642
			s=s.right(s.length() - part.length() -1 );
insilmaril@95
   643
		else	
insilmaril@95
   644
			break;
insilmaril@95
   645
	}
insilmaril@95
   646
	return lmo;
insilmaril@95
   647
}
insilmaril@95
   648
insilmaril@225
   649
void LinkableMapObj::setDockPos()
insilmaril@225
   650
{
insilmaril@225
   651
	cout <<"LMO::setDockPos()\n";
insilmaril@225
   652
}
insilmaril@225
   653
insilmaril@0
   654
QPoint LinkableMapObj::getChildPos()
insilmaril@0
   655
{
insilmaril@0
   656
    return childPos;
insilmaril@0
   657
}
insilmaril@0
   658
insilmaril@0
   659
QPoint LinkableMapObj::getParPos()
insilmaril@0
   660
{
insilmaril@0
   661
    return parPos;
insilmaril@0
   662
}
insilmaril@0
   663
insilmaril@0
   664
QPoint LinkableMapObj::getRelPos()
insilmaril@0
   665
{
insilmaril@225
   666
	return relPos;
insilmaril@225
   667
/* FIXME not needed? relPos was moved in 1.7.10 from
insilmaril@225
   668
   floatobj to linkablemapobj. Before we had:
insilmaril@225
   669
	
insilmaril@0
   670
	if (!parObj) return QPoint (0,0);
insilmaril@0
   671
    return QPoint(
insilmaril@0
   672
		absPos.x() - parObj->x(),
insilmaril@0
   673
		absPos.y() - parObj->y()
insilmaril@0
   674
	);
insilmaril@225
   675
*/	
insilmaril@0
   676
}
insilmaril@0
   677
insilmaril@218
   678
insilmaril@218
   679
void LinkableMapObj::setUseOrientation (const bool &b)
insilmaril@218
   680
{	
insilmaril@218
   681
	if (useOrientation!=b)
insilmaril@218
   682
	{
insilmaril@218
   683
		useOrientation=b;
insilmaril@218
   684
		requestReposition();
insilmaril@218
   685
	}	
insilmaril@218
   686
}
insilmaril@218
   687
insilmaril@0
   688
LinkOrient LinkableMapObj::getOrientation()
insilmaril@0
   689
{
insilmaril@0
   690
    return orientation;
insilmaril@0
   691
}
insilmaril@0
   692
insilmaril@0
   693
int LinkableMapObj::getDepth()
insilmaril@0
   694
{
insilmaril@0
   695
    return depth;
insilmaril@0
   696
}
insilmaril@0
   697
insilmaril@0
   698
void LinkableMapObj::setMapEditor (MapEditor *me)
insilmaril@0
   699
{
insilmaril@0
   700
	mapEditor=me;
insilmaril@0
   701
}
insilmaril@0
   702
insilmaril@0
   703
MapEditor* LinkableMapObj::getMapEditor ()
insilmaril@0
   704
{
insilmaril@0
   705
	return mapEditor;
insilmaril@0
   706
}
insilmaril@0
   707
insilmaril@0
   708
QPoint LinkableMapObj::getRandPos()
insilmaril@0
   709
{
insilmaril@0
   710
	// Choose a random position with given distance to parent:
insilmaril@0
   711
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@0
   712
    return QPoint ( (int)( + 150*cos (a)),
insilmaril@0
   713
                    (int)( + 150*sin (a)));
insilmaril@0
   714
}
insilmaril@0
   715
insilmaril@0
   716
void LinkableMapObj::alignRelativeTo (QPoint ref)
insilmaril@0
   717
{
insilmaril@166
   718
	// FIXME testing, seems not to be used right now...
insilmaril@95
   719
	cout << "LMO::alignRelTo   ref="<<ref<<endl;
insilmaril@0
   720
}
insilmaril@0
   721
insilmaril@0
   722
void LinkableMapObj::reposition()
insilmaril@0
   723
{
insilmaril@0
   724
	if (depth==0)
insilmaril@0
   725
	{
insilmaril@0
   726
		// only calculate the sizes once. If the deepest LMO changes its height,
insilmaril@0
   727
		// all upper LMOs have to change, too.
insilmaril@0
   728
		calcBBoxSizeWithChilds();
insilmaril@0
   729
insilmaril@0
   730
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
   731
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   732
	} else
insilmaril@0
   733
	{
insilmaril@0
   734
		// This is only important for moving branches:
insilmaril@0
   735
		// For editing a branch it isn't called...
insilmaril@0
   736
	    alignRelativeTo ( QPoint (absPos.x(),
insilmaril@0
   737
							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
insilmaril@0
   738
	}
insilmaril@0
   739
}
insilmaril@0
   740
insilmaril@0
   741
void LinkableMapObj::requestReposition()
insilmaril@0
   742
{
insilmaril@0
   743
	if (!repositionRequest)
insilmaril@0
   744
	{
insilmaril@0
   745
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   746
		// been done yet
insilmaril@0
   747
		repositionRequest=true;
insilmaril@0
   748
		if (parObj) parObj->requestReposition();
insilmaril@0
   749
	}
insilmaril@0
   750
}
insilmaril@0
   751
insilmaril@0
   752
void LinkableMapObj::forceReposition()
insilmaril@0
   753
{
insilmaril@0
   754
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   755
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   756
	// which could collect requests for a reposition.
insilmaril@0
   757
	// Then we have to call forceReposition()
insilmaril@0
   758
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   759
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   760
	// the end, thus check first:
insilmaril@0
   761
insilmaril@139
   762
	if (mapEditor->isRepositionBlocked()) return;
insilmaril@0
   763
	
insilmaril@0
   764
	// Pass on the request to parental objects, if this hasn't been done yet
insilmaril@0
   765
	
insilmaril@0
   766
	if (parObj) 
insilmaril@0
   767
		parObj->forceReposition(); 
insilmaril@0
   768
	else 
insilmaril@83
   769
		reposition(); 
insilmaril@83
   770
}
insilmaril@0
   771
insilmaril@0
   772
bool LinkableMapObj::repositionRequested()
insilmaril@0
   773
{
insilmaril@0
   774
	return repositionRequest;
insilmaril@0
   775
}
insilmaril@0
   776
insilmaril@0
   777
insilmaril@0
   778
void LinkableMapObj::setSelBox()
insilmaril@0
   779
{
insilmaril@175
   780
    selbox->setX (clickBox.x() );
insilmaril@175
   781
    selbox->setY (clickBox.y() );
insilmaril@175
   782
    selbox->setSize (clickBox.width(), clickBox.height() );
insilmaril@0
   783
}
insilmaril@0
   784
insilmaril@0
   785
void LinkableMapObj::select()
insilmaril@0
   786
{
insilmaril@0
   787
	setSelBox();
insilmaril@0
   788
    selected=true;
insilmaril@0
   789
    selbox->show();
insilmaril@160
   790
	setVisibility (visible);
insilmaril@0
   791
}
insilmaril@0
   792
insilmaril@0
   793
insilmaril@0
   794
void LinkableMapObj::unselect()
insilmaril@0
   795
{
insilmaril@0
   796
    selected=false;
insilmaril@0
   797
    selbox->hide();
insilmaril@160
   798
	setVisibility (visible);
insilmaril@0
   799
}
insilmaril@0
   800
insilmaril@0
   801
void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   802
insilmaril@0
   803
{
insilmaril@0
   804
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   805
	double vy=p2y - p1y;
insilmaril@0
   806
insilmaril@0
   807
	double dx;				// delta x during calculation of parabel
insilmaril@0
   808
	
insilmaril@0
   809
	double pnx;				// next point
insilmaril@0
   810
	double pny;
insilmaril@0
   811
	double m;
insilmaril@0
   812
insilmaril@0
   813
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   814
		m=0;
insilmaril@0
   815
	else	
insilmaril@0
   816
		m=(vy / (vx*vx));
insilmaril@0
   817
	dx=vx/(arcsegs);
insilmaril@0
   818
	int i;
insilmaril@104
   819
	ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
insilmaril@0
   820
	for (i=1;i<=arcsegs;i++)
insilmaril@0
   821
	{	
insilmaril@0
   822
		pnx=p1x+dx;
insilmaril@0
   823
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@104
   824
		ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
insilmaril@0
   825
		p1x=pnx;
insilmaril@0
   826
		p1y=pny;
insilmaril@0
   827
	}	
insilmaril@0
   828
}
insilmaril@0
   829
insilmaril@160
   830
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   831
{
insilmaril@160
   832
	if (hideLinkUnselected)
insilmaril@175
   833
		return attribut ("hideLink","true");
insilmaril@160
   834
	else
insilmaril@175
   835
		return attribut ("hideLink","false");
insilmaril@160
   836
	
insilmaril@160
   837
}