1.1 --- a/linkablemapobj.cpp Thu Nov 23 16:18:26 2006 +0000
1.2 +++ b/linkablemapobj.cpp Fri Dec 08 20:18:56 2006 +0000
1.3 @@ -4,10 +4,6 @@
1.4 #include "branchobj.h"
1.5 #include "mapeditor.h"
1.6
1.7 -//Added by qt3to4:
1.8 -#include <Q3PointArray>
1.9 -
1.10 -
1.11 /////////////////////////////////////////////////////////////////
1.12 // LinkableMapObj
1.13 /////////////////////////////////////////////////////////////////
1.14 @@ -18,13 +14,13 @@
1.15 init ();
1.16 }
1.17
1.18 -LinkableMapObj::LinkableMapObj(Q3Canvas* c) :MapObj(c)
1.19 +LinkableMapObj::LinkableMapObj(QGraphicsScene* s) :MapObj(s)
1.20 {
1.21 -// cout << "Const LinkableMapObj\n";
1.22 +// cout << "Const LinkableMapObj (s)\n";
1.23 init ();
1.24 }
1.25
1.26 -LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
1.27 +LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
1.28 {
1.29 copy (lmo);
1.30 }
1.31 @@ -49,11 +45,9 @@
1.32 break;
1.33 case StylePolyLine:
1.34 delete (p);
1.35 - delete (l);
1.36 break;
1.37 case StylePolyParabel:
1.38 delete (p);
1.39 - while (!segment.isEmpty()) delete segment.takeFirst();
1.40 break;
1.41 default:
1.42 break;
1.43 @@ -67,8 +61,8 @@
1.44 childObj=NULL;
1.45 parObj=NULL;
1.46 parObjTmpBuf=NULL;
1.47 - parPos=QPoint(0,0);
1.48 - childPos=QPoint(0,0);
1.49 + parPos=QPointF(0,0);
1.50 + childPos=QPointF(0,0);
1.51 link2ParPos=false;
1.52 l=NULL;
1.53 orientation=OrientUndef;
1.54 @@ -77,18 +71,18 @@
1.55 style=StyleUndef;
1.56 linkpos=LinkBottom;
1.57 arcsegs=13;
1.58 - Q3PointArray pa(arcsegs*2+2);
1.59
1.60 - bottomline=new Q3CanvasLine(canvas);
1.61 - bottomline->setPen( QPen(linkcolor, 1) );
1.62 - bottomline->setZ(Z_LINK);
1.63 +// FIXME instead of linkcolor pen.color() could be used
1.64 + pen.setWidth (1);
1.65 + pen.setColor (linkcolor);
1.66 + pen.setCapStyle ( Qt::RoundCap );
1.67 + bottomline=scene->addLine(QLineF(1,1,1,1),pen);
1.68 + bottomline->setZValue(Z_LINK);
1.69 bottomline->show();
1.70
1.71 // Prepare showing the selection of a MapObj
1.72 - selbox = new Q3CanvasRectangle (canvas);
1.73 - selbox->setZ(Z_SELBOX);
1.74 - selbox->setBrush( QColor(255,255,0) );
1.75 - selbox->setPen( QPen(QColor(255,255,0) ));
1.76 + selbox = scene->addRect(QRectF(0,0,0,0), QPen(QColor(255,255,0) ), QColor(255,255,0));
1.77 + selbox->setZValue(Z_SELBOX);
1.78 selbox->hide();
1.79 selected=false;
1.80
1.81 @@ -97,12 +91,12 @@
1.82 topPad=botPad=leftPad=rightPad=0;
1.83
1.84 // initialize frame
1.85 - frame = new FrameObj (canvas);
1.86 + frame = new FrameObj (scene);
1.87
1.88 repositionRequest=false;
1.89
1.90 // Rel Positions
1.91 - relPos=QPoint(0,0);
1.92 + relPos=QPointF(0,0);
1.93 useRelPos=false;
1.94 useOrientation=true;
1.95 }
1.96 @@ -129,7 +123,7 @@
1.97 mapEditor=parObj->getMapEditor();
1.98 }
1.99
1.100 -void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
1.101 +void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int)
1.102 {
1.103 }
1.104
1.105 @@ -161,7 +155,7 @@
1.106 }
1.107 }
1.108
1.109 -void LinkableMapObj::setRelPos(const QPoint &p)
1.110 +void LinkableMapObj::setRelPos(const QPointF &p)
1.111 {
1.112 relPos=p;
1.113 if (parObj)
1.114 @@ -174,23 +168,23 @@
1.115 }
1.116 }
1.117
1.118 -QPoint LinkableMapObj::getRelPos()
1.119 +QPointF LinkableMapObj::getRelPos()
1.120 {
1.121 - if (!parObj) return QPoint();
1.122 + if (!parObj) return QPointF();
1.123 return relPos;
1.124 }
1.125
1.126 -int LinkableMapObj::getTopPad()
1.127 +qreal LinkableMapObj::getTopPad()
1.128 {
1.129 return topPad;
1.130 }
1.131
1.132 -int LinkableMapObj::getLeftPad()
1.133 +qreal LinkableMapObj::getLeftPad()
1.134 {
1.135 return leftPad;
1.136 }
1.137
1.138 -int LinkableMapObj::getRightPad()
1.139 +qreal LinkableMapObj::getRightPad()
1.140 {
1.141 return rightPad;
1.142 }
1.143 @@ -234,29 +228,25 @@
1.144
1.145 if (childObj!=NULL && parObj != NULL)
1.146 {
1.147 - int i;
1.148 - Q3CanvasLine* cl;
1.149 + QGraphicsLineItem *cl;
1.150 switch (style)
1.151 {
1.152 case StyleUndef:
1.153 bottomline->hide();
1.154 break;
1.155 case StyleLine:
1.156 - l = new Q3CanvasLine(canvas);
1.157 - l->setPen( QPen(linkcolor, 1) );
1.158 - l->setZ(Z_LINK);
1.159 + l = scene->addLine(QLineF(1,1,1,1),pen);
1.160 + l->setZValue(Z_LINK);
1.161 if (visible)
1.162 l->show();
1.163 else
1.164 l->hide();
1.165 break;
1.166 case StyleParabel:
1.167 - for (i=0;i<arcsegs;i++)
1.168 + for (int i=0;i<arcsegs;i++)
1.169 {
1.170 - cl = new Q3CanvasLine(canvas);
1.171 - cl->setPen( QPen(linkcolor, 1) );
1.172 - cl->setPoints( i*5,0,i*10,100);
1.173 - cl->setZ(Z_LINK);
1.174 + cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
1.175 + cl->setZValue(Z_LINK);
1.176 if (visible)
1.177 cl->show();
1.178 else
1.179 @@ -266,28 +256,17 @@
1.180 pa0.resize (arcsegs+1);
1.181 break;
1.182 case StylePolyLine:
1.183 - p = new Q3CanvasPolygon(canvas);
1.184 - p->setBrush( linkcolor );
1.185 - p->setZ(Z_LINK);
1.186 + p =scene->addPolygon(QPolygonF(),pen,linkcolor);
1.187 + p->setZValue(Z_LINK);
1.188 if (visible)
1.189 p->show();
1.190 else
1.191 p->hide();
1.192 pa0.resize (3);
1.193 - // TODO a bit awkward: draw the lines additionally to polygon, to avoid
1.194 - // missing pixels, when polygon is extremly flat
1.195 - l = new Q3CanvasLine(canvas);
1.196 - l->setPen( QPen(linkcolor, 1) );
1.197 - l->setZ(Z_LINK);
1.198 - if (visible)
1.199 - l->show();
1.200 - else
1.201 - l->hide();
1.202 break;
1.203 case StylePolyParabel:
1.204 - p = new Q3CanvasPolygon(canvas);
1.205 - p->setBrush( linkcolor );
1.206 - p->setZ(Z_LINK);
1.207 + p = scene->addPolygon(QPolygonF(),pen,linkcolor);
1.208 + p->setZValue(Z_LINK);
1.209 if (visible)
1.210 p->show();
1.211 else
1.212 @@ -295,22 +274,6 @@
1.213 pa0.resize (arcsegs*2+2);
1.214 pa1.resize (arcsegs+1);
1.215 pa2.resize (arcsegs+1);
1.216 -
1.217 - // TODO a bit awkward: draw the lines additionally
1.218 - // to polygon, to avoid missing pixels,
1.219 - // if polygon is extremly flat
1.220 - for (i=0;i<arcsegs;i++)
1.221 - {
1.222 - cl = new Q3CanvasLine(canvas);
1.223 - cl->setPen( QPen(linkcolor, 1) );
1.224 - cl->setPoints( 5*i,0,i*10,100);
1.225 - cl->setZ(Z_LINK);
1.226 - if (visible)
1.227 - cl->show();
1.228 - else
1.229 - cl->hide();
1.230 - segment.append(cl);
1.231 - }
1.232 break;
1.233 default:
1.234 break;
1.235 @@ -357,24 +320,22 @@
1.236 void LinkableMapObj::setLinkColor(QColor col)
1.237 {
1.238 linkcolor=col;
1.239 - bottomline->setPen( QPen(linkcolor, 1) );
1.240 + pen.setColor(col);
1.241 + bottomline->setPen( pen );
1.242 switch (style)
1.243 {
1.244 case StyleLine:
1.245 - l->setPen( QPen(col,1));
1.246 + l->setPen( pen);
1.247 break;
1.248 case StyleParabel:
1.249 for (int i=0; i<segment.size(); ++i)
1.250 - segment.at(i)->setPen( QPen(col,1));
1.251 + segment.at(i)->setPen( pen);
1.252 break;
1.253 case StylePolyLine:
1.254 p->setBrush( QBrush(col));
1.255 - l->setPen( QPen(col,1));
1.256 break;
1.257 case StylePolyParabel:
1.258 p->setBrush( QBrush(col));
1.259 - for (int i=0; i<segment.size(); ++i)
1.260 - segment.at(i)->setPen( QPen(col,1));
1.261 break;
1.262 default:
1.263 break;
1.264 @@ -430,11 +391,8 @@
1.265 break;
1.266 case StylePolyLine:
1.267 if (p) p->show();
1.268 - if (l) l->show();
1.269 break;
1.270 case StylePolyParabel:
1.271 - for (int i=0; i<segment.size(); ++i)
1.272 - segment.at(i)->show();
1.273 if (p) p->show();
1.274 break;
1.275 default:
1.276 @@ -454,11 +412,8 @@
1.277 break;
1.278 case StylePolyLine:
1.279 if (p) p->hide();
1.280 - if (l) l->hide();
1.281 break;
1.282 case StylePolyParabel:
1.283 - for (int i=0; i<segment.size(); ++i)
1.284 - segment.at(i)->hide();
1.285 if (p) p->hide();
1.286 break;
1.287 default:
1.288 @@ -484,7 +439,7 @@
1.289 else
1.290 {
1.291 // calc orientation depending on position rel to parent
1.292 - if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
1.293 + if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
1.294 orientation=OrientLeftOfCenter;
1.295 else
1.296 orientation=OrientRightOfCenter;
1.297 @@ -527,12 +482,12 @@
1.298 double p2x,p2y; // Set P2 Before setting
1.299 if (!link2ParPos)
1.300 {
1.301 - p2x=QPoint( parObj->getChildPos() ).x(); // P1, we have to look at
1.302 - p2y=QPoint( parObj->getChildPos() ).y(); // orientation
1.303 + p2x=QPointF( parObj->getChildPos() ).x(); // P1, we have to look at
1.304 + p2y=QPointF( parObj->getChildPos() ).y(); // orientation
1.305 } else
1.306 {
1.307 - p2x=QPoint( parObj->getParPos() ).x();
1.308 - p2y=QPoint( parObj->getParPos() ).y();
1.309 + p2x=QPointF( parObj->getParPos() ).x();
1.310 + p2y=QPointF( parObj->getParPos() ).y();
1.311 }
1.312
1.313 setDockPos(); // Call overloaded method
1.314 @@ -545,10 +500,10 @@
1.315 double vy=p2y - p1y;
1.316
1.317 // Draw the horizontal line below heading (from ChildPos to ParPos)
1.318 - bottomline->setPoints (qRound(childPos.x()),
1.319 + bottomline->setLine (QLine (qRound(childPos.x()),
1.320 qRound(childPos.y()),
1.321 qRound(p1x),
1.322 - qRound(p1y) );
1.323 + qRound(p1y) ));
1.324
1.325 double a; // angle
1.326 if (vx > -0.000001 && vx < 0.000001)
1.327 @@ -556,45 +511,38 @@
1.328 else
1.329 a=atan( vy / vx );
1.330 // "turning point" for drawing polygonal links
1.331 - QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
1.332 + QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
1.333
1.334 // Draw the link
1.335 switch (style)
1.336 {
1.337 case StyleLine:
1.338 - l->setPoints( qRound (parPos.x()),
1.339 + l->setLine( QLine(qRound (parPos.x()),
1.340 qRound(parPos.y()),
1.341 qRound(p2x),
1.342 - qRound(p2y) );
1.343 + qRound(p2y) ));
1.344 break;
1.345 case StyleParabel:
1.346 parabel (pa0, p1x,p1y,p2x,p2y);
1.347 for (int i=0; i<segment.size(); ++i)
1.348 - segment.at(i)->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
1.349 + segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
1.350 break;
1.351 case StylePolyLine:
1.352 - pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
1.353 - pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
1.354 - pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
1.355 - p->setPoints (pa0);
1.356 - // here too, draw line to avoid missing pixels
1.357 - l->setPoints( qRound (parPos.x()),
1.358 - qRound(parPos.y()),
1.359 - qRound(p2x),
1.360 - qRound(p2y) );
1.361 + pa0.clear();
1.362 + pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
1.363 + pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
1.364 + pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
1.365 + p->setPolygon(QPolygonF (pa0));
1.366 break;
1.367 case StylePolyParabel:
1.368 parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
1.369 parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
1.370 + pa0.clear();
1.371 for (int i=0;i<=arcsegs;i++)
1.372 - {
1.373 - // Combine the arrays to a single one
1.374 - pa0[i]=pa1[i];
1.375 - pa0[i+arcsegs+1]=pa2[arcsegs-i];
1.376 - }
1.377 - p->setPoints (pa0);
1.378 - for (int i=0; i<segment.size(); ++i)
1.379 - segment.at(i)->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
1.380 + pa0 << QPointF (pa1.at(i));
1.381 + for (int i=0;i<=arcsegs;i++)
1.382 + pa0 << QPointF (pa2.at(arcsegs-i));
1.383 + p->setPolygon(QPolygonF (pa0));
1.384 break;
1.385 default:
1.386 break;
1.387 @@ -644,12 +592,12 @@
1.388 return lmo;
1.389 }
1.390
1.391 -QPoint LinkableMapObj::getChildPos()
1.392 +QPointF LinkableMapObj::getChildPos()
1.393 {
1.394 return childPos;
1.395 }
1.396
1.397 -QPoint LinkableMapObj::getParPos()
1.398 +QPointF LinkableMapObj::getParPos()
1.399 {
1.400 return parPos;
1.401 }
1.402 @@ -683,16 +631,16 @@
1.403 return mapEditor;
1.404 }
1.405
1.406 -QPoint LinkableMapObj::getRandPos()
1.407 +QPointF LinkableMapObj::getRandPos()
1.408 {
1.409 // Choose a random position with given distance to parent:
1.410 double a=rand()%360 * 2 * M_PI / 360;
1.411 - return QPoint ( (int)( + 150*cos (a)),
1.412 + return QPointF ( (int)( + 150*cos (a)),
1.413 (int)( + 150*sin (a)));
1.414 }
1.415
1.416 /*
1.417 -void LinkableMapObj::alignRelativeTo (QPoint ref)
1.418 +void LinkableMapObj::alignRelativeTo (QPointF ref)
1.419 {
1.420 // Overloaded, only called for BO, FIO, ...
1.421 // FIXME not needed?
1.422 @@ -702,7 +650,7 @@
1.423 void LinkableMapObj::reposition()
1.424 {
1.425 cout << "LMO::reposition\n";
1.426 - // FIXME not needed? Is overloaded in BranchObj...
1.427 + // FIXME LMO::reposition not needed? Is overloaded in BranchObj...
1.428 /*
1.429 if (depth==0)
1.430 {
1.431 @@ -710,14 +658,14 @@
1.432 // all upper LMOs have to change, too.
1.433 calcBBoxSizeWithChilds();
1.434
1.435 - alignRelativeTo ( QPoint (absPos.x(),
1.436 + alignRelativeTo ( QPointF (absPos.x(),
1.437 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.438 } else
1.439 {
1.440 // This is only important for moving branches:
1.441 // For editing a branch it isn't called...
1.442 cout << " reposition to abs "<<absPos<<endl;
1.443 - alignRelativeTo ( QPoint (absPos.x(),
1.444 + alignRelativeTo ( QPointF (absPos.x(),
1.445 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1.446 }
1.447 */
1.448 @@ -762,9 +710,7 @@
1.449
1.450 void LinkableMapObj::setSelBox()
1.451 {
1.452 - selbox->setX (clickBox.x() );
1.453 - selbox->setY (clickBox.y() );
1.454 - selbox->setSize (clickBox.width(), clickBox.height() );
1.455 + selbox->setRect (clickBox);
1.456 }
1.457
1.458 void LinkableMapObj::select()
1.459 @@ -785,7 +731,7 @@
1.460 setVisibility (visible);
1.461 }
1.462
1.463 -void LinkableMapObj::parabel (Q3PointArray &ya, double p1x, double p1y, double p2x, double p2y)
1.464 +void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
1.465
1.466 {
1.467 double vx=p2x - p1x; // V=P2-P1
1.468 @@ -802,13 +748,13 @@
1.469 else
1.470 m=(vy / (vx*vx));
1.471 dx=vx/(arcsegs);
1.472 - int i;
1.473 - ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
1.474 - for (i=1;i<=arcsegs;i++)
1.475 + ya.clear();
1.476 + ya<<QPointF (qRound(p1x),qRound(p1y));
1.477 + for (int i=1;i<=arcsegs;i++)
1.478 {
1.479 pnx=p1x+dx;
1.480 pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
1.481 - ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
1.482 + ya<<QPointF (qRound(pnx),qRound(pny));
1.483 p1x=pnx;
1.484 p1y=pny;
1.485 }