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