diff --git a/src/frameworks/UBGeometryUtils.cpp b/src/frameworks/UBGeometryUtils.cpp index a68db820..cc891b85 100644 --- a/src/frameworks/UBGeometryUtils.cpp +++ b/src/frameworks/UBGeometryUtils.cpp @@ -18,6 +18,11 @@ #include "core/memcheck.h" const double PI = 4.0 * atan(1.0); +const int UBGeometryUtils::centimeterGraduationHeight = 15; +const int UBGeometryUtils::halfCentimeterGraduationHeight = 10; +const int UBGeometryUtils::millimeterGraduationHeight = 5; +const int UBGeometryUtils::millimetersPerCentimeter = 10; +const int UBGeometryUtils::millimetersPerHalfCentimeter = 5; UBGeometryUtils::UBGeometryUtils() { diff --git a/src/frameworks/UBGeometryUtils.h b/src/frameworks/UBGeometryUtils.h index 5b6bb3d1..c5ac5e8e 100644 --- a/src/frameworks/UBGeometryUtils.h +++ b/src/frameworks/UBGeometryUtils.h @@ -37,6 +37,12 @@ class UBGeometryUtils static QPoint pointConstrainedInRect(QPoint point, QRect rect); static void crashPointList(QVector &points); + + const static int centimeterGraduationHeight; + const static int halfCentimeterGraduationHeight; + const static int millimeterGraduationHeight; + const static int millimetersPerCentimeter; + const static int millimetersPerHalfCentimeter; }; #endif /* UBGEOMETRYUTILS_H_ */ diff --git a/src/tools/UBAbstractDrawRuler.h b/src/tools/UBAbstractDrawRuler.h index 5aa2d617..c6d21f31 100644 --- a/src/tools/UBAbstractDrawRuler.h +++ b/src/tools/UBAbstractDrawRuler.h @@ -16,6 +16,8 @@ #define UB_ABSTRACTDRAWRULER_H_ #include +#include "frameworks/UBGeometryUtils.h" + class UBGraphicsScene; class QGraphicsSvgItem; @@ -45,7 +47,8 @@ protected: virtual void rotateAroundCenter(qreal angle) = 0; virtual QPointF rotationCenter() const = 0; - virtual QRectF closeButtonRect() const = 0; + virtual QRectF closeButtonRect() const = 0; + virtual void paintGraduations(QPainter *painter) = 0; bool mShowButtons; QGraphicsSvgItem* mCloseSvgItem; diff --git a/src/tools/UBGraphicsProtractor.h b/src/tools/UBGraphicsProtractor.h index 0af790de..6666ae76 100644 --- a/src/tools/UBGraphicsProtractor.h +++ b/src/tools/UBGraphicsProtractor.h @@ -62,10 +62,10 @@ class UBGraphicsProtractor : public UBAbstractDrawRuler, public QGraphicsEllipse virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event); virtual QPainterPath shape() const; QRectF boundingRect() const; + void paintGraduations(QPainter *painter); private: // Helpers - void paintGraduations (QPainter *painter); void paintButtons (QPainter *painter); void paintAngleMarker (QPainter *painter); Tool toolFromPos (QPointF pos); diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 2542bdec..66caf2f8 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -158,36 +158,30 @@ void UBGraphicsRuler::fillBackground(QPainter *painter) void UBGraphicsRuler::paintGraduations(QPainter *painter) { - const int centimeterGraduationHeight = 15; - const int halfCentimeterGraduationHeight = 10; - const int millimeterGraduationHeight = 5; - const int millimetersPerCentimeter = 10; - const int millimetersPerHalfCentimeter = 5; - painter->save(); painter->setFont(font()); QFontMetricsF fontMetrics(painter->font()); for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) { int graduationX = rotationCenter().x() + sPixelsPerMillimeter * millimeters; - int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? - centimeterGraduationHeight : - ((0 == millimeters % millimetersPerHalfCentimeter) ? - halfCentimeterGraduationHeight : millimeterGraduationHeight); + int graduationHeight = (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) ? + UBGeometryUtils::centimeterGraduationHeight : + ((0 == millimeters % UBGeometryUtils::millimetersPerHalfCentimeter) ? + UBGeometryUtils::halfCentimeterGraduationHeight : UBGeometryUtils::millimeterGraduationHeight); painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() + graduationHeight)); painter->drawLine(QLine(graduationX, rotationCenter().y() + rect().height(), graduationX, rotationCenter().y() + rect().height() - graduationHeight)); - if (0 == millimeters % millimetersPerCentimeter) + if (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) { - QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); + QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter)); if (graduationX + fontMetrics.width(text) / 2 < rect().right()) { qreal textWidth = fontMetrics.width(text); qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5; painter->drawText( - QRectF(graduationX - textWidth / 2, rect().top() + 5 + centimeterGraduationHeight, textWidth, textHeight), + QRectF(graduationX - textWidth / 2, rect().top() + 5 + UBGeometryUtils::centimeterGraduationHeight, textWidth, textHeight), Qt::AlignVCenter, text); painter->drawText( - QRectF(graduationX - textWidth / 2, rect().bottom() - 5 - centimeterGraduationHeight - textHeight, textWidth, textHeight), + QRectF(graduationX - textWidth / 2, rect().bottom() - 5 - UBGeometryUtils::centimeterGraduationHeight - textHeight, textWidth, textHeight), Qt::AlignVCenter, text); } } diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index f58e6348..6713d1f9 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -59,6 +59,7 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + void paintGraduations(QPainter *painter); private: @@ -68,7 +69,6 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu // Helpers void fillBackground(QPainter *painter); - void paintGraduations(QPainter *painter); void paintRotationCenter(QPainter *painter); virtual void rotateAroundCenter(qreal angle); diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index db642f06..f53b7e96 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -297,12 +297,6 @@ QPainterPath UBGraphicsTriangle::shape() const void UBGraphicsTriangle::paintGraduations(QPainter *painter) { - const int centimeterGraduationHeight = 15; - const int halfCentimeterGraduationHeight = 10; - const int millimeterGraduationHeight = 5; - const int millimetersPerCentimeter = 10; - const int millimetersPerHalfCentimeter = 5; - qreal kx = (mOrientation == TopLeft || mOrientation == BottomLeft) ? 1 : -1; qreal ky = (mOrientation == BottomLeft || mOrientation == BottomRight) ? 1 : -1; @@ -312,10 +306,10 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) for (int millimeters = 0; millimeters < (rect().width() - sLeftEdgeMargin - sRoundingRadius) / sPixelsPerMillimeter; millimeters++) { int graduationX = rotationCenter().x() + kx * sPixelsPerMillimeter * millimeters; - int graduationHeight = (0 == millimeters % millimetersPerCentimeter) ? - centimeterGraduationHeight : - ((0 == millimeters % millimetersPerHalfCentimeter) ? - halfCentimeterGraduationHeight : millimeterGraduationHeight); + int graduationHeight = (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) ? + UBGeometryUtils::centimeterGraduationHeight : + ((0 == millimeters % UBGeometryUtils::millimetersPerHalfCentimeter) ? + UBGeometryUtils::halfCentimeterGraduationHeight : UBGeometryUtils::millimeterGraduationHeight); // Check that grad. line inside triangle qreal dx = (kx > 0) ? rect().width() - graduationX : graduationX - rect().x(); @@ -332,15 +326,15 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) } painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - ky * graduationHeight)); - if (0 == millimeters % millimetersPerCentimeter) + if (0 == millimeters % UBGeometryUtils::millimetersPerCentimeter) { - QString text = QString("%1").arg((int)(millimeters / millimetersPerCentimeter)); + QString text = QString("%1").arg((int)(millimeters / UBGeometryUtils::millimetersPerCentimeter)); int textXRight = graduationX + fontMetrics.width(text) / 2; qreal textWidth = fontMetrics.width(text); qreal textHeight = fontMetrics.tightBoundingRect(text).height() + 5; - int textY = (ky > 0) ? rotationCenter().y() - 5 - centimeterGraduationHeight - textHeight - : rotationCenter().y() + 5 + centimeterGraduationHeight; + int textY = (ky > 0) ? rotationCenter().y() - 5 - UBGeometryUtils::centimeterGraduationHeight - textHeight + : rotationCenter().y() + 5 + UBGeometryUtils::centimeterGraduationHeight; bool bText = false; switch(mOrientation) diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index b945b6b6..015cb604 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -118,6 +118,7 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + void paintGraduations(QPainter *painter); private: @@ -143,9 +144,6 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt static const QRect sDefaultRect; static const UBGraphicsTriangleOrientation sDefaultOrientation; - void paintGraduations(QPainter *painter); - - UBGraphicsTriangleOrientation mOrientation; QPointF A1, B1, C1, A2, B2, C2; // coordinates of points in ext and int triangles