--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-11 16:23:20 +02:00
commit f600a00db8
4 changed files with 44 additions and 39 deletions

View File

@ -247,32 +247,8 @@ void VToolSinglePoint::RefreshPointGeometry(const VPointF &point)
void VToolSinglePoint::RefreshLine(quint32 id) void VToolSinglePoint::RefreshLine(quint32 id)
{ {
Q_UNUSED(id) Q_UNUSED(id)
VAbstractTool::RefreshLine(this, namePoint, lineName, radius);
QRectF nRec = namePoint->sceneBoundingRect(); lineName->setPen(QPen(CorrectColor(Qt::black), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
nRec.translate(- scenePos());
if (this->rect().intersects(nRec) == false)
{
const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos()));
lineName->setPen(QPen(CorrectColor(Qt::black),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -279,17 +279,5 @@ void VNodePoint::RefreshPointGeometry(const VPointF &point)
*/ */
void VNodePoint::RefreshLine() void VNodePoint::RefreshLine()
{ {
QRectF nameRec = namePoint->sceneBoundingRect(); VAbstractTool::RefreshLine(this, namePoint, lineName, radius);
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2);
QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - scenePos()));
if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
} }

View File

@ -33,6 +33,7 @@
#include "../../vmisc/vsettings.h" #include "../../vmisc/vsettings.h"
#include "../undocommands/deltool.h" #include "../undocommands/deltool.h"
#include "../undocommands/savetooloptions.h" #include "../undocommands/savetooloptions.h"
#include "../vwidgets/vgraphicssimpletextitem.h"
#include <QGraphicsView> #include <QGraphicsView>
#include <QIcon> #include <QIcon>
@ -315,3 +316,39 @@ void VAbstractTool::AddRecord(const quint32 id, const Tool &toolType, VAbstractP
history->insert(index+1, record); history->insert(index+1, record);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RefreshLine refresh line to label on scene.
*/
void VAbstractTool::RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, QGraphicsLineItem *lineName,
const qreal radius)
{
SCASSERT(point != nullptr);
SCASSERT(namePoint != nullptr);
SCASSERT(lineName != nullptr);
QRectF nRec = namePoint->sceneBoundingRect();
nRec.translate(- point->scenePos());
if (point->rect().intersects(nRec) == false)
{
const QRectF nameRec = namePoint->sceneBoundingRect();
QPointF p1, p2;
VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - point->scenePos()), p1, p2);
const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(point->scenePos(), nameRec.center()));
lineName->setLine(QLineF(p1, pRec - point->scenePos()));
if (QLineF(p1, pRec - point->scenePos()).length() <= ToPixel(4, Unit::Mm))
{
lineName->setVisible(false);
}
else
{
lineName->setVisible(true);
}
}
else
{
lineName->setVisible(false);
}
}

View File

@ -43,6 +43,7 @@ class QGraphicsView;
class QGraphicsItem; class QGraphicsItem;
class QRectF; class QRectF;
class Visualization; class Visualization;
class VGraphicsSimpleTextItem;
/** /**
* @brief The VAbstractTool abstract class for all tools. * @brief The VAbstractTool abstract class for all tools.
@ -121,6 +122,9 @@ protected:
virtual void SetVisualization()=0; virtual void SetVisualization()=0;
void ToolCreation(const Source &typeCreation); void ToolCreation(const Source &typeCreation);
static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, QGraphicsLineItem *lineName,
const qreal radius);
private: private:
Q_DISABLE_COPY(VAbstractTool) Q_DISABLE_COPY(VAbstractTool)
}; };