linkablemapobj.cpp
author insilmaril
Mon, 21 May 2007 13:05:26 +0000
changeset 496 1fc21685e3ea
parent 494 eea7fa702968
child 497 ab118b86bc54
permissions -rw-r--r--
Copy to new map, fixed pasting of images
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@0
   322
			break;
insilmaril@473
   323
		case PolyParabel:	
insilmaril@0
   324
			p->setBrush( QBrush(col));
insilmaril@0
   325
			break;
insilmaril@0
   326
		default:
insilmaril@0
   327
			break;
insilmaril@0
   328
	} // switch (style)	
insilmaril@0
   329
}
insilmaril@0
   330
insilmaril@0
   331
QColor LinkableMapObj::getLinkColor()
insilmaril@0
   332
{
insilmaril@0
   333
	return linkcolor;
insilmaril@0
   334
}
insilmaril@0
   335
insilmaril@0
   336
void LinkableMapObj::setVisibility (bool v)
insilmaril@0
   337
{
insilmaril@0
   338
	MapObj::setVisibility (v);
insilmaril@160
   339
	bool visnow=visible;
insilmaril@260
   340
insilmaril@260
   341
	// We can hide the link, while object is not selected
insilmaril@160
   342
	if (hideLinkUnselected && !selected)
insilmaril@160
   343
		visnow=false;
insilmaril@160
   344
insilmaril@160
   345
	if (visnow) 
insilmaril@0
   346
	{
insilmaril@0
   347
		bottomline->show();
insilmaril@160
   348
		switch (style)
insilmaril@0
   349
		{
insilmaril@473
   350
			case Line:
insilmaril@160
   351
				if (l) l->show();
insilmaril@160
   352
				break;
insilmaril@473
   353
			case Parabel:	
insilmaril@406
   354
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   355
					segment.at(i)->show();
insilmaril@160
   356
				break;	
insilmaril@473
   357
			case PolyLine:
insilmaril@160
   358
				if (p) p->show();
insilmaril@160
   359
				break;
insilmaril@473
   360
			case PolyParabel:	
insilmaril@160
   361
				if (p) p->show();
insilmaril@160
   362
				break;
insilmaril@160
   363
			default:
insilmaril@160
   364
				break;
insilmaril@160
   365
		}
insilmaril@0
   366
	} else 
insilmaril@0
   367
	{
insilmaril@0
   368
		bottomline->hide();
insilmaril@160
   369
		switch (style)
insilmaril@0
   370
		{
insilmaril@473
   371
			case Line:
insilmaril@160
   372
				if (l) l->hide();
insilmaril@160
   373
				break;
insilmaril@473
   374
			case Parabel:	
insilmaril@406
   375
				for (int i=0; i<segment.size(); ++i)
insilmaril@406
   376
					segment.at(i)->hide();
insilmaril@160
   377
				break;	
insilmaril@473
   378
			case PolyLine:
insilmaril@160
   379
				if (p) p->hide();
insilmaril@160
   380
				break;
insilmaril@473
   381
			case PolyParabel:	
insilmaril@160
   382
				if (p) p->hide();
insilmaril@160
   383
				break;
insilmaril@160
   384
			default:
insilmaril@160
   385
				break;
insilmaril@160
   386
		}
insilmaril@0
   387
	}	
insilmaril@0
   388
}
insilmaril@0
   389
insilmaril@388
   390
void LinkableMapObj::setOrientation()
insilmaril@388
   391
{
insilmaril@473
   392
	Orientation orientOld=orientation;
insilmaril@388
   393
insilmaril@388
   394
	if (!parObj) 
insilmaril@388
   395
	{
insilmaril@473
   396
		orientation=UndefinedOrientation;
insilmaril@388
   397
		return;
insilmaril@388
   398
	}
insilmaril@388
   399
		
insilmaril@388
   400
    // Set orientation, first look for orientation of parent
insilmaril@473
   401
    if (parObj->getOrientation() != UndefinedOrientation ) 
insilmaril@388
   402
		// use the orientation of the parent:
insilmaril@388
   403
		orientation=parObj->getOrientation();
insilmaril@388
   404
    else
insilmaril@388
   405
    {
insilmaril@388
   406
		// calc orientation depending on position rel to parent
insilmaril@408
   407
		if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
insilmaril@473
   408
			orientation=LeftOfCenter; 
insilmaril@388
   409
		else
insilmaril@473
   410
			orientation=RightOfCenter;
insilmaril@388
   411
    }
insilmaril@388
   412
	if (orientOld!=orientation) requestReposition();
insilmaril@388
   413
}
insilmaril@388
   414
insilmaril@0
   415
void LinkableMapObj::updateLink()
insilmaril@0
   416
{
insilmaril@0
   417
    // needs:
insilmaril@0
   418
    //	childPos of parent
insilmaril@0
   419
    //	orient   of parent
insilmaril@0
   420
    //	style
insilmaril@0
   421
    // 
insilmaril@0
   422
    // sets:
insilmaril@0
   423
    //	orientation
insilmaril@225
   424
    //	childPos	(by calling setDockPos())
insilmaril@225
   425
    //	parPos		(by calling setDockPos())
insilmaril@175
   426
	//  bottomlineY
insilmaril@0
   427
    //	drawing of the link itself
insilmaril@0
   428
insilmaril@0
   429
	// updateLink is called from move, but called from constructor we don't
insilmaril@0
   430
	// have parents yet...
insilmaril@473
   431
	if (style==UndefinedStyle) return;	
insilmaril@0
   432
insilmaril@0
   433
	switch (linkpos)
insilmaril@0
   434
	{
insilmaril@473
   435
		case Middle:
insilmaril@442
   436
			bottomlineY=bbox.top() + bbox.height()/2;	// draw link to middle (of frame)
insilmaril@0
   437
			break;
insilmaril@473
   438
		case Bottom:
insilmaril@225
   439
			bottomlineY=bbox.bottom()-1;	// draw link to bottom of box
insilmaril@0
   440
			break;
insilmaril@0
   441
	}
insilmaril@0
   442
	
insilmaril@0
   443
    double p2x,p2y;								// Set P2 Before setting
insilmaril@0
   444
	if (!link2ParPos)
insilmaril@0
   445
	{
insilmaril@408
   446
		p2x=QPointF( parObj->getChildPos() ).x();	// P1, we have to look at
insilmaril@408
   447
		p2y=QPointF( parObj->getChildPos() ).y();	// orientation
insilmaril@0
   448
	} else	
insilmaril@0
   449
	{
insilmaril@408
   450
		p2x=QPointF( parObj->getParPos() ).x();	
insilmaril@408
   451
		p2y=QPointF( parObj->getParPos() ).y();
insilmaril@0
   452
	} 
insilmaril@0
   453
insilmaril@388
   454
	setDockPos(); // Call overloaded method
insilmaril@393
   455
	setOrientation();
insilmaril@0
   456
insilmaril@0
   457
	double p1x=parPos.x();	// Link is drawn from P1 to P2
insilmaril@0
   458
	double p1y=parPos.y();
insilmaril@0
   459
insilmaril@0
   460
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   461
	double vy=p2y - p1y;
insilmaril@0
   462
insilmaril@0
   463
	// Draw the horizontal line below heading (from ChildPos to ParPos)
insilmaril@427
   464
	//bottomline->prepareGeometryChange();
insilmaril@408
   465
	bottomline->setLine (QLine (qRound(childPos.x()),
insilmaril@104
   466
		qRound(childPos.y()),
insilmaril@104
   467
		qRound(p1x),
insilmaril@408
   468
		qRound(p1y) ));
insilmaril@0
   469
insilmaril@0
   470
	double a;	// angle
insilmaril@0
   471
	if (vx > -0.000001 && vx < 0.000001)
insilmaril@0
   472
		a=M_PI_2;
insilmaril@0
   473
	else
insilmaril@0
   474
		a=atan( vy / vx );
insilmaril@0
   475
	// "turning point" for drawing polygonal links
insilmaril@408
   476
	QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));	
insilmaril@0
   477
	
insilmaril@0
   478
    // Draw the link
insilmaril@0
   479
	switch (style)
insilmaril@0
   480
	{
insilmaril@473
   481
		case Line:
insilmaril@427
   482
			//l->prepareGeometryChange();
insilmaril@408
   483
			l->setLine( QLine(qRound (parPos.x()),
insilmaril@104
   484
				qRound(parPos.y()),
insilmaril@104
   485
				qRound(p2x),
insilmaril@408
   486
				qRound(p2y) ));
insilmaril@0
   487
			break;	
insilmaril@473
   488
		case Parabel:	
insilmaril@0
   489
			parabel (pa0, p1x,p1y,p2x,p2y);
insilmaril@406
   490
			for (int i=0; i<segment.size(); ++i)
insilmaril@427
   491
			{
insilmaril@427
   492
				//segment.at(i)->prepareGeometryChange();
insilmaril@408
   493
				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
   494
			}	
insilmaril@0
   495
			break;
insilmaril@473
   496
		case PolyLine:
insilmaril@408
   497
			pa0.clear();
insilmaril@408
   498
			pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
insilmaril@408
   499
			pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
insilmaril@408
   500
			pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
insilmaril@427
   501
			//p->prepareGeometryChange();
insilmaril@408
   502
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   503
			break;
insilmaril@473
   504
		case PolyParabel:	
insilmaril@0
   505
			parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
insilmaril@0
   506
			parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
insilmaril@408
   507
			pa0.clear();
insilmaril@406
   508
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   509
				pa0 << QPointF (pa1.at(i));
insilmaril@408
   510
			for (int i=0;i<=arcsegs;i++)
insilmaril@408
   511
				pa0 << QPointF (pa2.at(arcsegs-i));
insilmaril@427
   512
			//p->prepareGeometryChange();
insilmaril@408
   513
			p->setPolygon(QPolygonF (pa0));
insilmaril@0
   514
			break;
insilmaril@0
   515
		default:
insilmaril@0
   516
			break;
insilmaril@0
   517
	} // switch (style)	
insilmaril@0
   518
}
insilmaril@0
   519
	
insilmaril@0
   520
LinkableMapObj* LinkableMapObj::getChildObj()
insilmaril@0
   521
{
insilmaril@0
   522
    return childObj;
insilmaril@0
   523
}
insilmaril@0
   524
insilmaril@0
   525
LinkableMapObj* LinkableMapObj::getParObj()
insilmaril@0
   526
{
insilmaril@0
   527
    return parObj;
insilmaril@0
   528
}
insilmaril@0
   529
insilmaril@106
   530
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
insilmaril@95
   531
{
insilmaril@95
   532
	LinkableMapObj *lmo=this;
insilmaril@95
   533
	QString part;
insilmaril@95
   534
	QString typ;
insilmaril@95
   535
	QString num;
insilmaril@95
   536
	while (!s.isEmpty() )
insilmaril@95
   537
	{
insilmaril@95
   538
		part=s.section(",",0,0);
insilmaril@95
   539
		typ=part.left (3);
insilmaril@95
   540
		num=part.right(part.length() - 3);
insilmaril@95
   541
		if (typ=="mc:")
insilmaril@95
   542
		{
insilmaril@95
   543
			if (depth>0)
insilmaril@95
   544
				return false;	// in a subtree there is no center
insilmaril@95
   545
			else
insilmaril@95
   546
				break;
insilmaril@95
   547
		} else
insilmaril@95
   548
			if (typ=="bo:")
insilmaril@406
   549
				lmo=((BranchObj*)(lmo))->getBranchNum (num.toInt());
insilmaril@95
   550
			else
insilmaril@95
   551
				if (typ=="fi:")
insilmaril@95
   552
					lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
insilmaril@95
   553
		if (!lmo) break;
insilmaril@95
   554
		
insilmaril@95
   555
		if (s.contains(","))
insilmaril@95
   556
			s=s.right(s.length() - part.length() -1 );
insilmaril@95
   557
		else	
insilmaril@95
   558
			break;
insilmaril@95
   559
	}
insilmaril@95
   560
	return lmo;
insilmaril@95
   561
}
insilmaril@95
   562
insilmaril@408
   563
QPointF LinkableMapObj::getChildPos()
insilmaril@0
   564
{
insilmaril@0
   565
    return childPos;
insilmaril@0
   566
}
insilmaril@0
   567
insilmaril@408
   568
QPointF LinkableMapObj::getParPos()
insilmaril@0
   569
{
insilmaril@0
   570
    return parPos;
insilmaril@0
   571
}
insilmaril@0
   572
insilmaril@218
   573
void LinkableMapObj::setUseOrientation (const bool &b)
insilmaril@218
   574
{	
insilmaril@218
   575
	if (useOrientation!=b)
insilmaril@218
   576
	{
insilmaril@218
   577
		useOrientation=b;
insilmaril@218
   578
		requestReposition();
insilmaril@218
   579
	}	
insilmaril@218
   580
}
insilmaril@218
   581
insilmaril@473
   582
LinkableMapObj::Orientation LinkableMapObj::getOrientation()
insilmaril@0
   583
{
insilmaril@0
   584
    return orientation;
insilmaril@0
   585
}
insilmaril@0
   586
insilmaril@0
   587
int LinkableMapObj::getDepth()
insilmaril@0
   588
{
insilmaril@0
   589
    return depth;
insilmaril@0
   590
}
insilmaril@0
   591
insilmaril@0
   592
void LinkableMapObj::setMapEditor (MapEditor *me)
insilmaril@0
   593
{
insilmaril@0
   594
	mapEditor=me;
insilmaril@0
   595
}
insilmaril@0
   596
insilmaril@0
   597
MapEditor* LinkableMapObj::getMapEditor ()
insilmaril@0
   598
{
insilmaril@0
   599
	return mapEditor;
insilmaril@0
   600
}
insilmaril@0
   601
insilmaril@408
   602
QPointF LinkableMapObj::getRandPos()
insilmaril@0
   603
{
insilmaril@0
   604
	// Choose a random position with given distance to parent:
insilmaril@0
   605
	double a=rand()%360 * 2 * M_PI / 360;
insilmaril@408
   606
    return QPointF ( (int)( + 150*cos (a)),
insilmaril@0
   607
                    (int)( + 150*sin (a)));
insilmaril@0
   608
}
insilmaril@0
   609
insilmaril@0
   610
void LinkableMapObj::reposition()
insilmaril@0
   611
{
insilmaril@0
   612
}
insilmaril@0
   613
insilmaril@0
   614
void LinkableMapObj::requestReposition()
insilmaril@0
   615
{
insilmaril@0
   616
	if (!repositionRequest)
insilmaril@0
   617
	{
insilmaril@0
   618
		// Pass on the request to parental objects, if this hasn't
insilmaril@0
   619
		// been done yet
insilmaril@0
   620
		repositionRequest=true;
insilmaril@0
   621
		if (parObj) parObj->requestReposition();
insilmaril@0
   622
	}
insilmaril@0
   623
}
insilmaril@0
   624
insilmaril@0
   625
void LinkableMapObj::forceReposition()
insilmaril@0
   626
{
insilmaril@0
   627
	// Sometimes a reposition has to be done immediatly: For example
insilmaril@0
   628
	// if the note editor flag changes, there is no user event in mapeditor
insilmaril@0
   629
	// which could collect requests for a reposition.
insilmaril@0
   630
	// Then we have to call forceReposition()
insilmaril@0
   631
	// But no rule without exception: While loading a map or undoing it,
insilmaril@0
   632
	// we want to block expensive repositioning, but just do it once at
insilmaril@0
   633
	// the end, thus check first:
insilmaril@0
   634
insilmaril@139
   635
	if (mapEditor->isRepositionBlocked()) return;
insilmaril@0
   636
	
insilmaril@0
   637
	// Pass on the request to parental objects, if this hasn't been done yet
insilmaril@0
   638
	
insilmaril@0
   639
	if (parObj) 
insilmaril@0
   640
		parObj->forceReposition(); 
insilmaril@0
   641
	else 
insilmaril@83
   642
		reposition(); 
insilmaril@83
   643
}
insilmaril@0
   644
insilmaril@0
   645
bool LinkableMapObj::repositionRequested()
insilmaril@0
   646
{
insilmaril@0
   647
	return repositionRequest;
insilmaril@0
   648
}
insilmaril@0
   649
insilmaril@0
   650
insilmaril@0
   651
void LinkableMapObj::select()
insilmaril@0
   652
{
insilmaril@473
   653
	// select and unselect are still needed to
insilmaril@473
   654
	// handle hiding of links
insilmaril@0
   655
    selected=true;
insilmaril@261
   656
	setVisibility (visible);
insilmaril@0
   657
}
insilmaril@0
   658
insilmaril@0
   659
insilmaril@0
   660
void LinkableMapObj::unselect()
insilmaril@0
   661
{
insilmaril@0
   662
    selected=false;
insilmaril@261
   663
	// Maybe we have to hide the link:
insilmaril@261
   664
	setVisibility (visible);
insilmaril@0
   665
}
insilmaril@0
   666
insilmaril@408
   667
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
insilmaril@0
   668
insilmaril@0
   669
{
insilmaril@0
   670
	double vx=p2x - p1x;	// V=P2-P1
insilmaril@0
   671
	double vy=p2y - p1y;
insilmaril@0
   672
insilmaril@0
   673
	double dx;				// delta x during calculation of parabel
insilmaril@0
   674
	
insilmaril@0
   675
	double pnx;				// next point
insilmaril@0
   676
	double pny;
insilmaril@0
   677
	double m;
insilmaril@0
   678
insilmaril@0
   679
	if (vx > -0.0001 && vx < 0.0001)
insilmaril@0
   680
		m=0;
insilmaril@0
   681
	else	
insilmaril@0
   682
		m=(vy / (vx*vx));
insilmaril@0
   683
	dx=vx/(arcsegs);
insilmaril@408
   684
	ya.clear();
insilmaril@408
   685
	ya<<QPointF (qRound(p1x),qRound(p1y));
insilmaril@408
   686
	for (int i=1;i<=arcsegs;i++)
insilmaril@0
   687
	{	
insilmaril@0
   688
		pnx=p1x+dx;
insilmaril@0
   689
		pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
insilmaril@408
   690
		ya<<QPointF (qRound(pnx),qRound(pny));
insilmaril@0
   691
		p1x=pnx;
insilmaril@0
   692
		p1y=pny;
insilmaril@0
   693
	}	
insilmaril@0
   694
}
insilmaril@0
   695
insilmaril@160
   696
QString LinkableMapObj::getLinkAttr ()
insilmaril@160
   697
{
insilmaril@160
   698
	if (hideLinkUnselected)
insilmaril@175
   699
		return attribut ("hideLink","true");
insilmaril@160
   700
	else
insilmaril@175
   701
		return attribut ("hideLink","false");
insilmaril@160
   702
	
insilmaril@160
   703
}
insilmaril@473
   704