1.1 --- a/linkablemapobj.cpp Fri Mar 05 20:16:46 2010 +0000
1.2 +++ b/linkablemapobj.cpp Tue Mar 23 11:54:30 2010 +0000
1.3 @@ -1,12 +1,10 @@
1.4 -//#include <math.h>
1.5 +#include <math.h>
1.6 +#include <cstdlib>
1.7
1.8 #include "linkablemapobj.h"
1.9 #include "branchobj.h"
1.10 #include "mapeditor.h"
1.11
1.12 -#include "version.h"
1.13 -
1.14 -
1.15 /////////////////////////////////////////////////////////////////
1.16 // LinkableMapObj
1.17 /////////////////////////////////////////////////////////////////
1.18 @@ -17,13 +15,13 @@
1.19 init ();
1.20 }
1.21
1.22 -LinkableMapObj::LinkableMapObj(QCanvas* c) :MapObj(c)
1.23 +LinkableMapObj::LinkableMapObj(QGraphicsScene* s) :MapObj(s)
1.24 {
1.25 -// cout << "Const LinkableMapObj\n";
1.26 +// cout << "Const LinkableMapObj (s)\n";
1.27 init ();
1.28 }
1.29
1.30 -LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
1.31 +LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
1.32 {
1.33 copy (lmo);
1.34 }
1.35 @@ -31,8 +29,6 @@
1.36 LinkableMapObj::~LinkableMapObj()
1.37 {
1.38 delete (bottomline);
1.39 - delete (selbox);
1.40 - delete (frame);
1.41 delLink();
1.42 }
1.43
1.44 @@ -40,19 +36,17 @@
1.45 {
1.46 switch (style)
1.47 {
1.48 - case StyleLine:
1.49 + case Line:
1.50 delete (l);
1.51 break;
1.52 - case StyleParabel:
1.53 - segment.clear();
1.54 + case Parabel:
1.55 + while (!segment.isEmpty()) delete segment.takeFirst();
1.56 break;
1.57 - case StylePolyLine:
1.58 + case PolyLine:
1.59 delete (p);
1.60 - delete (l);
1.61 break;
1.62 - case StylePolyParabel:
1.63 + case PolyParabel:
1.64 delete (p);
1.65 - segment.clear();
1.66 break;
1.67 default:
1.68 break;
1.69 @@ -62,49 +56,56 @@
1.70 void LinkableMapObj::init ()
1.71 {
1.72 depth=-1;
1.73 + mapEditor=NULL;
1.74 childObj=NULL;
1.75 parObj=NULL;
1.76 parObjTmpBuf=NULL;
1.77 - parPos=QPoint(0,0);
1.78 - childPos=QPoint(0,0);
1.79 + parPos=QPointF(0,0);
1.80 + childPos=QPointF(0,0);
1.81 link2ParPos=false;
1.82 l=NULL;
1.83 - orientation=OrientUndef;
1.84 + orientation=UndefinedOrientation;
1.85 linkwidth=20;
1.86 thickness_start=8;
1.87 - style=StyleUndef;
1.88 - linkpos=LinkBottom;
1.89 - segment.setAutoDelete (TRUE);
1.90 + style=UndefinedStyle;
1.91 + linkpos=Bottom;
1.92 arcsegs=13;
1.93 - QPointArray pa(arcsegs*2+2);
1.94
1.95 - bottomline=new QCanvasLine(canvas);
1.96 - bottomline->setPen( QPen(linkcolor, 1) );
1.97 - bottomline->setZ(Z_LINK);
1.98 +// TODO instead of linkcolor pen.color() could be used all around
1.99 + pen.setWidth (1);
1.100 + pen.setColor (linkcolor);
1.101 + pen.setCapStyle ( Qt::RoundCap );
1.102 + bottomline=scene->addLine(QLineF(1,1,1,1),pen);
1.103 + bottomline->setZValue(Z_LINK);
1.104 bottomline->show();
1.105
1.106 // Prepare showing the selection of a MapObj
1.107 - selbox = new QCanvasRectangle (canvas);
1.108 - selbox->setZ(Z_SELBOX);
1.109 - selbox->setBrush( QColor(255,255,0) );
1.110 - selbox->setPen( QPen(QColor(255,255,0) ));
1.111 - selbox->hide();
1.112 selected=false;
1.113
1.114 - // initialize frame
1.115 - frame = new FrameObj (canvas);
1.116 -
1.117 + hideLinkUnselected=false;
1.118 +
1.119 + topPad=botPad=leftPad=rightPad=0;
1.120 +
1.121 repositionRequest=false;
1.122 +
1.123 + // Rel Positions
1.124 + relPos=QPointF(0,0);
1.125 + useRelPos=false;
1.126 + useOrientation=true;
1.127 +
1.128 + // Reset ID
1.129 + objID="";
1.130 }
1.131
1.132 void LinkableMapObj::copy (LinkableMapObj* other)
1.133 {
1.134 MapObj::copy(other);
1.135 bboxTotal=other->bboxTotal;
1.136 -// linkwidth=other->linkwidth;
1.137 -
1.138 setLinkStyle(other->style);
1.139 setLinkColor (other->linkcolor);
1.140 + relPos=other->relPos;
1.141 + useOrientation=other->useOrientation;
1.142 + objID=other->objID;
1.143 }
1.144
1.145 void LinkableMapObj::setChildObj(LinkableMapObj* o)
1.146 @@ -118,7 +119,7 @@
1.147 mapEditor=parObj->getMapEditor();
1.148 }
1.149
1.150 -void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
1.151 +void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)
1.152 {
1.153 }
1.154
1.155 @@ -126,66 +127,116 @@
1.156 {
1.157 }
1.158
1.159 -LinkStyle LinkableMapObj::getDefLinkStyle ()
1.160 +bool LinkableMapObj::hasParObjTmp()
1.161 {
1.162 - LinkStyle ls=mapEditor->getLinkStyle();
1.163 + if (parObjTmpBuf) return true;
1.164 + return false;
1.165 +}
1.166 +
1.167 +void LinkableMapObj::setUseRelPos (const bool &b)
1.168 +{
1.169 + useRelPos=b;
1.170 +}
1.171 +
1.172 +void LinkableMapObj::setRelPos()
1.173 +{
1.174 + if (parObj)
1.175 + {
1.176 + relPos.setX (absPos.x() - parObj->getChildPos().x() );
1.177 + relPos.setY (absPos.y() - parObj->getChildPos().y() );
1.178 + parObj->calcBBoxSize();
1.179 + }
1.180 +}
1.181 +
1.182 +void LinkableMapObj::setRelPos(const QPointF &p)
1.183 +{
1.184 + relPos=p;
1.185 + if (parObj)
1.186 + {
1.187 + parObj->calcBBoxSize();
1.188 + requestReposition();
1.189 + }
1.190 +}
1.191 +
1.192 +QPointF LinkableMapObj::getRelPos()
1.193 +{
1.194 + if (!parObj) return QPointF();
1.195 + return relPos;
1.196 +}
1.197 +
1.198 +qreal LinkableMapObj::getTopPad()
1.199 +{
1.200 + return topPad;
1.201 +}
1.202 +
1.203 +qreal LinkableMapObj::getLeftPad()
1.204 +{
1.205 + return leftPad;
1.206 +}
1.207 +
1.208 +qreal LinkableMapObj::getRightPad()
1.209 +{
1.210 + return rightPad;
1.211 +}
1.212 +
1.213 +LinkableMapObj::Style LinkableMapObj::getDefLinkStyle ()
1.214 +{
1.215 + if (!mapEditor) return UndefinedStyle;
1.216 + Style ls=mapEditor->getMapLinkStyle();
1.217 switch (ls)
1.218 {
1.219 - case StyleLine:
1.220 + case Line:
1.221 return ls;
1.222 break;
1.223 - case StyleParabel:
1.224 + case Parabel:
1.225 return ls;
1.226 break;
1.227 - case StylePolyLine:
1.228 + case PolyLine:
1.229 if (depth>1)
1.230 - return StyleLine;
1.231 + return Line;
1.232 else
1.233 return ls;
1.234 break;
1.235 - case StylePolyParabel:
1.236 + case PolyParabel:
1.237 if (depth>1)
1.238 - return StyleParabel;
1.239 + return Parabel;
1.240 else
1.241 return ls;
1.242 break;
1.243 default:
1.244 break;
1.245 }
1.246 - return StyleUndef;
1.247 + return UndefinedStyle;
1.248 }
1.249
1.250 -void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
1.251 +void LinkableMapObj::setLinkStyle(Style newstyle)
1.252 {
1.253 + //if (newstyle=style) return;
1.254 delLink();
1.255
1.256 style=newstyle;
1.257
1.258 if (childObj!=NULL && parObj != NULL)
1.259 {
1.260 - int i;
1.261 - QCanvasLine* cl;
1.262 + QGraphicsLineItem *cl;
1.263 switch (style)
1.264 {
1.265 - case StyleUndef:
1.266 + case UndefinedStyle:
1.267 bottomline->hide();
1.268 break;
1.269 - case StyleLine:
1.270 - l = new QCanvasLine(canvas);
1.271 - l->setPen( QPen(linkcolor, 1) );
1.272 - l->setZ(Z_LINK);
1.273 + case Line:
1.274 + l = scene->addLine(QLineF(1,1,1,1),pen);
1.275 + l->setZValue(Z_LINK);
1.276 if (visible)
1.277 l->show();
1.278 else
1.279 l->hide();
1.280 break;
1.281 - case StyleParabel:
1.282 - for (i=0;i<arcsegs;i++)
1.283 + case Parabel:
1.284 + for (int i=0;i<arcsegs;i++)
1.285 {
1.286 - cl = new QCanvasLine(canvas);
1.287 - cl->setPen( QPen(linkcolor, 1) );
1.288 - cl->setPoints( 0,0,i*10,100);
1.289 - cl->setZ(Z_LINK);
1.290 + cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
1.291 + cl->setZValue(Z_LINK);
1.292 if (visible)
1.293 cl->show();
1.294 else
1.295 @@ -194,30 +245,18 @@
1.296 }
1.297 pa0.resize (arcsegs+1);
1.298 break;
1.299 - case StylePolyLine:
1.300 - p = new QCanvasPolygon(canvas);
1.301 - p->setBrush( linkcolor );
1.302 - p->setZ(Z_LINK);
1.303 + case PolyLine:
1.304 + p =scene->addPolygon(QPolygonF(),pen,linkcolor);
1.305 + p->setZValue(Z_LINK);
1.306 if (visible)
1.307 p->show();
1.308 else
1.309 p->hide();
1.310 pa0.resize (3);
1.311 - // TODO
1.312 - // a bit awkward: draw the lines additionally to polygon, to avoid
1.313 - // missing pixels, when polygon is extremly flat
1.314 - l = new QCanvasLine(canvas);
1.315 - l->setPen( QPen(linkcolor, 1) );
1.316 - l->setZ(Z_LINK);
1.317 - if (visible)
1.318 - l->show();
1.319 - else
1.320 - l->hide();
1.321 break;
1.322 - case StylePolyParabel:
1.323 - p = new QCanvasPolygon(canvas);
1.324 - p->setBrush( linkcolor );
1.325 - p->setZ(Z_LINK);
1.326 + case PolyParabel:
1.327 + p = scene->addPolygon(QPolygonF(),pen,linkcolor);
1.328 + p->setZValue(Z_LINK);
1.329 if (visible)
1.330 p->show();
1.331 else
1.332 @@ -225,83 +264,83 @@
1.333 pa0.resize (arcsegs*2+2);
1.334 pa1.resize (arcsegs+1);
1.335 pa2.resize (arcsegs+1);
1.336 -
1.337 - // TODO
1.338 - // a bit awkward: draw the lines additionally
1.339 - // to polygon, to avoid missing pixels,
1.340 - // if polygon is extremly flat
1.341 - for (i=0;i<arcsegs;i++)
1.342 - {
1.343 - cl = new QCanvasLine(canvas);
1.344 - cl->setPen( QPen(linkcolor, 1) );
1.345 - cl->setPoints( 0,0,i*10,100);
1.346 - cl->setZ(Z_LINK);
1.347 - if (visible)
1.348 - cl->show();
1.349 - else
1.350 - cl->hide();
1.351 - segment.append(cl);
1.352 - }
1.353 break;
1.354 default:
1.355 break;
1.356 }
1.357 - } else
1.358 - {
1.359 - cout << "Error: ChildObj or parObj == NULL in LinkableMapObj::setLinkStyle\n";
1.360 - }
1.361 + }
1.362 }
1.363
1.364 -LinkStyle LinkableMapObj::getLinkStyle()
1.365 +LinkableMapObj::Style LinkableMapObj::getLinkStyle()
1.366 {
1.367 return style;
1.368 }
1.369
1.370 -void LinkableMapObj::setLinkPos(LinkPos lp)
1.371 +void LinkableMapObj::setHideLinkUnselected(bool b)
1.372 +{
1.373 + hideLinkUnselected=b;
1.374 + setVisibility (visible);
1.375 + updateLink();
1.376 +}
1.377 +
1.378 +bool LinkableMapObj::getHideLinkUnselected()
1.379 +{
1.380 + return hideLinkUnselected;
1.381 +}
1.382 +
1.383 +void LinkableMapObj::setLinkPos(Position lp)
1.384 {
1.385 linkpos=lp;
1.386 }
1.387
1.388 -LinkPos LinkableMapObj::getLinkPos()
1.389 +LinkableMapObj::Position LinkableMapObj::getLinkPos()
1.390 {
1.391 return linkpos;
1.392 }
1.393
1.394 +void LinkableMapObj::setID (const QString &s)
1.395 +{
1.396 + objID=s;
1.397 +}
1.398 +
1.399 +QString LinkableMapObj::getID()
1.400 +{
1.401 + return objID;
1.402 +}
1.403
1.404 void LinkableMapObj::setLinkColor()
1.405 {
1.406 // Overloaded in BranchObj and childs
1.407 // here only set default color
1.408 - setLinkColor (mapEditor->getDefLinkColor());
1.409 + if (mapEditor)
1.410 + setLinkColor (mapEditor->getMapDefLinkColor());
1.411 }
1.412
1.413 void LinkableMapObj::setLinkColor(QColor col)
1.414 {
1.415 linkcolor=col;
1.416 - bottomline->setPen( QPen(linkcolor, 1) );
1.417 - QCanvasLine *cl;
1.418 + pen.setColor(col);
1.419 + bottomline->setPen( pen );
1.420 switch (style)
1.421 {
1.422 - case StyleLine:
1.423 - l->setPen( QPen(col,1));
1.424 + case Line:
1.425 + l->setPen( pen);
1.426 break;
1.427 - case StyleParabel:
1.428 - for (cl=segment.first(); cl; cl=segment.next() )
1.429 - cl->setPen( QPen(col,1));
1.430 + case Parabel:
1.431 + for (int i=0; i<segment.size(); ++i)
1.432 + segment.at(i)->setPen( pen);
1.433 break;
1.434 - case StylePolyLine:
1.435 + case PolyLine:
1.436 p->setBrush( QBrush(col));
1.437 - l->setPen( QPen(col,1));
1.438 + p->setPen( pen);
1.439 break;
1.440 - case StylePolyParabel:
1.441 + case PolyParabel:
1.442 p->setBrush( QBrush(col));
1.443 - for (cl=segment.first(); cl; cl=segment.next() )
1.444 - cl->setPen( QPen(col,1));
1.445 + p->setPen( pen);
1.446 break;
1.447 default:
1.448 break;
1.449 } // switch (style)
1.450 - updateLink();
1.451 }
1.452
1.453 QColor LinkableMapObj::getLinkColor()
1.454 @@ -309,58 +348,85 @@
1.455 return linkcolor;
1.456 }
1.457
1.458 -FrameType LinkableMapObj::getFrameType()
1.459 -{
1.460 - return frame->getFrameType();
1.461 -}
1.462 -
1.463 -void LinkableMapObj::setFrameType(const FrameType &t)
1.464 -{
1.465 - frame->setFrameType(t);
1.466 - calcBBoxSize();
1.467 - positionBBox();
1.468 - requestReposition();
1.469 -}
1.470 -
1.471 -void LinkableMapObj::setFrameType(const QString &t)
1.472 -{
1.473 - frame->setFrameType(t);
1.474 - calcBBoxSize();
1.475 - positionBBox();
1.476 - requestReposition();
1.477 -}
1.478 -
1.479 void LinkableMapObj::setVisibility (bool v)
1.480 {
1.481 MapObj::setVisibility (v);
1.482 - if (visible)
1.483 + bool visnow=visible;
1.484 +
1.485 + // We can hide the link, while object is not selected
1.486 + if (hideLinkUnselected && !selected)
1.487 + visnow=false;
1.488 +
1.489 + if (visnow)
1.490 {
1.491 bottomline->show();
1.492 - // FIXME lines and segments should be done in LMO?
1.493 - if (style==StyleLine && l)
1.494 + switch (style)
1.495 {
1.496 - l->show();
1.497 - } else
1.498 - {
1.499 - QCanvasLine* cl;
1.500 - for (cl=segment.first(); cl; cl=segment.next() )
1.501 - cl->show();
1.502 - }
1.503 + case Line:
1.504 + if (l) l->show();
1.505 + break;
1.506 + case Parabel:
1.507 + for (int i=0; i<segment.size(); ++i)
1.508 + segment.at(i)->show();
1.509 + break;
1.510 + case PolyLine:
1.511 + if (p) p->show();
1.512 + break;
1.513 + case PolyParabel:
1.514 + if (p) p->show();
1.515 + break;
1.516 + default:
1.517 + break;
1.518 + }
1.519 } else
1.520 {
1.521 bottomline->hide();
1.522 - if (style==StyleLine && l)
1.523 + switch (style)
1.524 {
1.525 - l->hide();
1.526 - } else
1.527 - {
1.528 - QCanvasLine* cl;
1.529 - for (cl=segment.first(); cl; cl=segment.next() )
1.530 - cl->hide();
1.531 - }
1.532 + case Line:
1.533 + if (l) l->hide();
1.534 + break;
1.535 + case Parabel:
1.536 + for (int i=0; i<segment.size(); ++i)
1.537 + segment.at(i)->hide();
1.538 + break;
1.539 + case PolyLine:
1.540 + if (p) p->hide();
1.541 + break;
1.542 + case PolyParabel:
1.543 + if (p) p->hide();
1.544 + break;
1.545 + default:
1.546 + break;
1.547 + }
1.548 }
1.549 }
1.550
1.551 +void LinkableMapObj::setOrientation()
1.552 +{
1.553 + Orientation orientOld=orientation;
1.554 +
1.555 + if (!parObj)
1.556 + {
1.557 + orientation=UndefinedOrientation;
1.558 + return;
1.559 + }
1.560 +
1.561 + // Set orientation, first look for orientation of parent
1.562 + if (parObj->getOrientation() != UndefinedOrientation )
1.563 + // use the orientation of the parent:
1.564 + orientation=parObj->getOrientation();
1.565 + else
1.566 + {
1.567 + // calc orientation depending on position rel to parent
1.568 + if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
1.569 + orientation=LeftOfCenter;
1.570 + else
1.571 + orientation=RightOfCenter;
1.572 + }
1.573 + if (orientOld!=orientation) requestReposition();
1.574 +}
1.575 +
1.576 void LinkableMapObj::updateLink()
1.577 {
1.578 // needs:
1.579 @@ -370,84 +436,38 @@
1.580 //
1.581 // sets:
1.582 // orientation
1.583 - // childPos
1.584 - // parPos
1.585 - // offset
1.586 + // childPos (by calling setDockPos())
1.587 + // parPos (by calling setDockPos())
1.588 + // bottomlineY
1.589 // drawing of the link itself
1.590
1.591 -
1.592 // updateLink is called from move, but called from constructor we don't
1.593 // have parents yet...
1.594 - if (style==StyleUndef) return;
1.595 + if (style==UndefinedStyle) return;
1.596
1.597 - if (frame->getFrameType() == NoFrame)
1.598 - linkpos=LinkBottom;
1.599 - else
1.600 - linkpos=LinkMiddle;
1.601 switch (linkpos)
1.602 {
1.603 - case LinkMiddle:
1.604 - offset=bbox.height() /2;
1.605 + case Middle:
1.606 + bottomlineY=bbox.top() + bbox.height()/2; // draw link to middle (of frame)
1.607 break;
1.608 - default :
1.609 - offset=bbox.height()-1; // draw link to bottom of bbox
1.610 + case Bottom:
1.611 + bottomlineY=bbox.bottom()-1; // draw link to bottom of box
1.612 break;
1.613 }
1.614
1.615 double p2x,p2y; // Set P2 Before setting
1.616 if (!link2ParPos)
1.617 {
1.618 - p2x=QPoint( parObj->getChildPos() ).x(); // P1, we have to look at
1.619 - p2y=QPoint( parObj->getChildPos() ).y(); // orientation
1.620 + p2x=QPointF( parObj->getChildPos() ).x(); // P1, we have to look at
1.621 + p2y=QPointF( parObj->getChildPos() ).y(); // orientation
1.622 } else
1.623 {
1.624 - p2x=QPoint( parObj->getParPos() ).x();
1.625 - p2y=QPoint( parObj->getParPos() ).y();
1.626 + p2x=QPointF( parObj->getParPos() ).x();
1.627 + p2y=QPointF( parObj->getParPos() ).y();
1.628 }
1.629
1.630 - LinkOrient orientOld=orientation;
1.631 -
1.632 - // Set orientation, first look for orientation of parent
1.633 - if (parObj->getOrientation() != OrientUndef )
1.634 - // use the orientation of the parent:
1.635 - orientation=parObj->getOrientation();
1.636 - else
1.637 - {
1.638 - // calc orientation depending on position rel to mapCenter
1.639 - if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
1.640 - orientation=OrientLeftOfCenter;
1.641 - else
1.642 - orientation=OrientRightOfCenter;
1.643 - }
1.644 -
1.645 - if ((orientation!=orientOld) && (orientOld!= OrientUndef))
1.646 - {
1.647 - // Orientation just changed. Reorient this subbranch, because move is called
1.648 - // before updateLink => Position is still the old one, which could lead to
1.649 - // linking of subranch to itself => segfault
1.650 - //
1.651 - // Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
1.652 - // no need to reposition now
1.653 - reposition();
1.654 - }
1.655 -
1.656 - if (orientation==OrientLeftOfCenter )
1.657 - {
1.658 - childPos=QPoint (absPos.x(),absPos.y()+offset);
1.659 - parPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset );
1.660 - } else
1.661 - {
1.662 - childPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset );
1.663 - parPos=QPoint (absPos.x(),absPos.y()+offset);
1.664 - }
1.665 - /* FIXME
1.666 - cout << " LMO::updateLink absPos="<<absPos<<endl;
1.667 - cout << " LMO::updateLink childPos="<<childPos<<endl;
1.668 - cout << " LMO::updateLink parPos="<<parPos<<endl;
1.669 - cout << " LMO::updateLink offset="<<offset<<endl;
1.670 - cout << " LMO::updateLink bbox.w="<<bbox.width()<<endl;
1.671 - cout << " LMO::updateLink bbox.h="<<bbox.height()<<endl;
1.672 - */
1.673 + setDockPos(); // Call overloaded method
1.674 + setOrientation();
1.675
1.676 double p1x=parPos.x(); // Link is drawn from P1 to P2
1.677 double p1y=parPos.y();
1.678 @@ -456,10 +476,11 @@
1.679 double vy=p2y - p1y;
1.680
1.681 // Draw the horizontal line below heading (from ChildPos to ParPos)
1.682 - bottomline->setPoints (lrint(childPos.x()),
1.683 - lrint(childPos.y()),
1.684 - lrint(p1x),
1.685 - lrint(p1y) );
1.686 + //bottomline->prepareGeometryChange();
1.687 + bottomline->setLine (QLine (qRound(childPos.x()),
1.688 + qRound(childPos.y()),
1.689 + qRound(p1x),
1.690 + qRound(p1y) ));
1.691
1.692 double a; // angle
1.693 if (vx > -0.000001 && vx < 0.000001)
1.694 @@ -467,57 +488,44 @@
1.695 else
1.696 a=atan( vy / vx );
1.697 // "turning point" for drawing polygonal links
1.698 - QPoint tp (-lrint(sin (a)*thickness_start), lrint(cos (a)*thickness_start));
1.699 + QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
1.700
1.701 - QCanvasLine *cl;
1.702 -
1.703 - int i;
1.704 -
1.705 // Draw the link
1.706 switch (style)
1.707 {
1.708 - case StyleLine:
1.709 - l->setPoints( lrint (parPos.x()),
1.710 - lrint(parPos.y()),
1.711 - lrint(p2x),
1.712 - lrint(p2y) );
1.713 + case Line:
1.714 + //l->prepareGeometryChange();
1.715 + l->setLine( QLine(qRound (parPos.x()),
1.716 + qRound(parPos.y()),
1.717 + qRound(p2x),
1.718 + qRound(p2y) ));
1.719 break;
1.720 - case StyleParabel:
1.721 + case Parabel:
1.722 parabel (pa0, p1x,p1y,p2x,p2y);
1.723 - i=0;
1.724 - for (cl=segment.first(); cl; cl=segment.next() )
1.725 - {
1.726 - cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
1.727 - i++;
1.728 - }
1.729 + for (int i=0; i<segment.size(); ++i)
1.730 + {
1.731 + //segment.at(i)->prepareGeometryChange();
1.732 + segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
1.733 + }
1.734 break;
1.735 - case StylePolyLine:
1.736 - pa0[0]=QPoint (lrint(p2x+tp.x()), lrint(p2y+tp.y()));
1.737 - pa0[1]=QPoint (lrint(p2x-tp.x()), lrint(p2y-tp.y()));
1.738 - pa0[2]=QPoint (lrint (parPos.x()), lrint(parPos.y()) );
1.739 - p->setPoints (pa0);
1.740 - // here too, draw line to avoid missing pixels
1.741 - l->setPoints( lrint (parPos.x()),
1.742 - lrint(parPos.y()),
1.743 - lrint(p2x),
1.744 - lrint(p2y) );
1.745 + case PolyLine:
1.746 + pa0.clear();
1.747 + pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
1.748 + pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
1.749 + pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
1.750 + //p->prepareGeometryChange();
1.751 + p->setPolygon(QPolygonF (pa0));
1.752 break;
1.753 - case StylePolyParabel:
1.754 + case PolyParabel:
1.755 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
1.756 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
1.757 - for (i=0;i<=arcsegs;i++)
1.758 - {
1.759 - // Combine the arrays to a single one
1.760 - pa0[i]=pa1[i];
1.761 - pa0[i+arcsegs+1]=pa2[arcsegs-i];
1.762 - }
1.763 - p->setPoints (pa0);
1.764 - i=0;
1.765 - for (cl=segment.first(); cl; cl=segment.next() )
1.766 - {
1.767 - cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
1.768 - i++;
1.769 - }
1.770 + pa0.clear();
1.771 + for (int i=0;i<=arcsegs;i++)
1.772 + pa0 << QPointF (pa1.at(i));
1.773 + for (int i=0;i<=arcsegs;i++)
1.774 + pa0 << QPointF (pa2.at(arcsegs-i));
1.775 + //p->prepareGeometryChange();
1.776 + p->setPolygon(QPolygonF (pa0));
1.777 break;
1.778 default:
1.779 break;
1.780 @@ -534,26 +542,59 @@
1.781 return parObj;
1.782 }
1.783
1.784 -QPoint LinkableMapObj::getChildPos()
1.785 +LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
1.786 +{
1.787 + LinkableMapObj *lmo=this;
1.788 + QString part;
1.789 + QString typ;
1.790 + QString num;
1.791 + while (!s.isEmpty() )
1.792 + {
1.793 + part=s.section(",",0,0);
1.794 + typ=part.left (3);
1.795 + num=part.right(part.length() - 3);
1.796 + if (typ=="mc:")
1.797 + {
1.798 + if (depth>0)
1.799 + return false; // in a subtree there is no center
1.800 + else
1.801 + break;
1.802 + } else
1.803 + if (typ=="bo:")
1.804 + lmo=((BranchObj*)lmo)->getBranchNum (num.toInt());
1.805 + else
1.806 + if (typ=="fi:")
1.807 + lmo=((BranchObj*)lmo)->getFloatImageNum (num.toUInt());
1.808 + if (!lmo) break;
1.809 +
1.810 + if (s.contains(","))
1.811 + s=s.right(s.length() - part.length() -1 );
1.812 + else
1.813 + break;
1.814 + }
1.815 + return lmo;
1.816 +}
1.817 +
1.818 +QPointF LinkableMapObj::getChildPos()
1.819 {
1.820 return childPos;
1.821 }
1.822
1.823 -QPoint LinkableMapObj::getParPos()
1.824 +QPointF LinkableMapObj::getParPos()
1.825 {
1.826 return parPos;
1.827 }
1.828
1.829 -QPoint LinkableMapObj::getRelPos()
1.830 -{
1.831 - if (!parObj) return QPoint (0,0);
1.832 - return QPoint(
1.833 - absPos.x() - parObj->x(),
1.834 - absPos.y() - parObj->y()
1.835 - );
1.836 +void LinkableMapObj::setUseOrientation (const bool &b)
1.837 +{
1.838 + if (useOrientation!=b)
1.839 + {
1.840 + useOrientation=b;
1.841 + requestReposition();
1.842 + }
1.843 }
1.844
1.845 -LinkOrient LinkableMapObj::getOrientation()
1.846 +LinkableMapObj::Orientation LinkableMapObj::getOrientation()
1.847 {
1.848 return orientation;
1.849 }
1.850 @@ -573,36 +614,16 @@
1.851 return mapEditor;
1.852 }
1.853
1.854 -QPoint LinkableMapObj::getRandPos()
1.855 +QPointF LinkableMapObj::getRandPos()
1.856 {
1.857 // Choose a random position with given distance to parent:
1.858 double a=rand()%360 * 2 * M_PI / 360;
1.859 - return QPoint ( (int)( + 150*cos (a)),
1.860 + return QPointF ( (int)( + 150*cos (a)),
1.861 (int)( + 150*sin (a)));
1.862 }
1.863
1.864 -void LinkableMapObj::alignRelativeTo (QPoint ref)
1.865 -{
1.866 -}
1.867 -
1.868 void LinkableMapObj::reposition()
1.869 {
1.870 -cout << "LMO::reposition ???"<<endl;
1.871 - if (depth==0)
1.872 - {
1.873 - // only calculate the sizes once. If the deepest LMO changes its height,
1.874 - // all upper LMOs have to change, too.
1.875 - calcBBoxSizeWithChilds();
1.876 -
1.877 - alignRelativeTo ( QPoint (absPos.x(),
1.878 - absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.879 - } else
1.880 - {
1.881 - // This is only important for moving branches:
1.882 - // For editing a branch it isn't called...
1.883 - alignRelativeTo ( QPoint (absPos.x(),
1.884 - absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.885 - }
1.886 }
1.887
1.888 void LinkableMapObj::requestReposition()
1.889 @@ -626,14 +647,15 @@
1.890 // we want to block expensive repositioning, but just do it once at
1.891 // the end, thus check first:
1.892
1.893 - if (mapEditor->blockReposition()) return;
1.894 + if (mapEditor->isRepositionBlocked()) return;
1.895
1.896 // Pass on the request to parental objects, if this hasn't been done yet
1.897
1.898 if (parObj)
1.899 parObj->forceReposition();
1.900 else
1.901 - reposition(); }
1.902 + reposition();
1.903 +}
1.904
1.905 bool LinkableMapObj::repositionRequested()
1.906 {
1.907 @@ -641,28 +663,23 @@
1.908 }
1.909
1.910
1.911 -void LinkableMapObj::setSelBox()
1.912 -{
1.913 - selbox->setX (bbox.x() );
1.914 - selbox->setY (bbox.y() );
1.915 - selbox->setSize (bbox.width(), bbox.height() );
1.916 -}
1.917 -
1.918 void LinkableMapObj::select()
1.919 {
1.920 - setSelBox();
1.921 + // select and unselect are still needed to
1.922 + // handle hiding of links
1.923 selected=true;
1.924 - selbox->show();
1.925 + setVisibility (visible);
1.926 }
1.927
1.928
1.929 void LinkableMapObj::unselect()
1.930 {
1.931 selected=false;
1.932 - selbox->hide();
1.933 + // Maybe we have to hide the link:
1.934 + setVisibility (visible);
1.935 }
1.936
1.937 -void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y)
1.938 +void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
1.939
1.940 {
1.941 double vx=p2x - p1x; // V=P2-P1
1.942 @@ -679,15 +696,24 @@
1.943 else
1.944 m=(vy / (vx*vx));
1.945 dx=vx/(arcsegs);
1.946 - int i;
1.947 - ya.setPoint (0,QPoint (lrint(p1x),lrint(p1y)));
1.948 - for (i=1;i<=arcsegs;i++)
1.949 + ya.clear();
1.950 + ya<<QPointF (p1x,p1y);
1.951 + for (int i=1;i<=arcsegs;i++)
1.952 {
1.953 pnx=p1x+dx;
1.954 pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
1.955 - ya.setPoint (i,QPoint (lrint(pnx),lrint(pny)));
1.956 + ya<<QPointF (pnx,pny);
1.957 p1x=pnx;
1.958 p1y=pny;
1.959 }
1.960 }
1.961
1.962 +QString LinkableMapObj::getLinkAttr ()
1.963 +{
1.964 + if (hideLinkUnselected)
1.965 + return attribut ("hideLink","true");
1.966 + else
1.967 + return attribut ("hideLink","false");
1.968 +
1.969 +}
1.970 +