Refactoring.
--HG-- branch : develop
This commit is contained in:
parent
33ad980c91
commit
0dbd72be67
|
@ -111,6 +111,55 @@ qreal VisLine::FindLength(const QString &expression)
|
|||
return qApp->toPixel(length);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (lineItem != nullptr);
|
||||
|
||||
lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
|
||||
lineItem->setLine(line);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color)
|
||||
{
|
||||
SCASSERT (point != nullptr);
|
||||
|
||||
point->setPos(pos);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QLineF VisLine::Line(const QPointF &p1, const qreal &length, const qreal &angle)
|
||||
{
|
||||
QLineF line = QLineF();
|
||||
line.setP1(p1);
|
||||
line.setLength(length);
|
||||
line.setAngle(angle);
|
||||
return line;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *VisLine::InitPoint(const QColor &color)
|
||||
{
|
||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(this);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsLineItem *VisLine::InitLine(const QColor &color)
|
||||
{
|
||||
QGraphicsLineItem *line = new QGraphicsLineItem(this);
|
||||
line->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
line->setZValue(1);
|
||||
line->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
return line;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisLine::setMainColor(const QColor &value)
|
||||
{
|
||||
|
|
|
@ -64,6 +64,13 @@ protected:
|
|||
QString toolTip;
|
||||
QRectF PointRect();
|
||||
qreal FindLength(const QString &expression);
|
||||
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color);
|
||||
QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle);
|
||||
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &color);
|
||||
QGraphicsLineItem *InitLine(const QColor &color);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisLine)
|
||||
};
|
||||
|
|
|
@ -40,13 +40,7 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent
|
|||
|
||||
lineP1 = InitPoint(supportColor);
|
||||
lineP2 = InitPoint(supportColor);
|
||||
|
||||
line = new QGraphicsLineItem(this);
|
||||
line->setVisible(false);
|
||||
line->setPen(QPen(supportColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
line->setZValue(1);
|
||||
line->setFlags(QGraphicsItem::ItemStacksBehindParent);
|
||||
|
||||
line = InitLine(supportColor);
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
||||
|
@ -66,39 +60,6 @@ void VisToolAlongLine::setLength(const QString &expression)
|
|||
length = FindLength(expression);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QGraphicsEllipseItem *VisToolAlongLine::InitPoint(const QColor &color)
|
||||
{
|
||||
QGraphicsEllipseItem *point = new QGraphicsEllipseItem(this);
|
||||
point->setVisible(false);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
return point;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style)
|
||||
{
|
||||
SCASSERT (lineItem != nullptr);
|
||||
|
||||
lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style));
|
||||
lineItem->setLine(line);
|
||||
lineItem->setVisible(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color)
|
||||
{
|
||||
SCASSERT (point != nullptr);
|
||||
|
||||
point->setPos(pos);
|
||||
point->setVisible(true);
|
||||
point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolAlongLine::RefreshGeometry()
|
||||
{
|
||||
|
@ -121,11 +82,7 @@ void VisToolAlongLine::RefreshGeometry()
|
|||
|
||||
if (qFuzzyCompare(1 + length, 1 + 0) == false)
|
||||
{
|
||||
QLineF mainLine = QLineF();
|
||||
mainLine.setP1(first->toQPointF());
|
||||
mainLine.setAngle(line->line().angle());
|
||||
mainLine.setLength(length);
|
||||
|
||||
QLineF mainLine = Line(first->toQPointF(), length, line->line().angle());
|
||||
DrawLine(this, mainLine, mainColor, lineStyle);
|
||||
|
||||
DrawPoint(point, mainLine.p2(), mainColor);
|
||||
|
|
|
@ -51,10 +51,6 @@ private:
|
|||
QGraphicsEllipseItem *lineP2;
|
||||
QGraphicsLineItem *line;
|
||||
qreal length;
|
||||
QGraphicsEllipseItem *InitPoint(const QColor &mainColor);
|
||||
void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color,
|
||||
Qt::PenStyle style = Qt::SolidLine);
|
||||
void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color);
|
||||
};
|
||||
|
||||
#endif // VISTOOLALONGLINE_H
|
||||
|
|
|
@ -41,12 +41,7 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
|
|||
{
|
||||
this->mainColor = Qt::red;
|
||||
|
||||
point = new QGraphicsEllipseItem(this);
|
||||
point->setVisible(false);
|
||||
point->setZValue(1);
|
||||
point->setBrush(QBrush(Qt::NoBrush));
|
||||
point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
point->setRect(PointRect());
|
||||
point = InitPoint(mainColor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -57,42 +52,26 @@ VisToolEndLine::~VisToolEndLine()
|
|||
void VisToolEndLine::RefreshGeometry()
|
||||
{
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
QLineF line;
|
||||
if (qFuzzyCompare(1 + length, 1 + 0))
|
||||
{
|
||||
QGraphicsScene *sc = this->scene();
|
||||
QPointF second;
|
||||
if(sc == nullptr)
|
||||
if(this->scene() == nullptr)
|
||||
{
|
||||
second = scenePos;
|
||||
}
|
||||
else
|
||||
{
|
||||
line = QLineF(first->toQPointF(), scenePos);
|
||||
QRectF scRect = sc->sceneRect();
|
||||
qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2));
|
||||
line.setLength(diagonal);
|
||||
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
|
||||
{
|
||||
line.setAngle(CorrectAngle(line.angle()));
|
||||
}
|
||||
second = VAbstractTool::LineIntersectRect(scRect, line);
|
||||
second = CorrectRay(first->toQPointF());
|
||||
}
|
||||
line = QLineF(first->toQPointF(), second);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = QLineF();
|
||||
line.setP1(first->toQPointF());
|
||||
line.setLength(length);
|
||||
line.setAngle(angle);
|
||||
|
||||
point->setPos(line.p2());
|
||||
point->setVisible(true);
|
||||
point->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
||||
line = Line(first->toQPointF(), length, angle);
|
||||
DrawPoint(point, line.p2(), mainColor);
|
||||
}
|
||||
this->setLine(line);
|
||||
DrawLine(this, line, mainColor, lineStyle);
|
||||
toolTip = QString(tr("<b>Point at distance and angle</b>: angle = %1°; <b>Shift</b> - sticking angle, "
|
||||
"<b>Enter</b> - finish creation")).arg(this->line().angle());
|
||||
}
|
||||
|
@ -145,6 +124,19 @@ qreal VisToolEndLine::CorrectAngle(const qreal &angle) const
|
|||
}
|
||||
}
|
||||
|
||||
QPointF VisToolEndLine::CorrectRay(const QPointF &firstPoint) const
|
||||
{
|
||||
QLineF line = QLineF(firstPoint, scenePos);
|
||||
QRectF scRect = this->scene()->sceneRect();
|
||||
qreal diagonal = sqrt(pow(scRect.height(), 2) + pow(scRect.width(), 2));
|
||||
line.setLength(diagonal);
|
||||
if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier)
|
||||
{
|
||||
line.setAngle(CorrectAngle(line.angle()));
|
||||
}
|
||||
return VAbstractTool::LineIntersectRect(scRect, line);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolEndLine::setAngle(const qreal &value)
|
||||
{
|
||||
|
|
|
@ -47,10 +47,11 @@ public:
|
|||
void setLength(const QString &expression);
|
||||
private:
|
||||
Q_DISABLE_COPY(VisToolEndLine)
|
||||
qreal CorrectAngle(const qreal &angle) const;
|
||||
qreal length;
|
||||
qreal angle;
|
||||
QGraphicsEllipseItem *point;
|
||||
qreal CorrectAngle(const qreal &angle) const;
|
||||
QPointF CorrectRay(const QPointF &firstPoint) const;
|
||||
};
|
||||
|
||||
#endif // VISTOOLENDLINE_H
|
||||
|
|
|
@ -46,17 +46,18 @@ VisToolLine::~VisToolLine()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VisToolLine::RefreshGeometry()
|
||||
{
|
||||
QLineF line;
|
||||
const VPointF *first = data->GeometricObject<const VPointF *>(point1Id);
|
||||
if (point2Id == 0)
|
||||
{
|
||||
this->setLine(QLineF(first->toQPointF(), scenePos));
|
||||
line = QLineF(first->toQPointF(), scenePos);
|
||||
}
|
||||
else
|
||||
{
|
||||
const VPointF *second = data->GeometricObject<const VPointF *>(point2Id);
|
||||
this->setLine(QLineF(first->toQPointF(), second->toQPointF()));
|
||||
line = QLineF(first->toQPointF(), second->toQPointF());
|
||||
}
|
||||
this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle));
|
||||
DrawLine(this, line, mainColor, lineStyle);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user