From 02fde1464df7725a5af2878b5798c1d1cd9931b5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 24 Feb 2017 19:47:13 +0200 Subject: [PATCH] Fix infinite redrawing. --HG-- branch : feature --- src/libs/vtools/tools/vtoolseamallowance.cpp | 19 ++------- src/libs/vwidgets/vgrainlineitem.cpp | 41 +++++++++++++------- src/libs/vwidgets/vgrainlineitem.h | 3 +- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 7d70830db..e9f6e4375 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -767,22 +767,9 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) */ void VToolSeamAllowance::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (scene()->views().count() > 0) - { - const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); - const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); - - const QPoint p = pt - pt0; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - const qreal dScale = qSqrt(QPoint::dotProduct(p, p)); -#else - const qreal dScale = qSqrt(p.x() * p.x() + p.y() * p.y()); -#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - m_grainLine->SetScale(100/dScale); - } - - if (m_dataLabel->IsIdle() == false || m_patternInfo->IsIdle() == false || m_grainLine->IsIdle() == false) + if ((m_dataLabel->IsIdle() == false + || m_patternInfo->IsIdle() == false + || m_grainLine->IsIdle() == false) && not isSelected()) { setSelected(true); } diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index d1e92f9b9..9190d5976 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -104,8 +106,10 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->drawLine(pt1, pt2); pP->setBrush(clr); + QPolygonF poly; QPointF ptA; + m_dScale = GetScale(); qreal dArrLen = ARROW_LENGTH*m_dScale; if (m_eArrowType != ArrowType::atRear) { @@ -175,7 +179,6 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->drawArc(iX - iR, -iY, iR, iR, 90*16, -90*16); pP->restore(); } - } pP->restore(); } @@ -270,18 +273,6 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal return bInside; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VGrainlineItem::SetScale sets the scale for keeping the arrows of constant size - * @param dScale scale factor - */ -void VGrainlineItem::SetScale(qreal dScale) -{ - m_dScale = dScale; - UpdateRectangle(); - Update(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::mousePressEvent handles left button mouse press events @@ -547,3 +538,27 @@ QPointF VGrainlineItem::GetInsideCorner(int i, qreal dDist) const return m_polyBound.at(i) + pt1 + pt2; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetScale gets the scale for keeping the arrows of constant size + */ +qreal VGrainlineItem::GetScale() const +{ + if (scene()->views().count() > 0) + { + const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); + const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); + + const QPoint p = pt - pt0; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + const qreal dScale = qSqrt(QPoint::dotProduct(p, p)); +#else + const qreal dScale = qSqrt(p.x() * p.x() + p.y() * p.y()); +#endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) + return 100/dScale; + } + + return 1.0; +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index 4a0c445b2..bad83d687 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -43,7 +43,6 @@ public: void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength, ArrowType eAT); bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const; - void SetScale(qreal dScale); signals: void SignalResized(qreal dLength); @@ -75,6 +74,8 @@ private: QPointF m_ptCenter; qreal m_dAngle; ArrowType m_eArrowType; + + qreal GetScale() const; }; #endif // VGRAINLINEITEM_H