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