diff --git a/src/tools/UBAbstractDrawRuler.cpp b/src/tools/UBAbstractDrawRuler.cpp index 03ec15f0..6b84c79d 100644 --- a/src/tools/UBAbstractDrawRuler.cpp +++ b/src/tools/UBAbstractDrawRuler.cpp @@ -18,6 +18,15 @@ const QColor UBAbstractDrawRuler::sDarkBackgroundMiddleFillColor = QColor(0xb5, const QColor UBAbstractDrawRuler::sDarkBackgroundEdgeFillColor = QColor(0xdd, 0xdd, 0xdd, sFillTransparency); const QColor UBAbstractDrawRuler::sDarkBackgroundDrawColor = QColor(0xff, 0xff, 0xff, sDrawTransparency); +const int UBAbstractDrawRuler::sLeftEdgeMargin = 10; +const int UBAbstractDrawRuler::sDegreeToQtAngleUnit = 16; +const int UBAbstractDrawRuler::sRotationRadius = 15; +const int UBAbstractDrawRuler::sPixelsPerMillimeter = 5; +const int UBAbstractDrawRuler::sFillTransparency = 127; +const int UBAbstractDrawRuler::sDrawTransparency = 192; +const int UBAbstractDrawRuler::sRoundingRadius = sLeftEdgeMargin / 2; + + UBAbstractDrawRuler::UBAbstractDrawRuler() : mShowButtons(false) , mAntiScaleRatio(1.0) diff --git a/src/tools/UBAbstractDrawRuler.h b/src/tools/UBAbstractDrawRuler.h index ed2d411c..7ed53fdd 100644 --- a/src/tools/UBAbstractDrawRuler.h +++ b/src/tools/UBAbstractDrawRuler.h @@ -56,13 +56,13 @@ protected: static const QColor sDarkBackgroundMiddleFillColor; static const QColor sDarkBackgroundDrawColor; - static const int sLeftEdgeMargin = 10; - static const int sDegreeToQtAngleUnit = 16; - static const int sRotationRadius = 15; - static const int sPixelsPerMillimeter = 5; - static const int sFillTransparency = 127; - static const int sDrawTransparency = 192; - static const int sRoundingRadius = sLeftEdgeMargin / 2; + static const int sLeftEdgeMargin; + static const int sDegreeToQtAngleUnit; + static const int sRotationRadius; + static const int sPixelsPerMillimeter; + static const int sFillTransparency; + static const int sDrawTransparency; + static const int sRoundingRadius; }; diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index dd3c2f1f..f54b9cf0 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -17,7 +17,7 @@ #include "core/memcheck.h" -const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96); +const QRect UBGraphicsRuler::sDefaultRect = QRect(0, 0, 800, 96); UBGraphicsRuler::UBGraphicsRuler() diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index 376c0230..f60cf9cf 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -20,6 +20,7 @@ UBGraphicsTriangle::UBGraphicsTriangle() , mResizing1(false) , mResizing2(false) , mRotating(false) + , angle(0) { setRect(sDefaultRect, sDefaultOrientation); @@ -89,7 +90,9 @@ void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientatio t.setMatrix(-1, 0, 0, 0, -1, 0, boundingRect().right(), boundingRect().bottom(), 1); break; } - setTransform(t, true); + + rotateAroundCenter(t); + setTransform(t); } UBGraphicsScene* UBGraphicsTriangle::scene() const @@ -203,7 +206,7 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) // Check that grad. line inside triangle qreal lineY = rect().bottom() - rect().height()/rect().width()*(rect().width() - graduationX); - if (lineY >= rotationCenter().y() + rect().height() - graduationHeight) + if (lineY >= rotationCenter().y() - graduationHeight) break; painter->drawLine(QLine(graduationX, rotationCenter().y(), graduationX, rotationCenter().y() - graduationHeight)); @@ -233,13 +236,20 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter) void UBGraphicsTriangle::rotateAroundCenter(qreal angle) { + this->angle = angle; QTransform transform; + rotateAroundCenter(transform); + setTransform(transform, true); +} + +void UBGraphicsTriangle::rotateAroundCenter(QTransform& transform) +{ transform.translate(rotationCenter().x(), rotationCenter().y()); transform.rotate(angle); transform.translate(- rotationCenter().x(), - rotationCenter().y()); - setTransform(transform, true); } + QPointF UBGraphicsTriangle::rotationCenter() const { return QPointF(rect().x() + sLeftEdgeMargin , rect().bottom()); diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index e74f2c06..69e9f436 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -92,6 +92,10 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt private: + QTransform calculateRotationTransform(); + qreal angle; + void rotateAroundCenter(QTransform& transform); + bool mResizing1; bool mResizing2; bool mRotating;