Fix infinite redrawing.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-24 19:47:13 +02:00
parent 449543f203
commit 02fde1464d
3 changed files with 33 additions and 30 deletions

View File

@ -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);
}

View File

@ -32,6 +32,8 @@
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <QDebug>
#include <QGraphicsScene>
#include <QGraphicsView>
#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;
}

View File

@ -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