linkablemapobj.cpp
author insilmaril
Wed May 02 15:31:18 2007 +0000 (2007-05-02)
changeset 485 aff86e2f2a4a
parent 442 dfbc371b7280
child 494 eea7fa702968
permissions -rw-r--r--
Mainly documentation fixes
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@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@473
   184
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle ()
insilmaril@0
   185
{
insilmaril@473
   186
	if (mapEditor==0) return UndefinedStyle;
insilmaril@473
   187
	Style ls=mapEditor->getMapLinkStyle();
insilmaril@0
   188
	switch (ls)
insilmaril@0
   189
	{
insilmaril@473
   190
		case Line: 
insilmaril@0
   191
			return ls;
insilmaril@0
   192
			break;
insilmaril@473
   193
		case Parabel:
insilmaril@0
   194
			return ls;
insilmaril@0
   195
			break;
insilmaril@473
   196
		case PolyLine:	
insilmaril@0
   197
			if (depth>1)
insilmaril@473
   198
				return Line;
insilmaril@0
   199
			else	
insilmaril@0
   200
				return ls;
insilmaril@0
   201
			break;
insilmaril@473
   202
		case PolyParabel:	
insilmaril@0
   203
			if (depth>1)
insilmaril@473
   204
				return Parabel;
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@473
   211
	return UndefinedStyle;
insilmaril@0
   212
}
insilmaril@0
   213
insilmaril@473
   214
void LinkableMapObj::setLinkStyle(Style 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@473
   226
			case UndefinedStyle:
insilmaril@0
   227
				bottomline->hide();
insilmaril@0
   228
				break;
insilmaril@473
   229
			case Line: 
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@473
   237
			case Parabel:
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@473
   250
			case PolyLine:	
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@473
   259
			case PolyParabel:	
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@473
   276
LinkableMapObj::Style 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@473
   293
void LinkableMapObj::setLinkPos(Position lp)
insilmaril@0
   294
{
insilmaril@0
   295
	linkpos=lp;
insilmaril@0
   296
}
insilmaril@0
   297
insilmaril@473
   298
LinkableMapObj::Position 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@473
   319
		case Line:
insilmaril@408
   320
			l->setPen( pen);
insilmaril@0
   321
			break;	
insilmaril@473
   322
		case Parabel:	
insilmaril@406
   323
			for (int i=0; i<segment.size(); ++i)
insilmaril@408
   324
				segment.at(i)->setPen( pen);
insilmaril@0
   325
			break;
insilmaril@473
   326
		case PolyLine:
insilmaril@0
   327
			p->setBrush( QBrush(col));
insilmaril@0
   328
			break;
insilmaril@473
   329
		case PolyParabel:	
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@473
   356
			case Line:
insilmaril@160
   357
				if (l) l->show();
insilmaril@160
   358
				break;
insilmaril@473
   359
			case Parabel:	
insilmaril@406
   360
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   361
					segment.at(i)->show();
insilmaril@160
   362
				break;	
insilmaril@473
   363
			case PolyLine:
insilmaril@160
   364
				if (p) p->show();
insilmaril@160
   365
				break;
insilmaril@473
   366
			case PolyParabel:	
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@473
   377
			case Line:
insilmaril@160
   378
				if (l) l->hide();
insilmaril@160
   379
				break;
insilmaril@473
   380
			case Parabel:	
insilmaril@406
   381
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   382
					segment.at(i)->hide();
insilmaril@160
   383
				break;	
insilmaril@473
   384
			case PolyLine:
insilmaril@160
   385
				if (p) p->hide();
insilmaril@160
   386
				break;
insilmaril@473
   387
			case PolyParabel:	
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@473
   398
	Orientation orientOld=orientation;
insilmaril@388
   399
insilmaril@388
   400
	if (!parObj) 
insilmaril@388
   401
	{
insilmaril@473
   402
		orientation=UndefinedOrientation;
insilmaril@388
   403
		return;
insilmaril@388
   404
	}
insilmaril@388
   405
		
insilmaril@388
   406
    // Set orientation, first look for orientation of parent
insilmaril@473
   407
    if (parObj->getOrientation() != UndefinedOrientation ) 
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@473
   414
			orientation=LeftOfCenter; 
insilmaril@388
   415
		else
insilmaril@473
   416
			orientation=RightOfCenter;
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@473
   437
	if (style==UndefinedStyle) return;	
insilmaril@0
   438
insilmaril@0
   439
	switch (linkpos)
insilmaril@0
   440
	{
insilmaril@473
   441
		case Middle:
insilmaril@442
   442
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   443
			break;
insilmaril@473
   444
		case Bottom:
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@473
   487
		case Line:
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@473
   494
		case Parabel:	
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@473
   502
		case PolyLine:
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@473
   510
		case PolyParabel:	
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@473
   588
LinkableMapObj::Orientation 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@473
   659
	// select and unselect are still needed to
insilmaril@473
   660
	// handle hiding of links
insilmaril@0
   661
    selected=true;
insilmaril@261
   662
	setVisibility (visible);
insilmaril@0
   663
}
insilmaril@0
   664
insilmaril@0
   665
insilmaril@0
   666
void LinkableMapObj::unselect()
insilmaril@0
   667
{
insilmaril@0
   668
    selected=false;
insilmaril@261
   669
	// Maybe we have to hide the link:
insilmaril@261
   670
	setVisibility (visible);
insilmaril@0
   671
}
insilmaril@0
   672
insilmaril@408
   673
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   674
insilmaril@0
   675
{
insilmaril@0
   676
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   677
	double vy=p2y - p1y;
insilmaril@0
   678
insilmaril@0
   679
	double dx;				// delta x during calculation of parabel
insilmaril@0
   680
	
insilmaril@0
   681
	double pnx;				// next point
insilmaril@0
   682
	double pny;
insilmaril@0
   683
	double m;
insilmaril@0
   684
insilmaril@0
   685
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   686
		m=0;
insilmaril@0
   687
	else	
insilmaril@0
   688
		m=(vy / (vx*vx));
insilmaril@0
   689
	dx=vx/(arcsegs);
insilmaril@408
   690
	ya.clear();
insilmaril@408
   691
	ya<<QPointF (qRound(p1x),qRound(p1y));
insilmaril@408
   692
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   693
	{	
insilmaril@0
   694
		pnx=p1x+dx;
insilmaril@0
   695
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@408
   696
		ya<<QPointF (qRound(pnx),qRound(pny));
insilmaril@0
   697
		p1x=pnx;
insilmaril@0
   698
		p1y=pny;
insilmaril@0
   699
	}	
insilmaril@0
   700
}
insilmaril@0
   701
insilmaril@160
   702
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   703
{
insilmaril@160
   704
	if (hideLinkUnselected)
insilmaril@175
   705
		return attribut ("hideLink","true");
insilmaril@160
   706
	else
insilmaril@175
   707
		return attribut ("hideLink","false");
insilmaril@160
   708
	
insilmaril@160
   709
}
insilmaril@473
   710