QTfrontend/drawmapscene.cpp
changeset 9553 f92d43816186
parent 9551 61f160dfd0f1
child 9555 485b424be769
equal deleted inserted replaced
9551:61f160dfd0f1 9553:f92d43816186
   139         case Polyline: {
   139         case Polyline: {
   140             QPainterPath path = m_currPath->path();
   140             QPainterPath path = m_currPath->path();
   141             path.lineTo(mouseEvent->scenePos());
   141             path.lineTo(mouseEvent->scenePos());
   142             paths.first().points.append(mouseEvent->scenePos().toPoint());
   142             paths.first().points.append(mouseEvent->scenePos().toPoint());
   143             m_currPath->setPath(path);
   143             m_currPath->setPath(path);
       
   144             simplifyLast();
   144             break;
   145             break;
   145         }
   146         }
   146         case Rectangle: {
   147         case Rectangle: {
   147             QPoint p1 = paths.first().initialPoint;
   148             QPoint p1 = paths.first().initialPoint;
   148             QPoint p2 = mouseEvent->scenePos().toPoint();
   149             QPoint p2 = mouseEvent->scenePos().toPoint();
   160                 epoints.append(p.toPoint());
   161                 epoints.append(p.toPoint());
   161             paths.first().points = epoints;
   162             paths.first().points = epoints;
   162             break;
   163             break;
   163         }
   164         }
   164 
   165 
   165         simplifyLast();
       
   166 
       
   167         m_currPath = 0;
   166         m_currPath = 0;
       
   167 
       
   168         emit pathChanged();
   168     }
   169     }
   169 }
   170 }
   170 
   171 
   171 void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
   172 void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
   172 {
   173 {
   393     // redraw path
   394     // redraw path
   394     {
   395     {
   395         QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[m_isCursorShown ? 1 : 0]);
   396         QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[m_isCursorShown ? 1 : 0]);
   396         pathItem->setPath(pointsToPath(paths[0].points));
   397         pathItem->setPath(pointsToPath(paths[0].points));
   397     }
   398     }
   398 
       
   399     emit pathChanged();
       
   400 }
   399 }
   401 
   400 
   402 int DrawMapScene::pointsCount()
   401 int DrawMapScene::pointsCount()
   403 {
   402 {
   404     int cnt = 0;
   403     int cnt = 0;
   440 }
   439 }
   441 
   440 
   442 QList<QPointF> DrawMapScene::makeEllipse(const QPointF &center, const QPointF &corner)
   441 QList<QPointF> DrawMapScene::makeEllipse(const QPointF &center, const QPointF &corner)
   443 {
   442 {
   444     QList<QPointF> l;
   443     QList<QPointF> l;
   445     qreal r = (center - corner).manhattanLength();
       
   446     qreal rx = qAbs(center.x() - corner.x());
   444     qreal rx = qAbs(center.x() - corner.x());
   447     qreal ry = qAbs(center.y() - corner.y());
   445     qreal ry = qAbs(center.y() - corner.y());
       
   446     qreal r = qMax(rx, ry);
   448 
   447 
   449     if(r < 4)
   448     if(r < 4)
   450     {
   449     {
   451         l.append(center);
   450         l.append(center);
   452     } else
   451     } else
   453     {
   452     {
   454         qreal angleDelta = 12 / r;
   453         qreal angleDelta = qMax(0.1, qMin(0.7, 120 / r));
   455         for(qreal angle = 0.0; angle < 2*M_PI; angle += angleDelta)
   454         for(qreal angle = 0.0; angle < 2*M_PI; angle += angleDelta)
   456             l.append(center + QPointF(rx * cos(angle), ry * sin(angle)));
   455             l.append(center + QPointF(rx * cos(angle), ry * sin(angle)));
   457         l.append(l.first());
   456         l.append(l.first());
   458     }
   457     }
   459 
   458