diff --git a/Mapper.cpp b/Mapper.cpp index 6c4a864..69f39ef 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -238,21 +238,16 @@ void EllipseColorMapper::draw(QPainter* painter) std::tr1::shared_ptr outputEllipse = std::tr1::static_pointer_cast(outputShape); qreal rotation = outputEllipse->getRotation(); qDebug() << "Rotation: " << rotation << endl; - QRect rect = outputEllipse->getBoundingRect(); + painter->save(); // save painter state painter->resetTransform(); painter->setBrush(color->getColor()); -// painter->translate() - //painter->translate(0, rect.height()/2); - const QPointF& p0 = outputEllipse->getVertex(0); const QPointF& center = outputEllipse->getCenter(); - float rx = rect.width() / 2; - float ry = rect.height() / 2; + float rx = outputEllipse->getHorizontalAxis().length() / 2; + float ry = outputEllipse->getVerticalAxis().length() / 2; painter->translate(center); painter->rotate(rotation); painter->drawEllipse(QPointF(0,0), rx, ry); -// painter->translate(p0.x() + rect.width()/2, p0.y() + rect.height() / 2); - //painter->drawEllipse(rect); painter->resetTransform(); for (int i=0; i<4; i++) { diff --git a/Shape.h b/Shape.h index 88fb96a..8cd8370 100644 --- a/Shape.h +++ b/Shape.h @@ -214,24 +214,27 @@ public: virtual QString getType() const { return "ellipse"; } qreal getRotation() const { - QPointF hAxis = getHorizontalAxis(); + QVector2D hAxis = getHorizontalAxis(); return atan2(hAxis.y(), hAxis.x()) * 180.0 / M_PI; } - QRect getBoundingRect() const { - return QRect(0, getVerticalAxis().manhattanLength(), getHorizontalAxis().manhattanLength(), getVerticalAxis().manhattanLength()); - } - +// QRect getBoundingRect() const { +// return QRect(0, getVerticalAxis().manhattanLength(), +// getHorizontalAxis().manhattanLength(), getVerticalAxis().manhattanLength()); +// } +// QPointF getCenter() const { - return getVertex(0) + (getHorizontalAxis() / 2); + return (QVector2D(getVertex(0)) + (getHorizontalAxis() / 2)).toPointF(); } - QPointF getHorizontalAxis() const { - return getVertex(2) - getVertex(0); + QVector2D getHorizontalAxis() const { + return QVector2D(getVertex(2)) - QVector2D(getVertex(0)); + } + + QVector2D getVerticalAxis() const { + return QVector2D(getVertex(1)) - QVector2D(getVertex(3)); } - QPointF getVerticalAxis() const { - return getVertex(1) - getVertex(3); } //protected: