linkablemapobj.cpp
author insilmaril
Wed, 11 Apr 2007 09:21:16 +0000
changeset 455 1462e380b82b
parent 442 dfbc371b7280
child 473 8b9cfc26638c
permissions -rw-r--r--
Updated documentation about macros
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
/////////////////////////////////////////////////////////////////
insilmaril@0
     8
// LinkableMapObj
insilmaril@0
     9
/////////////////////////////////////////////////////////////////
insilmaril@0
    10
insilmaril@0
    11
LinkableMapObj::LinkableMapObj():MapObj()
insilmaril@0
    12
{
insilmaril@0
    13
  //  cout << "Const LinkableMapObj ()\n";
insilmaril@0
    14
    init ();
insilmaril@0
    15
}
insilmaril@0
    16
insilmaril@408
    17
LinkableMapObj::LinkableMapObj(QGraphicsScene* s) :MapObj(s)
insilmaril@0
    18
{
insilmaril@408
    19
//    cout << "Const LinkableMapObj (s)\n";
insilmaril@0
    20
    init ();
insilmaril@0
    21
}
insilmaril@0
    22
insilmaril@408
    23
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
insilmaril@0
    24
{
insilmaril@0
    25
    copy (lmo);
insilmaril@0
    26
}
insilmaril@0
    27
insilmaril@0
    28
LinkableMapObj::~LinkableMapObj()
insilmaril@0
    29
{
insilmaril@0
    30
    delete (bottomline);
insilmaril@0
    31
	delLink();
insilmaril@0
    32
}
insilmaril@0
    33
insilmaril@0
    34
void LinkableMapObj::delLink()
insilmaril@0
    35
{
insilmaril@0
    36
	switch (style)
insilmaril@0
    37
	{
insilmaril@0
    38
		case StyleLine:
insilmaril@0
    39
			delete (l);
insilmaril@0
    40
			break;
insilmaril@0
    41
		case StyleParabel:
insilmaril@406
    42
			while (!segment.isEmpty()) delete segment.takeFirst();
insilmaril@0
    43
			break;
insilmaril@0
    44
		case StylePolyLine:
insilmaril@0
    45
			delete (p);
insilmaril@0
    46
			break;
insilmaril@0
    47
		case StylePolyParabel:
insilmaril@0
    48
			delete (p);
insilmaril@0
    49
			break;
insilmaril@0
    50
		default:
insilmaril@0
    51
			break;
insilmaril@0
    52
	}		
insilmaril@0
    53
}
insilmaril@0
    54
insilmaril@0
    55
void LinkableMapObj::init ()
insilmaril@0
    56
{
insilmaril@0
    57
    depth=-1;	
insilmaril@164
    58
	mapEditor=NULL;
insilmaril@0
    59
    childObj=NULL;
insilmaril@0
    60
    parObj=NULL;
insilmaril@0
    61
    parObjTmpBuf=NULL;
insilmaril@408
    62
    parPos=QPointF(0,0);
insilmaril@408
    63
    childPos=QPointF(0,0);
insilmaril@0
    64
	link2ParPos=false;
insilmaril@0
    65
    l=NULL;
insilmaril@0
    66
    orientation=OrientUndef;
insilmaril@0
    67
    linkwidth=20;		
insilmaril@0
    68
	thickness_start=8;
insilmaril@0
    69
    style=StyleUndef;
insilmaril@0
    70
	linkpos=LinkBottom;
insilmaril@0
    71
    arcsegs=13;
insilmaril@0
    72
    
insilmaril@412
    73
// TODO instead of linkcolor pen.color() could be used	all around
insilmaril@408
    74
	pen.setWidth (1);
insilmaril@408
    75
	pen.setColor (linkcolor);
insilmaril@408
    76
	pen.setCapStyle ( Qt::RoundCap );
insilmaril@408
    77
	bottomline=scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
    78
    bottomline->setZValue(Z_LINK);
insilmaril@0
    79
    bottomline->show();
insilmaril@0
    80
insilmaril@0
    81
    // Prepare showing the selection of a MapObj
insilmaril@0
    82
    selected=false;
insilmaril@0
    83
insilmaril@160
    84
	hideLinkUnselected=false;
insilmaril@160
    85
insilmaril@175
    86
	topPad=botPad=leftPad=rightPad=0;
insilmaril@175
    87
insilmaril@0
    88
	repositionRequest=false;
insilmaril@218
    89
insilmaril@218
    90
	// Rel Positions
insilmaril@408
    91
	relPos=QPointF(0,0);
insilmaril@250
    92
	useRelPos=false;
insilmaril@218
    93
	useOrientation=true;
insilmaril@0
    94
}
insilmaril@0
    95
insilmaril@0
    96
void LinkableMapObj::copy (LinkableMapObj* other)
insilmaril@0
    97
{
insilmaril@0
    98
    MapObj::copy(other);
insilmaril@0
    99
	bboxTotal=other->bboxTotal;
insilmaril@0
   100
    setLinkStyle(other->style);
insilmaril@0
   101
    setLinkColor (other->linkcolor);
insilmaril@218
   102
	relPos=other->relPos;
insilmaril@218
   103
	useOrientation=other->useOrientation;
insilmaril@218
   104
insilmaril@0
   105
}
insilmaril@0
   106
insilmaril@0
   107
void LinkableMapObj::setChildObj(LinkableMapObj* o)
insilmaril@0
   108
{
insilmaril@0
   109
    childObj=o;
insilmaril@0
   110
}
insilmaril@0
   111
insilmaril@0
   112
void LinkableMapObj::setParObj(LinkableMapObj* o)
insilmaril@0
   113
{
insilmaril@0
   114
    parObj=o;
insilmaril@0
   115
	mapEditor=parObj->getMapEditor();
insilmaril@0
   116
}
insilmaril@0
   117
insilmaril@408
   118
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)
insilmaril@0
   119
{
insilmaril@0
   120
}
insilmaril@0
   121
insilmaril@0
   122
void LinkableMapObj::unsetParObjTmp()
insilmaril@0
   123
{
insilmaril@0
   124
}
insilmaril@0
   125
insilmaril@164
   126
bool LinkableMapObj::hasParObjTmp()
insilmaril@164
   127
{
insilmaril@164
   128
	if (parObjTmpBuf) return true;
insilmaril@164
   129
	return false;
insilmaril@164
   130
}
insilmaril@164
   131
insilmaril@218
   132
void LinkableMapObj::setUseRelPos (const bool &b)
insilmaril@218
   133
{
insilmaril@218
   134
	useRelPos=b;
insilmaril@218
   135
}
insilmaril@218
   136
insilmaril@218
   137
void LinkableMapObj::setRelPos()
insilmaril@218
   138
{
insilmaril@218
   139
	if (parObj)
insilmaril@218
   140
	{	
insilmaril@395
   141
		relPos.setX (absPos.x() - parObj->getChildPos().x() );
insilmaril@395
   142
		relPos.setY (absPos.y() - parObj->getChildPos().y() );
insilmaril@218
   143
		parObj->calcBBoxSize();
insilmaril@395
   144
	}	else
insilmaril@395
   145
	{
insilmaril@395
   146
		qWarning ("LMO::setRelPos   No parent yet!");
insilmaril@395
   147
	}
insilmaril@218
   148
}
insilmaril@218
   149
insilmaril@408
   150
void LinkableMapObj::setRelPos(const QPointF &p)
insilmaril@218
   151
{
insilmaril@218
   152
	relPos=p;
insilmaril@218
   153
	if (parObj)
insilmaril@388
   154
	{		
insilmaril@388
   155
		parObj->calcBBoxSize();
insilmaril@388
   156
		requestReposition();
insilmaril@395
   157
	}	else
insilmaril@395
   158
	{
insilmaril@395
   159
		qWarning ("LMO::setRelPos   No parent yet!");
insilmaril@395
   160
	}
insilmaril@218
   161
}
insilmaril@218
   162
insilmaril@408
   163
QPointF LinkableMapObj::getRelPos()
insilmaril@366
   164
{
insilmaril@408
   165
	if (!parObj) return QPointF();
insilmaril@366
   166
	return relPos;
insilmaril@366
   167
}
insilmaril@366
   168
insilmaril@408
   169
qreal LinkableMapObj::getTopPad()
insilmaril@175
   170
{
insilmaril@175
   171
	return topPad;
insilmaril@175
   172
}
insilmaril@175
   173
insilmaril@408
   174
qreal LinkableMapObj::getLeftPad()
insilmaril@175
   175
{
insilmaril@175
   176
	return leftPad;
insilmaril@175
   177
}
insilmaril@175
   178
insilmaril@408
   179
qreal LinkableMapObj::getRightPad()
insilmaril@175
   180
{
insilmaril@175
   181
	return rightPad;
insilmaril@175
   182
}
insilmaril@175
   183
insilmaril@0
   184
LinkStyle LinkableMapObj::getDefLinkStyle ()
insilmaril@0
   185
{
insilmaril@406
   186
	if (mapEditor==0) return StyleUndef;
insilmaril@398
   187
	LinkStyle ls=mapEditor->getMapLinkStyle();
insilmaril@0
   188
	switch (ls)
insilmaril@0
   189
	{
insilmaril@0
   190
		case StyleLine: 
insilmaril@0
   191
			return ls;
insilmaril@0
   192
			break;
insilmaril@0
   193
		case StyleParabel:
insilmaril@0
   194
			return ls;
insilmaril@0
   195
			break;
insilmaril@0
   196
		case StylePolyLine:	
insilmaril@0
   197
			if (depth>1)
insilmaril@0
   198
				return StyleLine;
insilmaril@0
   199
			else	
insilmaril@0
   200
				return ls;
insilmaril@0
   201
			break;
insilmaril@0
   202
		case StylePolyParabel:	
insilmaril@0
   203
			if (depth>1)
insilmaril@0
   204
				return StyleParabel;
insilmaril@0
   205
			else	
insilmaril@0
   206
				return ls;
insilmaril@0
   207
			break;
insilmaril@0
   208
		default: 
insilmaril@0
   209
			break;	
insilmaril@0
   210
	}	
insilmaril@0
   211
	return StyleUndef;
insilmaril@0
   212
}
insilmaril@0
   213
insilmaril@0
   214
void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
insilmaril@0
   215
{
insilmaril@83
   216
	//if (newstyle=style) return;
insilmaril@0
   217
	delLink();
insilmaril@0
   218
		
insilmaril@0
   219
	style=newstyle;
insilmaril@0
   220
insilmaril@0
   221
    if (childObj!=NULL && parObj != NULL)
insilmaril@0
   222
    {
insilmaril@408
   223
		QGraphicsLineItem *cl;
insilmaril@0
   224
		switch (style)
insilmaril@0
   225
		{
insilmaril@0
   226
			case StyleUndef:
insilmaril@0
   227
				bottomline->hide();
insilmaril@0
   228
				break;
insilmaril@0
   229
			case StyleLine: 
insilmaril@408
   230
				l = scene->addLine(QLineF(1,1,1,1),pen);
insilmaril@408
   231
				l->setZValue(Z_LINK);
insilmaril@0
   232
				if (visible)
insilmaril@0
   233
					l->show();
insilmaril@0
   234
				else
insilmaril@0
   235
					l->hide();
insilmaril@0
   236
				break;
insilmaril@0
   237
			case StyleParabel:
insilmaril@408
   238
				for (int i=0;i<arcsegs;i++)
insilmaril@0
   239
				{
insilmaril@408
   240
					cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
insilmaril@408
   241
					cl->setZValue(Z_LINK);
insilmaril@0
   242
					if (visible)
insilmaril@0
   243
						cl->show();
insilmaril@0
   244
					else
insilmaril@0
   245
						cl->hide();
insilmaril@0
   246
					segment.append(cl);
insilmaril@0
   247
				}
insilmaril@0
   248
				pa0.resize (arcsegs+1);
insilmaril@0
   249
				break;
insilmaril@0
   250
			case StylePolyLine:	
insilmaril@408
   251
				p =scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   252
				p->setZValue(Z_LINK);
insilmaril@0
   253
				if (visible)
insilmaril@0
   254
					p->show();
insilmaril@0
   255
				else
insilmaril@0
   256
					p->hide();
insilmaril@0
   257
				pa0.resize (3);
insilmaril@0
   258
				break;
insilmaril@0
   259
			case StylePolyParabel:	
insilmaril@408
   260
				p = scene->addPolygon(QPolygonF(),pen,linkcolor);
insilmaril@408
   261
				p->setZValue(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 (arcsegs*2+2);
insilmaril@0
   267
				pa1.resize (arcsegs+1);
insilmaril@0
   268
				pa2.resize (arcsegs+1);
insilmaril@0
   269
				break;
insilmaril@0
   270
			default: 
insilmaril@0
   271
				break;	
insilmaril@0
   272
		}	
insilmaril@164
   273
	} 
insilmaril@0
   274
}
insilmaril@0
   275
insilmaril@0
   276
LinkStyle LinkableMapObj::getLinkStyle()
insilmaril@0
   277
{
insilmaril@0
   278
	return style;
insilmaril@0
   279
}
insilmaril@0
   280
insilmaril@160
   281
void LinkableMapObj::setHideLinkUnselected(bool b)
insilmaril@160
   282
{
insilmaril@160
   283
	hideLinkUnselected=b;
insilmaril@160
   284
	setVisibility (visible);
insilmaril@160
   285
	updateLink();
insilmaril@160
   286
}
insilmaril@160
   287
insilmaril@160
   288
bool LinkableMapObj::getHideLinkUnselected()
insilmaril@160
   289
{
insilmaril@160
   290
	return hideLinkUnselected;
insilmaril@160
   291
}
insilmaril@160
   292
insilmaril@0
   293
void LinkableMapObj::setLinkPos(LinkPos lp)
insilmaril@0
   294
{
insilmaril@0
   295
	linkpos=lp;
insilmaril@0
   296
}
insilmaril@0
   297
insilmaril@0
   298
LinkPos LinkableMapObj::getLinkPos()
insilmaril@0
   299
{
insilmaril@0
   300
	return linkpos;
insilmaril@0
   301
}
insilmaril@0
   302
insilmaril@0
   303
insilmaril@0
   304
void LinkableMapObj::setLinkColor()
insilmaril@0
   305
{
insilmaril@0
   306
	// Overloaded in BranchObj and childs
insilmaril@0
   307
	// here only set default color
insilmaril@164
   308
	if (mapEditor)
insilmaril@398
   309
		setLinkColor (mapEditor->getMapDefLinkColor());
insilmaril@0
   310
}
insilmaril@0
   311
insilmaril@0
   312
void LinkableMapObj::setLinkColor(QColor col)
insilmaril@0
   313
{
insilmaril@0
   314
	linkcolor=col;
insilmaril@408
   315
	pen.setColor(col);
insilmaril@408
   316
    bottomline->setPen( pen );
insilmaril@0
   317
	switch (style)
insilmaril@0
   318
	{
insilmaril@0
   319
		case StyleLine:
insilmaril@408
   320
			l->setPen( pen);
insilmaril@0
   321
			break;	
insilmaril@0
   322
		case StyleParabel:	
insilmaril@406
   323
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   324
				segment.at(i)->setPen( pen);
insilmaril@0
   325
			break;
insilmaril@0
   326
		case StylePolyLine:
insilmaril@0
   327
			p->setBrush( QBrush(col));
insilmaril@0
   328
			break;
insilmaril@0
   329
		case StylePolyParabel:	
insilmaril@0
   330
			p->setBrush( QBrush(col));
insilmaril@0
   331
			break;
insilmaril@0
   332
		default:
insilmaril@0
   333
			break;
insilmaril@0
   334
	} // switch (style)	
insilmaril@0
   335
}
insilmaril@0
   336
insilmaril@0
   337
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   338
{
insilmaril@0
   339
	return linkcolor;
insilmaril@0
   340
}
insilmaril@0
   341
insilmaril@0
   342
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   343
{
insilmaril@0
   344
	MapObj::setVisibility (v);
insilmaril@160
   345
	bool visnow=visible;
insilmaril@260
   346
insilmaril@260
   347
	// We can hide the link, while object is not selected
insilmaril@160
   348
	if (hideLinkUnselected && !selected)
insilmaril@160
   349
		visnow=false;
insilmaril@160
   350
insilmaril@160
   351
	if (visnow) 
insilmaril@0
   352
	{
insilmaril@0
   353
		bottomline->show();
insilmaril@160
   354
		switch (style)
insilmaril@0
   355
		{
insilmaril@160
   356
			case StyleLine:
insilmaril@160
   357
				if (l) l->show();
insilmaril@160
   358
				break;
insilmaril@160
   359
			case StyleParabel:	
insilmaril@406
   360
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   361
					segment.at(i)->show();
insilmaril@160
   362
				break;	
insilmaril@160
   363
			case StylePolyLine:
insilmaril@160
   364
				if (p) p->show();
insilmaril@160
   365
				break;
insilmaril@160
   366
			case StylePolyParabel:	
insilmaril@160
   367
				if (p) p->show();
insilmaril@160
   368
				break;
insilmaril@160
   369
			default:
insilmaril@160
   370
				break;
insilmaril@160
   371
		}
insilmaril@0
   372
	} else 
insilmaril@0
   373
	{
insilmaril@0
   374
		bottomline->hide();
insilmaril@160
   375
		switch (style)
insilmaril@0
   376
		{
insilmaril@160
   377
			case StyleLine:
insilmaril@160
   378
				if (l) l->hide();
insilmaril@160
   379
				break;
insilmaril@160
   380
			case StyleParabel:	
insilmaril@406
   381
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   382
					segment.at(i)->hide();
insilmaril@160
   383
				break;	
insilmaril@160
   384
			case StylePolyLine:
insilmaril@160
   385
				if (p) p->hide();
insilmaril@160
   386
				break;
insilmaril@160
   387
			case StylePolyParabel:	
insilmaril@160
   388
				if (p) p->hide();
insilmaril@160
   389
				break;
insilmaril@160
   390
			default:
insilmaril@160
   391
				break;
insilmaril@160
   392
		}
insilmaril@0
   393
	}	
insilmaril@0
   394
}
insilmaril@0
   395
insilmaril@388
   396
void LinkableMapObj::setOrientation()
insilmaril@388
   397
{
insilmaril@388
   398
	LinkOrient orientOld=orientation;
insilmaril@388
   399
insilmaril@388
   400
	if (!parObj) 
insilmaril@388
   401
	{
insilmaril@388
   402
		orientation=OrientUndef;
insilmaril@388
   403
		return;
insilmaril@388
   404
	}
insilmaril@388
   405
		
insilmaril@388
   406
    // Set orientation, first look for orientation of parent
insilmaril@388
   407
    if (parObj->getOrientation() != OrientUndef ) 
insilmaril@388
   408
		// use the orientation of the parent:
insilmaril@388
   409
		orientation=parObj->getOrientation();
insilmaril@388
   410
    else
insilmaril@388
   411
    {
insilmaril@388
   412
		// calc orientation depending on position rel to parent
insilmaril@408
   413
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@388
   414
			orientation=OrientLeftOfCenter; 
insilmaril@388
   415
		else
insilmaril@388
   416
			orientation=OrientRightOfCenter;
insilmaril@388
   417
    }
insilmaril@388
   418
	if (orientOld!=orientation) requestReposition();
insilmaril@388
   419
}
insilmaril@388
   420
insilmaril@0
   421
void LinkableMapObj::updateLink()
insilmaril@0
   422
{
insilmaril@0
   423
    // needs:
insilmaril@0
   424
    //	childPos of parent
insilmaril@0
   425
    //	orient   of parent
insilmaril@0
   426
    //	style
insilmaril@0
   427
    // 
insilmaril@0
   428
    // sets:
insilmaril@0
   429
    //	orientation
insilmaril@225
   430
    //	childPos	(by calling setDockPos())
insilmaril@225
   431
    //	parPos		(by calling setDockPos())
insilmaril@175
   432
	//  bottomlineY
insilmaril@0
   433
    //	drawing of the link itself
insilmaril@0
   434
insilmaril@0
   435
	// updateLink is called from move, but called from constructor we don't
insilmaril@0
   436
	// have parents yet...
insilmaril@0
   437
	if (style==StyleUndef) return;	
insilmaril@0
   438
insilmaril@0
   439
	switch (linkpos)
insilmaril@0
   440
	{
insilmaril@0
   441
		case LinkMiddle:
insilmaril@442
   442
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   443
			break;
insilmaril@442
   444
		case LinkBottom:
insilmaril@225
   445
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   446
			break;
insilmaril@0
   447
	}
insilmaril@0
   448
	
insilmaril@0
   449
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   450
	if (!link2ParPos)
insilmaril@0
   451
	{
insilmaril@408
   452
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   453
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   454
	} else	
insilmaril@0
   455
	{
insilmaril@408
   456
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   457
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   458
	} 
insilmaril@0
   459
insilmaril@388
   460
	setDockPos(); // Call overloaded method
insilmaril@393
   461
	setOrientation();
insilmaril@0
   462
insilmaril@0
   463
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   464
	double p1y=parPos.y();
insilmaril@0
   465
insilmaril@0
   466
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   467
	double vy=p2y - p1y;
insilmaril@0
   468
insilmaril@0
   469
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@427
   470
	//bottomline->prepareGeometryChange();
insilmaril@408
   471
	bottomline->setLine (QLine (qRound(childPos.x()),
insilmaril@104
   472
		qRound(childPos.y()),
insilmaril@104
   473
		qRound(p1x),
insilmaril@408
   474
		qRound(p1y) ));
insilmaril@0
   475
insilmaril@0
   476
	double a;	// angle
insilmaril@0
   477
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   478
		a=M_PI_2;
insilmaril@0
   479
	else
insilmaril@0
   480
		a=atan( vy / vx );
insilmaril@0
   481
	// "turning point" for drawing polygonal links
insilmaril@408
   482
	QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   483
	
insilmaril@0
   484
    // Draw the link
insilmaril@0
   485
	switch (style)
insilmaril@0
   486
	{
insilmaril@0
   487
		case StyleLine:
insilmaril@427
   488
			//l->prepareGeometryChange();
insilmaril@408
   489
			l->setLine( QLine(qRound (parPos.x()),
insilmaril@104
   490
				qRound(parPos.y()),
insilmaril@104
   491
				qRound(p2x),
insilmaril@408
   492
				qRound(p2y) ));
insilmaril@0
   493
			break;	
insilmaril@0
   494
		case StyleParabel:	
insilmaril@0
   495
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@406
   496
			for (int i=0; i<segment.size(); ++i)
insilmaril@427
   497
			{
insilmaril@427
   498
				//segment.at(i)->prepareGeometryChange();
insilmaril@408
   499
				segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
insilmaril@427
   500
			}	
insilmaril@0
   501
			break;
insilmaril@0
   502
		case StylePolyLine:
insilmaril@408
   503
			pa0.clear();
insilmaril@408
   504
			pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@408
   505
			pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@408
   506
			pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@427
   507
			//p->prepareGeometryChange();
insilmaril@408
   508
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   509
			break;
insilmaril@0
   510
		case StylePolyParabel:	
insilmaril@0
   511
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   512
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@408
   513
			pa0.clear();
insilmaril@406
   514
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   515
				pa0 << QPointF (pa1.at(i));
insilmaril@408
   516
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   517
				pa0 << QPointF (pa2.at(arcsegs-i));
insilmaril@427
   518
			//p->prepareGeometryChange();
insilmaril@408
   519
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   520
			break;
insilmaril@0
   521
		default:
insilmaril@0
   522
			break;
insilmaril@0
   523
	} // switch (style)	
insilmaril@0
   524
}
insilmaril@0
   525
	
insilmaril@0
   526
LinkableMapObj* LinkableMapObj::getChildObj()
insilmaril@0
   527
{
insilmaril@0
   528
    return childObj;
insilmaril@0
   529
}
insilmaril@0
   530
insilmaril@0
   531
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   532
{
insilmaril@0
   533
    return parObj;
insilmaril@0
   534
}
insilmaril@0
   535
insilmaril@106
   536
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
insilmaril@95
   537
{
insilmaril@95
   538
	LinkableMapObj *lmo=this;
insilmaril@95
   539
	QString part;
insilmaril@95
   540
	QString typ;
insilmaril@95
   541
	QString num;
insilmaril@95
   542
	while (!s.isEmpty() )
insilmaril@95
   543
	{
insilmaril@95
   544
		part=s.section(",",0,0);
insilmaril@95
   545
		typ=part.left (3);
insilmaril@95
   546
		num=part.right(part.length() - 3);
insilmaril@95
   547
		if (typ=="mc:")
insilmaril@95
   548
		{
insilmaril@95
   549
			if (depth>0)
insilmaril@95
   550
				return false;	// in a subtree there is no center
insilmaril@95
   551
			else
insilmaril@95
   552
				break;
insilmaril@95
   553
		} else
insilmaril@95
   554
			if (typ=="bo:")
insilmaril@406
   555
				lmo=((BranchObj*)(lmo))->getBranchNum (num.toInt());
insilmaril@95
   556
			else
insilmaril@95
   557
				if (typ=="fi:")
insilmaril@95
   558
					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
insilmaril@95
   559
		if (!lmo) break;
insilmaril@95
   560
		
insilmaril@95
   561
		if (s.contains(","))
insilmaril@95
   562
			s=s.right(s.length() - part.length() -1 );
insilmaril@95
   563
		else	
insilmaril@95
   564
			break;
insilmaril@95
   565
	}
insilmaril@95
   566
	return lmo;
insilmaril@95
   567
}
insilmaril@95
   568
insilmaril@408
   569
QPointF LinkableMapObj::getChildPos()
insilmaril@0
   570
{
insilmaril@0
   571
    return childPos;
insilmaril@0
   572
}
insilmaril@0
   573
insilmaril@408
   574
QPointF LinkableMapObj::getParPos()
insilmaril@0
   575
{
insilmaril@0
   576
    return parPos;
insilmaril@0
   577
}
insilmaril@0
   578
insilmaril@218
   579
void LinkableMapObj::setUseOrientation (const bool &b)
insilmaril@218
   580
{	
insilmaril@218
   581
	if (useOrientation!=b)
insilmaril@218
   582
	{
insilmaril@218
   583
		useOrientation=b;
insilmaril@218
   584
		requestReposition();
insilmaril@218
   585
	}	
insilmaril@218
   586
}
insilmaril@218
   587
insilmaril@0
   588
LinkOrient LinkableMapObj::getOrientation()
insilmaril@0
   589
{
insilmaril@0
   590
    return orientation;
insilmaril@0
   591
}
insilmaril@0
   592
insilmaril@0
   593
int LinkableMapObj::getDepth()
insilmaril@0
   594
{
insilmaril@0
   595
    return depth;
insilmaril@0
   596
}
insilmaril@0
   597
insilmaril@0
   598
void LinkableMapObj::setMapEditor (MapEditor *me)
insilmaril@0
   599
{
insilmaril@0
   600
	mapEditor=me;
insilmaril@0
   601
}
insilmaril@0
   602
insilmaril@0
   603
MapEditor* LinkableMapObj::getMapEditor ()
insilmaril@0
   604
{
insilmaril@0
   605
	return mapEditor;
insilmaril@0
   606
}
insilmaril@0
   607
insilmaril@408
   608
QPointF LinkableMapObj::getRandPos()
insilmaril@0
   609
{
insilmaril@0
   610
	// Choose a random position with given distance to parent:
insilmaril@0
   611
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@408
   612
    return QPointF ( (int)( + 150*cos (a)),
insilmaril@0
   613
                    (int)( + 150*sin (a)));
insilmaril@0
   614
}
insilmaril@0
   615
insilmaril@0
   616
void LinkableMapObj::reposition()
insilmaril@0
   617
{
insilmaril@0
   618
}
insilmaril@0
   619
insilmaril@0
   620
void LinkableMapObj::requestReposition()
insilmaril@0
   621
{
insilmaril@0
   622
	if (!repositionRequest)
insilmaril@0
   623
	{
insilmaril@0
   624
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   625
		// been done yet
insilmaril@0
   626
		repositionRequest=true;
insilmaril@0
   627
		if (parObj) parObj->requestReposition();
insilmaril@0
   628
	}
insilmaril@0
   629
}
insilmaril@0
   630
insilmaril@0
   631
void LinkableMapObj::forceReposition()
insilmaril@0
   632
{
insilmaril@0
   633
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   634
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   635
	// which could collect requests for a reposition.
insilmaril@0
   636
	// Then we have to call forceReposition()
insilmaril@0
   637
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   638
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   639
	// the end, thus check first:
insilmaril@0
   640
insilmaril@139
   641
	if (mapEditor->isRepositionBlocked()) return;
insilmaril@0
   642
	
insilmaril@0
   643
	// Pass on the request to parental objects, if this hasn't been done yet
insilmaril@0
   644
	
insilmaril@0
   645
	if (parObj) 
insilmaril@0
   646
		parObj->forceReposition(); 
insilmaril@0
   647
	else 
insilmaril@83
   648
		reposition(); 
insilmaril@83
   649
}
insilmaril@0
   650
insilmaril@0
   651
bool LinkableMapObj::repositionRequested()
insilmaril@0
   652
{
insilmaril@0
   653
	return repositionRequest;
insilmaril@0
   654
}
insilmaril@0
   655
insilmaril@0
   656
insilmaril@0
   657
void LinkableMapObj::select()
insilmaril@0
   658
{
insilmaril@0
   659
    selected=true;
insilmaril@261
   660
	setVisibility (visible);
insilmaril@0
   661
}
insilmaril@0
   662
insilmaril@0
   663
insilmaril@0
   664
void LinkableMapObj::unselect()
insilmaril@0
   665
{
insilmaril@0
   666
    selected=false;
insilmaril@261
   667
	// Maybe we have to hide the link:
insilmaril@261
   668
	setVisibility (visible);
insilmaril@0
   669
}
insilmaril@0
   670
insilmaril@408
   671
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   672
insilmaril@0
   673
{
insilmaril@0
   674
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   675
	double vy=p2y - p1y;
insilmaril@0
   676
insilmaril@0
   677
	double dx;				// delta x during calculation of parabel
insilmaril@0
   678
	
insilmaril@0
   679
	double pnx;				// next point
insilmaril@0
   680
	double pny;
insilmaril@0
   681
	double m;
insilmaril@0
   682
insilmaril@0
   683
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   684
		m=0;
insilmaril@0
   685
	else	
insilmaril@0
   686
		m=(vy / (vx*vx));
insilmaril@0
   687
	dx=vx/(arcsegs);
insilmaril@408
   688
	ya.clear();
insilmaril@408
   689
	ya<<QPointF (qRound(p1x),qRound(p1y));
insilmaril@408
   690
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   691
	{	
insilmaril@0
   692
		pnx=p1x+dx;
insilmaril@0
   693
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@408
   694
		ya<<QPointF (qRound(pnx),qRound(pny));
insilmaril@0
   695
		p1x=pnx;
insilmaril@0
   696
		p1y=pny;
insilmaril@0
   697
	}	
insilmaril@0
   698
}
insilmaril@0
   699
insilmaril@160
   700
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   701
{
insilmaril@160
   702
	if (hideLinkUnselected)
insilmaril@175
   703
		return attribut ("hideLink","true");
insilmaril@160
   704
	else
insilmaril@175
   705
		return attribut ("hideLink","false");
insilmaril@160
   706
	
insilmaril@160
   707
}