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