From 8d0b2c0af9b325c1e4d0c2e3c4842e97e34edbb3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 23 Jun 2017 12:25:02 +0300 Subject: [PATCH] Fix a crash. Valentina crahed if create a curve. --HG-- branch : develop --- src/libs/vmisc/def.h | 2 + .../toollinepoint/vtoollinepoint.cpp | 32 ++++--- .../toollinepoint/vtoollinepoint.h | 5 +- .../toolsinglepoint/vtoolsinglepoint.cpp | 1 + .../vtools/tools/nodeDetails/vnodepoint.cpp | 4 +- .../line/operation/visoperation.cpp | 4 +- .../line/operation/visoperation.h | 8 +- .../line/operation/vistoolflippingbyaxis.cpp | 10 --- .../line/operation/vistoolflippingbyaxis.h | 5 +- .../line/operation/vistoolflippingbyline.cpp | 11 --- .../line/operation/vistoolflippingbyline.h | 8 +- .../line/operation/vistoolmove.cpp | 15 +--- .../line/operation/vistoolmove.h | 10 +-- .../line/operation/vistoolrotation.cpp | 16 +--- .../line/operation/vistoolrotation.h | 10 +-- .../vtools/visualization/line/visline.cpp | 20 +---- src/libs/vtools/visualization/line/visline.h | 9 +- .../visualization/line/vistoolalongline.cpp | 15 +--- .../visualization/line/vistoolalongline.h | 15 ++-- .../visualization/line/vistoolbisector.cpp | 19 +--- .../visualization/line/vistoolbisector.h | 21 ++--- .../line/vistoolcurveintersectaxis.cpp | 18 +--- .../line/vistoolcurveintersectaxis.h | 17 ++-- .../visualization/line/vistoolendline.cpp | 10 --- .../visualization/line/vistoolendline.h | 9 +- .../visualization/line/vistoolheight.cpp | 19 +--- .../vtools/visualization/line/vistoolheight.h | 15 ++-- .../vtools/visualization/line/vistoolline.cpp | 2 +- .../vtools/visualization/line/vistoolline.h | 2 +- .../line/vistoollineintersect.cpp | 17 +--- .../visualization/line/vistoollineintersect.h | 15 ++-- .../line/vistoollineintersectaxis.cpp | 22 +---- .../line/vistoollineintersectaxis.h | 17 ++-- .../visualization/line/vistoolnormal.cpp | 15 +--- .../vtools/visualization/line/vistoolnormal.h | 10 +-- .../line/vistoolpointfromarcandtangent.cpp | 15 +--- .../line/vistoolpointfromarcandtangent.h | 15 ++-- .../line/vistoolpointfromcircleandtangent.cpp | 18 +--- .../line/vistoolpointfromcircleandtangent.h | 19 ++-- .../line/vistoolpointofcontact.cpp | 16 +--- .../line/vistoolpointofcontact.h | 19 ++-- .../line/vistoolpointofintersection.cpp | 15 +--- .../line/vistoolpointofintersection.h | 11 +-- .../line/vistoolpointofintersectionarcs.cpp | 12 --- .../line/vistoolpointofintersectionarcs.h | 15 ++-- .../vistoolpointofintersectioncircles.cpp | 19 +--- .../line/vistoolpointofintersectioncircles.h | 21 ++--- .../line/vistoolshoulderpoint.cpp | 22 +---- .../visualization/line/vistoolshoulderpoint.h | 23 +++-- .../visualization/line/vistooltriangle.cpp | 25 +----- .../visualization/line/vistooltriangle.h | 27 +++--- .../visualization/line/vistooltruedarts.cpp | 29 +------ .../visualization/line/vistooltruedarts.h | 25 +++--- .../vtools/visualization/path/vispath.cpp | 16 ---- src/libs/vtools/visualization/path/vispath.h | 4 - .../vtools/visualization/path/vistoolarc.cpp | 11 +-- .../vtools/visualization/path/vistoolarc.h | 11 +-- .../path/vistoolarcwithlength.cpp | 10 --- .../visualization/path/vistoolarcwithlength.h | 11 +-- .../visualization/path/vistoolcubicbezier.cpp | 20 +---- .../visualization/path/vistoolcubicbezier.h | 21 ++--- .../path/vistoolcubicbezierpath.cpp | 54 +++--------- .../path/vistoolcubicbezierpath.h | 21 ++--- .../visualization/path/vistoolcutarc.cpp | 13 +-- .../vtools/visualization/path/vistoolcutarc.h | 11 +-- .../visualization/path/vistoolcutspline.cpp | 13 +-- .../visualization/path/vistoolcutspline.h | 11 +-- .../path/vistoolcutsplinepath.cpp | 12 --- .../visualization/path/vistoolcutsplinepath.h | 11 +-- .../path/vistoolellipticalarc.cpp | 10 --- .../visualization/path/vistoolellipticalarc.h | 15 ++-- .../visualization/path/vistoolpiece.cpp | 25 ++---- .../vtools/visualization/path/vistoolpiece.h | 11 +-- .../visualization/path/vistoolpiecepath.cpp | 18 +--- .../visualization/path/vistoolpiecepath.h | 5 +- .../path/vistoolpointofintersectioncurves.cpp | 11 --- .../path/vistoolpointofintersectioncurves.h | 14 ++- .../visualization/path/vistoolspline.cpp | 11 --- .../vtools/visualization/path/vistoolspline.h | 19 ++-- .../visualization/path/vistoolsplinepath.cpp | 25 ++---- .../visualization/path/vistoolsplinepath.h | 13 ++- .../vtools/visualization/visualization.cpp | 22 ++--- src/libs/vtools/visualization/visualization.h | 34 ++------ src/libs/vwidgets/scalesceneitems.cpp | 86 +++++++++++++++++++ src/libs/vwidgets/scalesceneitems.h | 73 ++++++++++++++++ src/libs/vwidgets/vcontrolpointspline.cpp | 23 ++--- src/libs/vwidgets/vcontrolpointspline.h | 9 +- src/libs/vwidgets/vcurvepathitem.cpp | 52 +++++++++++ src/libs/vwidgets/vcurvepathitem.h | 5 ++ src/libs/vwidgets/vscenepoint.cpp | 26 ++---- src/libs/vwidgets/vscenepoint.h | 14 ++- src/libs/vwidgets/vsimplecurve.cpp | 41 ++++----- src/libs/vwidgets/vsimplecurve.h | 4 +- src/libs/vwidgets/vwidgets.pri | 6 +- 94 files changed, 586 insertions(+), 1010 deletions(-) create mode 100644 src/libs/vwidgets/scalesceneitems.cpp create mode 100644 src/libs/vwidgets/scalesceneitems.h diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index ffc216724..c355225a1 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -165,6 +165,8 @@ enum class Vis : ToolVisHolderType { ControlPointSpline = static_cast(Tool::LAST_ONE_DO_NOT_USE), GraphicsSimpleTextItem, + ScaledLine, + ScaledEllipse, SimplePoint, SimpleCurve, Line, diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp index 2538bcf61..3f93d6a06 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp @@ -48,6 +48,7 @@ #include "../../../../vabstracttool.h" #include "../../../vdrawtool.h" #include "../vtoolsinglepoint.h" +#include "../vwidgets/scalesceneitems.h" template class QSharedPointer; @@ -74,7 +75,8 @@ VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const qu Q_ASSERT_X(basePointId != 0, Q_FUNC_INFO, "basePointId == 0"); //-V654 //-V712 QPointF point1 = static_cast(*data->GeometricObject(basePointId)); QPointF point2 = static_cast(*data->GeometricObject(id)); - mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); + mainLine = new VScaledLine(QLineF(point1 - point2, QPointF()), this); + mainLine->SetBasicWidth(widthHairLine); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -87,21 +89,15 @@ VToolLinePoint::~VToolLinePoint() //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - const qreal width = ScaleWidth(m_isHovered ? widthMainLine : widthHairLine, SceneScale(scene())); + QPen mPen = mainLine->pen(); + mPen.setColor(CorrectColor(this, lineColor)); + mPen.setStyle(LineStyleToPenStyle(m_lineType)); - mainLine->setPen(QPen(CorrectColor(this, lineColor), width, LineStyleToPenStyle(m_lineType))); + mainLine->setPen(mPen); VToolSinglePoint::paint(painter, option, widget); } -//--------------------------------------------------------------------------------------------------------------------- -QRectF VToolLinePoint::boundingRect() const -{ - QRectF recTool = VToolSinglePoint::boundingRect(); - recTool = recTool.united(childrenBoundingRect()); - return recTool; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -133,6 +129,20 @@ void VToolLinePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj doc->SetAttribute(tag, AttrLineColor, lineColor); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + mainLine->SetBasicWidth(widthMainLine); + VToolSinglePoint::hoverEnterEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + mainLine->SetBasicWidth(widthHairLine); + VToolSinglePoint::hoverLeaveEvent(event); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::Disable(bool disable, const QString &namePP) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h index e195eb864..f0a12fcf4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h @@ -58,7 +58,6 @@ public: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) Q_DECL_OVERRIDE; - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; VFormula GetFormulaLength() const; void SetFormulaLength(const VFormula &value); @@ -88,7 +87,7 @@ protected: quint32 basePointId; /** @brief mainLine line item. */ - QGraphicsLineItem *mainLine; + VScaledLine *mainLine; /** @brief lineColor color of a line. */ QString lineColor; @@ -96,6 +95,8 @@ protected: virtual void RefreshGeometry(); virtual void RemoveReferens() Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolLinePoint) }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 05caecd7a..e9bb4a938 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -55,6 +55,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vgraphicssimpletextitem.h" +#include "../vwidgets/scalesceneitems.h" #include "../../../vabstracttool.h" #include "../../vdrawtool.h" #include "../vabstractpoint.h" diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 8ac1931f7..31b0865c2 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -201,7 +201,7 @@ void VNodePoint::RefreshDataInFile() void VNodePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event - QGraphicsEllipseItem::mousePressEvent(event); + VScenePoint::mousePressEvent(event); // Somehow clicking on notselectable object do not clean previous selections. if (not (flags() & ItemIsSelectable) && scene()) @@ -223,7 +223,7 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { emit ChoosedTool(id, SceneObject::Point); } - QGraphicsEllipseItem::mouseReleaseEvent(event); + VScenePoint::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index 6887bae6c..7d5e810eb 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -75,7 +75,7 @@ void VisOperation::VisualMode(const quint32 &pointId) } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) +VScaledEllipse *VisOperation::GetPoint(quint32 i, const QColor &color) { return GetPointItem(points, i, color, this); } @@ -118,7 +118,7 @@ void VisOperation::RefreshFlippedObjects(const QPointF &firstPoint, const QPoint const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; - QGraphicsEllipseItem *point = GetPoint(static_cast(iPoint), supportColor2); + VScaledEllipse *point = GetPoint(static_cast(iPoint), supportColor2); DrawPoint(point, static_cast(*p), supportColor2); ++iPoint; diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h index 79d1769a1..d13ae01b7 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.h +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -50,11 +50,11 @@ protected: QVector objects; QColor supportColor2; - QVector points; - QVector curves; + QVector points; + QVector curves; - QGraphicsEllipseItem * GetPoint(quint32 i, const QColor &color); - VCurvePathItem * GetCurve(quint32 i, const QColor &color); + VScaledEllipse *GetPoint(quint32 i, const QColor &color); + VCurvePathItem *GetCurve(quint32 i, const QColor &color); template int AddFlippedCurve(const QPointF &firstPoint, const QPointF &secondPoint, quint32 id, int i); diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp index 042ec08f2..4a74646a3 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp @@ -80,13 +80,3 @@ void VisToolFlippingByAxis::SetAxisType(AxisType value) { m_axisType = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolFlippingByAxis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point1, scale); - - VisOperation::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h index 2cede15c6..8e8f1326b 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h @@ -48,15 +48,12 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolFlippingByAxis)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolFlippingByAxis) AxisType m_axisType; - QGraphicsEllipseItem *point1; + VScaledEllipse *point1; }; #endif // VISTOOLFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp index 8f8f1de28..2a189f3f1 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -72,17 +72,6 @@ void VisToolFlippingByLine::RefreshGeometry() RefreshFlippedObjects(firstPoint, secondPoint); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolFlippingByLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point1, scale); - ScalePoint(point2, scale); - - VisOperation::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolFlippingByLine::SetFirstLinePointId(quint32 value) { diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h index 1a0fd251f..1bf6c915b 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -41,8 +41,6 @@ public: virtual ~VisToolFlippingByLine() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; void SetFirstLinePointId(quint32 value); void SetSecondLinePointId(quint32 value); @@ -51,9 +49,9 @@ public: enum { Type = UserType + static_cast(Vis::ToolFlippingByLine)}; private: Q_DISABLE_COPY(VisToolFlippingByLine) - quint32 object2Id; - QGraphicsEllipseItem *point1; - QGraphicsEllipseItem *point2; + quint32 object2Id; + VScaledEllipse *point1; + VScaledEllipse *point2; }; #endif // VISTOOLFLIPPINGBYLINE_H diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp index 5babe5d44..79210ddbb 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -128,17 +128,6 @@ void VisToolMove::RefreshGeometry() CreateMovedObjects(iPoint, iCurve, tempLength, tempAngle); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolMove::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(pointOrigin, scale); - ScalePoint(pointFinish, scale); - - VisOperation::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- QString VisToolMove::Angle() const { @@ -244,7 +233,7 @@ QVector VisToolMove::CreateOriginObjects(int &iPoint, int &iCur const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; - QGraphicsEllipseItem *point = GetPoint(static_cast(iPoint), supportColor2); + VScaledEllipse *point = GetPoint(static_cast(iPoint), supportColor2); DrawPoint(point, static_cast(*p), supportColor2); originObjects.append(point); @@ -299,7 +288,7 @@ void VisToolMove::CreateMovedObjects(int &iPoint, int &iCurve, qreal length, qre const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; - QGraphicsEllipseItem *point = GetPoint(static_cast(iPoint), supportColor); + VScaledEllipse *point = GetPoint(static_cast(iPoint), supportColor); DrawPoint(point, static_cast(p->Move(length, angle)), supportColor); break; } diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.h b/src/libs/vtools/visualization/line/operation/vistoolmove.h index bf1ae9a53..339b0ca1d 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.h +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.h @@ -51,8 +51,6 @@ public: virtual ~VisToolMove(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; QString Angle() const; void SetAngle(const QString &expression); @@ -65,10 +63,10 @@ public: enum { Type = UserType + static_cast(Vis::ToolMove)}; private: Q_DISABLE_COPY(VisToolMove) - qreal angle; - qreal length; - QGraphicsEllipseItem *pointOrigin; - QGraphicsEllipseItem *pointFinish; + qreal angle; + qreal length; + VScaledEllipse *pointOrigin; + VScaledEllipse *pointFinish; template QGraphicsPathItem *AddOriginCurve(quint32 id, int &i); diff --git a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 88f962807..971e351bb 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -65,7 +65,7 @@ VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) { point = InitPoint(supportColor2, this); angleArc = InitItem(supportColor2, this); - xAxis = InitItem(supportColor2, this); + xAxis = InitItem(supportColor2, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -140,7 +140,7 @@ void VisToolRotation::RefreshGeometry() const QSharedPointer p = Visualization::data->GeometricObject(id); ++iPoint; - QGraphicsEllipseItem *point = GetPoint(static_cast(iPoint), supportColor2); + VScaledEllipse *point = GetPoint(static_cast(iPoint), supportColor2); DrawPoint(point, static_cast(*p), supportColor2); ++iPoint; @@ -190,18 +190,6 @@ void VisToolRotation::RefreshGeometry() } QT_WARNING_POP -//--------------------------------------------------------------------------------------------------------------------- -void VisToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(angleArc, scale); - ScalePenWidth(xAxis, scale); - - VisOperation::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolRotation::SetOriginPointId(quint32 value) { diff --git a/src/libs/vtools/visualization/line/operation/vistoolrotation.h b/src/libs/vtools/visualization/line/operation/vistoolrotation.h index cdbd9a9e5..5689f2c78 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.h +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.h @@ -51,8 +51,6 @@ public: virtual ~VisToolRotation(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; void SetOriginPointId(quint32 value); @@ -63,10 +61,10 @@ public: enum { Type = UserType + static_cast(Vis::ToolRotation)}; private: Q_DISABLE_COPY(VisToolRotation) - qreal angle; - QGraphicsEllipseItem *point; - VCurvePathItem *angleArc; - QGraphicsLineItem *xAxis; + qreal angle; + VScaledEllipse *point; + VCurvePathItem *angleArc; + VScaledLine *xAxis; template int AddCurve(qreal angle, const QPointF &origin, quint32 id, int i); diff --git a/src/libs/vtools/visualization/line/visline.cpp b/src/libs/vtools/visualization/line/visline.cpp index a5c9b9b11..22f21a509 100644 --- a/src/libs/vtools/visualization/line/visline.cpp +++ b/src/libs/vtools/visualization/line/visline.cpp @@ -41,7 +41,7 @@ //--------------------------------------------------------------------------------------------------------------------- VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) - :Visualization(data), QGraphicsLineItem(parent) + :Visualization(data), VScaledLine(parent) { this->setZValue(1);// Show on top real tool InitPen(); @@ -78,22 +78,6 @@ qreal VisLine::CorrectAngle(const qreal &angle) } } -//--------------------------------------------------------------------------------------------------------------------- -void VisLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - ScalePenWidth(this, SceneScale(scene())); - - QGraphicsLineItem::paint(painter, option, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -QRectF VisLine::boundingRect() const -{ - QRectF recTool = QGraphicsLineItem::boundingRect(); - recTool = recTool.united(childrenBoundingRect()); - return recTool; -} - //--------------------------------------------------------------------------------------------------------------------- QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const { @@ -164,7 +148,7 @@ void VisLine::AddOnScene() } //--------------------------------------------------------------------------------------------------------------------- -void VisLine::DrawRay(QGraphicsLineItem *lineItem, const QPointF &p, const QPointF &pTangent, const QColor &color, +void VisLine::DrawRay(VScaledLine *lineItem, const QPointF &p, const QPointF &pTangent, const QColor &color, Qt::PenStyle style) { SCASSERT (lineItem != nullptr) diff --git a/src/libs/vtools/visualization/line/visline.h b/src/libs/vtools/visualization/line/visline.h index 3419be329..5a15d90ab 100644 --- a/src/libs/vtools/visualization/line/visline.h +++ b/src/libs/vtools/visualization/line/visline.h @@ -43,8 +43,9 @@ #include "../vtools/visualization/visualization.h" #include "../vmisc/def.h" +#include "../vwidgets/scalesceneitems.h" -class VisLine: public Visualization, public QGraphicsLineItem +class VisLine: public Visualization, public VScaledLine { Q_OBJECT public: @@ -54,10 +55,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::Line)}; static qreal CorrectAngle(const qreal &angle); - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; protected: QPointF Ray(const QPointF &firstPoint, const qreal &angle) const; QPointF Ray(const QPointF &firstPoint) const; @@ -66,7 +63,7 @@ protected: virtual void InitPen() Q_DECL_OVERRIDE; virtual void AddOnScene() Q_DECL_OVERRIDE; - void DrawRay(QGraphicsLineItem *lineItem, const QPointF &p, const QPointF &pTangent, + void DrawRay(VScaledLine *lineItem, const QPointF &p, const QPointF &pTangent, const QColor &color, Qt::PenStyle style); private: Q_DISABLE_COPY(VisLine) diff --git a/src/libs/vtools/visualization/line/vistoolalongline.cpp b/src/libs/vtools/visualization/line/vistoolalongline.cpp index d79602bfa..eeb3e72b1 100644 --- a/src/libs/vtools/visualization/line/vistoolalongline.cpp +++ b/src/libs/vtools/visualization/line/vistoolalongline.cpp @@ -53,7 +53,7 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent lineP1 = InitPoint(supportColor, this); lineP2 = InitPoint(supportColor, this); //-V656 - line = InitItem(supportColor, this); + line = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -69,19 +69,6 @@ void VisToolAlongLine::setLength(const QString &expression) length = FindLength(expression, Visualization::data->PlainVariables()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolAlongLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(lineP1, scale); - ScalePoint(lineP2, scale); - ScalePenWidth(line, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolAlongLine::RefreshGeometry() { diff --git a/src/libs/vtools/visualization/line/vistoolalongline.h b/src/libs/vtools/visualization/line/vistoolalongline.h index 70f20a327..2b3ad1c20 100644 --- a/src/libs/vtools/visualization/line/vistoolalongline.h +++ b/src/libs/vtools/visualization/line/vistoolalongline.h @@ -51,17 +51,14 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolAlongLine)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolAlongLine) - quint32 object2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP2; - QGraphicsLineItem *line; - qreal length; + quint32 object2Id; + VScaledEllipse *point; + VScaledEllipse *lineP1; + VScaledEllipse *lineP2; + VScaledLine *line; + qreal length; }; #endif // VISTOOLALONGLINE_H diff --git a/src/libs/vtools/visualization/line/vistoolbisector.cpp b/src/libs/vtools/visualization/line/vistoolbisector.cpp index 6965c3910..6d12d3366 100644 --- a/src/libs/vtools/visualization/line/vistoolbisector.cpp +++ b/src/libs/vtools/visualization/line/vistoolbisector.cpp @@ -49,10 +49,10 @@ VisToolBisector::VisToolBisector(const VContainer *data, QGraphicsItem *parent) { line1P1 = InitPoint(supportColor, this); line1P2 = InitPoint(supportColor, this); //-V656 - line1 = InitItem(supportColor, this); + line1 = InitItem(supportColor, this); line2P2 = InitPoint(supportColor, this); - line2 = InitItem(supportColor, this); + line2 = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -75,21 +75,6 @@ void VisToolBisector::setLength(const QString &expression) length = FindLength(expression, Visualization::data->PlainVariables()); } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolBisector::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(line1P1, scale); - ScalePoint(line1P2, scale); - ScalePenWidth(line1, scale); - ScalePoint(line2P2, scale); - ScalePenWidth(line2, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolBisector::RefreshGeometry() { diff --git a/src/libs/vtools/visualization/line/vistoolbisector.h b/src/libs/vtools/visualization/line/vistoolbisector.h index c81c45977..2f0393c10 100644 --- a/src/libs/vtools/visualization/line/vistoolbisector.h +++ b/src/libs/vtools/visualization/line/vistoolbisector.h @@ -52,20 +52,17 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolBisector)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolBisector) - quint32 object2Id; - quint32 object3Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *line1P1; - QGraphicsEllipseItem *line1P2; - QGraphicsLineItem *line1; - QGraphicsEllipseItem *line2P2; - QGraphicsLineItem *line2; - qreal length; + quint32 object2Id; + quint32 object3Id; + VScaledEllipse *point; + VScaledEllipse *line1P1; + VScaledEllipse *line1P2; + VScaledLine *line1; + VScaledEllipse *line2P2; + VScaledLine *line2; + qreal length; }; #endif // VISTOOLBISECTOR_H diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp index ca3d86be7..41a194439 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp @@ -55,8 +55,8 @@ VisToolCurveIntersectAxis::VisToolCurveIntersectAxis(const VContainer *data, QGr visCurve = InitItem(Qt::darkGreen, this); basePoint = InitPoint(supportColor, this); - baseLine = InitItem(supportColor, this); - axisLine = InitItem(supportColor, this); //-V656 + baseLine = InitItem(supportColor, this); + axisLine = InitItem(supportColor, this); //-V656 point = InitPoint(mainColor, this); } @@ -113,17 +113,3 @@ void VisToolCurveIntersectAxis::setAxisPointId(const quint32 &value) { axisPointId = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolCurveIntersectAxis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(basePoint, scale); - ScalePenWidth(baseLine, scale); - ScalePenWidth(axisLine, scale); - ScalePenWidth(visCurve, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h index 66ec7905d..7413492c6 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h @@ -54,18 +54,15 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolLineIntersectAxis)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolCurveIntersectAxis) - quint32 axisPointId; - qreal angle; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *basePoint; - QGraphicsLineItem *baseLine; - QGraphicsLineItem *axisLine; - VCurvePathItem *visCurve; + quint32 axisPointId; + qreal angle; + VScaledEllipse *point; + VScaledEllipse *basePoint; + VScaledLine *baseLine; + VScaledLine *axisLine; + VCurvePathItem *visCurve; }; #endif // VISTOOLCURVEINTERSECTAXIS_H diff --git a/src/libs/vtools/visualization/line/vistoolendline.cpp b/src/libs/vtools/visualization/line/vistoolendline.cpp index 36d89799f..2c0722d03 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.cpp +++ b/src/libs/vtools/visualization/line/vistoolendline.cpp @@ -110,13 +110,3 @@ void VisToolEndLine::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolEndLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolendline.h b/src/libs/vtools/visualization/line/vistoolendline.h index 5e7864638..28bfd4f00 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.h +++ b/src/libs/vtools/visualization/line/vistoolendline.h @@ -56,14 +56,11 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolEndLine)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolEndLine) - qreal length; - qreal angle; - QGraphicsEllipseItem *point; + qreal length; + qreal angle; + VScaledEllipse *point; }; #endif // VISTOOLENDLINE_H diff --git a/src/libs/vtools/visualization/line/vistoolheight.cpp b/src/libs/vtools/visualization/line/vistoolheight.cpp index 9fdf028c9..63306cc2b 100644 --- a/src/libs/vtools/visualization/line/vistoolheight.cpp +++ b/src/libs/vtools/visualization/line/vistoolheight.cpp @@ -50,8 +50,8 @@ VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent) base_point = InitPoint(supportColor, this); lineP1 = InitPoint(supportColor, this); lineP2 = InitPoint(supportColor, this); - line = InitItem(supportColor, this); - line_intersection = InitItem(supportColor, this); //-V656 + line = InitItem(supportColor, this); + line_intersection = InitItem(supportColor, this); //-V656 point = InitPoint(mainColor, this); } @@ -112,21 +112,6 @@ void VisToolHeight::setLineP2Id(const quint32 &value) lineP2Id = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolHeight::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(base_point, scale); - ScalePoint(lineP1, scale); - ScalePoint(lineP2, scale); - ScalePenWidth(line, scale); - ScalePenWidth(line_intersection, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolHeight::ShowIntersection(const QLineF &height_line, const QLineF &base_line) { diff --git a/src/libs/vtools/visualization/line/vistoolheight.h b/src/libs/vtools/visualization/line/vistoolheight.h index 17c44a510..befba7477 100644 --- a/src/libs/vtools/visualization/line/vistoolheight.h +++ b/src/libs/vtools/visualization/line/vistoolheight.h @@ -53,20 +53,17 @@ public: void setLineP2Id(const quint32 &value); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolHeight)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolHeight) //base point in parent class quint32 lineP1Id;//first point of line quint32 lineP2Id;//second point of line - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *base_point; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP2; - QGraphicsLineItem *line; - QGraphicsLineItem *line_intersection; + VScaledEllipse *point; + VScaledEllipse *base_point; + VScaledEllipse *lineP1; + VScaledEllipse *lineP2; + VScaledLine *line; + VScaledLine *line_intersection; void ShowIntersection(const QLineF &height_line, const QLineF &base_line); }; diff --git a/src/libs/vtools/visualization/line/vistoolline.cpp b/src/libs/vtools/visualization/line/vistoolline.cpp index a591061af..c37b7a4b0 100644 --- a/src/libs/vtools/visualization/line/vistoolline.cpp +++ b/src/libs/vtools/visualization/line/vistoolline.cpp @@ -72,7 +72,7 @@ void VisToolLine::setPoint2Id(const quint32 &value) } //--------------------------------------------------------------------------------------------------------------------- -void VisToolLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style) +void VisToolLine::DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style) { SCASSERT (lineItem != nullptr) diff --git a/src/libs/vtools/visualization/line/vistoolline.h b/src/libs/vtools/visualization/line/vistoolline.h index 5ca5f8d92..e5a73cd34 100644 --- a/src/libs/vtools/visualization/line/vistoolline.h +++ b/src/libs/vtools/visualization/line/vistoolline.h @@ -54,7 +54,7 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolLine)}; protected: - virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, + virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style = Qt::SolidLine) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolLine) diff --git a/src/libs/vtools/visualization/line/vistoollineintersect.cpp b/src/libs/vtools/visualization/line/vistoollineintersect.cpp index 158062f33..cf59b933d 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersect.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersect.cpp @@ -48,7 +48,7 @@ VisToolLineIntersect::VisToolLineIntersect(const VContainer *data, QGraphicsItem { line1P1 = InitPoint(supportColor, this); line1P2 = InitPoint(supportColor, this); - line1 = InitItem(supportColor, this); + line1 = InitItem(supportColor, this); line2P1 = InitPoint(supportColor, this); line2P2 = InitPoint(supportColor, this); @@ -135,18 +135,3 @@ void VisToolLineIntersect::setLine2P2Id(const quint32 &value) { line2P2Id = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolLineIntersect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(line1P1, scale); - ScalePoint(line1P2, scale); - ScalePenWidth(line1, scale); - ScalePoint(line2P1, scale); - ScalePoint(line2P2, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoollineintersect.h b/src/libs/vtools/visualization/line/vistoollineintersect.h index 253dec5a7..8da03904f 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersect.h +++ b/src/libs/vtools/visualization/line/vistoollineintersect.h @@ -53,20 +53,17 @@ public: void setLine2P2Id(const quint32 &value); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolLineIntersect)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolLineIntersect) quint32 line1P2Id; quint32 line2P1Id; quint32 line2P2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *line1P1; - QGraphicsEllipseItem *line1P2; - QGraphicsLineItem *line1; - QGraphicsEllipseItem *line2P1; - QGraphicsEllipseItem *line2P2; + VScaledEllipse *point; + VScaledEllipse *line1P1; + VScaledEllipse *line1P2; + VScaledLine *line1; + VScaledEllipse *line2P1; + VScaledEllipse *line2P2; }; #endif // VISTOOLLINEINTERSECT_H diff --git a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp index 9b60b2267..01e2b451f 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp @@ -53,9 +53,9 @@ VisToolLineIntersectAxis::VisToolLineIntersectAxis(const VContainer *data, QGrap lineP1 = InitPoint(supportColor, this); lineP2 = InitPoint(supportColor, this); basePoint = InitPoint(supportColor, this); - baseLine = InitItem(supportColor, this); - axisLine = InitItem(supportColor, this); - line_intersection = InitItem(supportColor, this); + baseLine = InitItem(supportColor, this); + axisLine = InitItem(supportColor, this); + line_intersection = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -133,22 +133,6 @@ void VisToolLineIntersectAxis::setAxisPointId(const quint32 &value) axisPointId = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolLineIntersectAxis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(lineP1, scale); - ScalePoint(lineP2, scale); - ScalePoint(basePoint, scale); - ScalePenWidth(baseLine, scale); - ScalePenWidth(axisLine, scale); - ScalePenWidth(line_intersection, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolLineIntersectAxis::ShowIntersection(const QLineF &axis_line, const QLineF &base_line) { diff --git a/src/libs/vtools/visualization/line/vistoollineintersectaxis.h b/src/libs/vtools/visualization/line/vistoollineintersectaxis.h index 8538e3de0..5c79adf1a 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.h +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.h @@ -56,21 +56,18 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolLineIntersectAxis)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolLineIntersectAxis) quint32 point2Id; quint32 axisPointId; qreal angle; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP2; - QGraphicsEllipseItem *basePoint; - QGraphicsLineItem *baseLine; - QGraphicsLineItem *axisLine; - QGraphicsLineItem *line_intersection; + VScaledEllipse *point; + VScaledEllipse *lineP1; + VScaledEllipse *lineP2; + VScaledEllipse *basePoint; + VScaledLine *baseLine; + VScaledLine *axisLine; + VScaledLine *line_intersection; void ShowIntersection(const QLineF &axis_line, const QLineF &base_line); }; diff --git a/src/libs/vtools/visualization/line/vistoolnormal.cpp b/src/libs/vtools/visualization/line/vistoolnormal.cpp index b49587342..4efa76db3 100644 --- a/src/libs/vtools/visualization/line/vistoolnormal.cpp +++ b/src/libs/vtools/visualization/line/vistoolnormal.cpp @@ -52,7 +52,7 @@ VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent) lineP1 = InitPoint(supportColor, this); lineP2 = InitPoint(supportColor, this); //-V656 - line = InitItem(supportColor, this); + line = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -124,16 +124,3 @@ void VisToolNormal::SetAngle(const qreal &value) { angle = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolNormal::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(lineP1, scale); - ScalePoint(lineP2, scale); - ScalePenWidth(line, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolnormal.h b/src/libs/vtools/visualization/line/vistoolnormal.h index 56b31b2a0..1d22649da 100644 --- a/src/libs/vtools/visualization/line/vistoolnormal.h +++ b/src/libs/vtools/visualization/line/vistoolnormal.h @@ -55,15 +55,13 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolNormal)}; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolNormal) quint32 object2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP2; - QGraphicsLineItem *line; + VScaledEllipse *point; + VScaledEllipse *lineP1; + VScaledEllipse *lineP2; + VScaledLine *line; qreal length; qreal angle; diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp index 546d9ed2d..4e19cd387 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp @@ -54,7 +54,7 @@ VisToolPointFromArcAndTangent::VisToolPointFromArcAndTangent(const VContainer *d arcPath = InitItem(Qt::darkGreen, this); point = InitPoint(mainColor, this); tangent = InitPoint(supportColor, this); - tangentLine2 = InitItem(supportColor, this); + tangentLine2 = InitItem(supportColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,19 +91,6 @@ void VisToolPointFromArcAndTangent::setCrossPoint(const CrossCirclesPoint &value crossPoint = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointFromArcAndTangent::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(tangent, scale); - ScalePenWidth(arcPath, scale); - ScalePenWidth(tangentLine2, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointFromArcAndTangent::FindRays(const QPointF &p, const VArc *arc) { diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h index 43d4bddf5..afd5801df 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h @@ -55,17 +55,14 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointFromArcAndTangent)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointFromArcAndTangent) - quint32 arcId; - CrossCirclesPoint crossPoint; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *tangent; - VCurvePathItem *arcPath; - QGraphicsLineItem *tangentLine2; + quint32 arcId; + CrossCirclesPoint crossPoint; + VScaledEllipse *point; + VScaledEllipse *tangent; + VCurvePathItem *arcPath; + VScaledLine *tangentLine2; void FindRays(const QPointF &p, const VArc *arc); }; diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp index 6288cb452..c44834439 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp @@ -47,11 +47,11 @@ VisToolPointFromCircleAndTangent::VisToolPointFromCircleAndTangent(const VContai : VisLine(data, parent), object2Id(NULL_ID), cRadius(0), crossPoint(CrossCirclesPoint::FirstPoint), point(nullptr), tangent(nullptr), cCenter(nullptr), cPath(nullptr), tangent2(nullptr) { - cPath = InitItem(Qt::darkGreen, this); + cPath = InitItem(Qt::darkGreen, this); point = InitPoint(mainColor, this); tangent = InitPoint(supportColor, this); cCenter = InitPoint(supportColor, this); //-V656 - tangent2 = InitItem(supportColor, this); + tangent2 = InitItem(supportColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -101,20 +101,6 @@ void VisToolPointFromCircleAndTangent::setCrossPoint(const CrossCirclesPoint &va crossPoint = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointFromCircleAndTangent::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(tangent, scale); - ScalePoint(cCenter, scale); - ScalePoint(cPath, scale); - ScalePenWidth(tangent2, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointFromCircleAndTangent::FindRays(const QPointF &p, const QPointF ¢er, qreal radius) { diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h index e52acaea0..de60969c2 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h @@ -56,19 +56,16 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointFromCircleAndTangent)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointFromCircleAndTangent) - quint32 object2Id; - qreal cRadius; - CrossCirclesPoint crossPoint; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *tangent; - QGraphicsEllipseItem *cCenter; - QGraphicsEllipseItem *cPath; - QGraphicsLineItem *tangent2; + quint32 object2Id; + qreal cRadius; + CrossCirclesPoint crossPoint; + VScaledEllipse *point; + VScaledEllipse *tangent; + VScaledEllipse *cCenter; + VScaledEllipse *cPath; + VScaledLine *tangent2; void FindRays(const QPointF &p, const QPointF ¢er, qreal radius); }; diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp index 0cf39427f..5190f2e06 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp @@ -50,7 +50,7 @@ VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsIt arc_point = InitPoint(supportColor, this); lineP1 = InitPoint(supportColor, this); lineP2 = InitPoint(supportColor, this); - circle = InitItem(supportColor, this); + circle = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -114,17 +114,3 @@ void VisToolPointOfContact::setRadius(const QString &expression) { radius = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointOfContact::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(lineP1, scale); - ScalePoint(lineP2, scale); - ScalePoint(arc_point, scale); - ScalePoint(circle, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.h b/src/libs/vtools/visualization/line/vistoolpointofcontact.h index 30c733b9e..367efe5b4 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.h +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.h @@ -52,19 +52,16 @@ public: void setRadius(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointOfContact)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfContact) - quint32 lineP2Id; - quint32 radiusId; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *lineP1; - QGraphicsEllipseItem *lineP2; - QGraphicsEllipseItem *arc_point; - QGraphicsEllipseItem *circle; - qreal radius; + quint32 lineP2Id; + quint32 radiusId; + VScaledEllipse *point; + VScaledEllipse *lineP1; + VScaledEllipse *lineP2; + VScaledEllipse *arc_point; + VScaledEllipse *circle; + qreal radius; }; diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp index 4a07af911..23d2fd07f 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp @@ -48,7 +48,7 @@ VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, Q { axisP1 = InitPoint(supportColor, this); axisP2 = InitPoint(supportColor, this); //-V656 - axis2 = InitItem(supportColor, this); + axis2 = InitItem(supportColor, this); point = InitPoint(mainColor, this); } @@ -93,19 +93,6 @@ void VisToolPointOfIntersection::setPoint2Id(const quint32 &value) point2Id = value; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointOfIntersection::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(axisP1, scale); - ScalePoint(axisP2, scale); - ScalePenWidth(axis2, scale); - - VisLine::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersection::ShowIntersection(const QLineF &axis1, const QLineF &axis2, const QColor &color) { diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersection.h b/src/libs/vtools/visualization/line/vistoolpointofintersection.h index f6a215b7c..dfaaf7125 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersection.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersection.h @@ -53,16 +53,13 @@ public: void setPoint2Id(const quint32 &value); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointOfIntersection)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersection) quint32 point2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *axisP1;//axis1 is class themself - QGraphicsEllipseItem *axisP2; - QGraphicsLineItem *axis2;//axis1 is class themself + VScaledEllipse *point; + VScaledEllipse *axisP1;//axis1 is class themself + VScaledEllipse *axisP2; + VScaledLine *axis2;//axis1 is class themself void ShowIntersection(const QLineF &axis1, const QLineF &axis2, const QColor &color); }; diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp index 93c4ab411..1ad0fce0f 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp @@ -114,15 +114,3 @@ void VisToolPointOfIntersectionArcs::setCrossPoint(const CrossCirclesPoint &valu { crossPoint = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointOfIntersectionArcs::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(arc1Path, scale); - ScalePenWidth(arc2Path, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h index 5b0a9f92d..b8e9abb96 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h @@ -56,17 +56,14 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointOfIntersectionArcs)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionArcs) - quint32 arc1Id; - quint32 arc2Id; - CrossCirclesPoint crossPoint; - QGraphicsEllipseItem *point; - VCurvePathItem *arc1Path; - VCurvePathItem *arc2Path; + quint32 arc1Id; + quint32 arc2Id; + CrossCirclesPoint crossPoint; + VScaledEllipse *point; + VCurvePathItem *arc1Path; + VCurvePathItem *arc2Path; }; #endif // VISTOOLPOINTOFINTERSECTIONARCS_H diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp index 08cb94a3c..43db7d61a 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp @@ -52,8 +52,8 @@ VisToolPointOfIntersectionCircles::VisToolPointOfIntersectionCircles(const VCont { this->setPen(QPen(Qt::NoPen)); // don't use parent this time - c1Path = InitItem(Qt::darkGreen, this); - c2Path = InitItem(Qt::darkRed, this); + c1Path = InitItem(Qt::darkGreen, this); + c2Path = InitItem(Qt::darkRed, this); point = InitPoint(mainColor, this); c1Center = InitPoint(supportColor, this); c2Center = InitPoint(supportColor, this); //-V656 @@ -125,18 +125,3 @@ void VisToolPointOfIntersectionCircles::setCrossPoint(const CrossCirclesPoint &v { crossPoint = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointOfIntersectionCircles::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(c1Center, scale); - ScalePoint(c2Center, scale); - ScalePoint(c1Path, scale); - ScalePoint(c2Path, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h index f08b3f9f4..0b3111bc9 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h @@ -57,20 +57,17 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointOfIntersectionCircles)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionCircles) - quint32 object2Id; - qreal c1Radius; - qreal c2Radius; - CrossCirclesPoint crossPoint; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *c1Center; - QGraphicsEllipseItem *c2Center; - QGraphicsEllipseItem *c1Path; - QGraphicsEllipseItem *c2Path; + quint32 object2Id; + qreal c1Radius; + qreal c2Radius; + CrossCirclesPoint crossPoint; + VScaledEllipse *point; + VScaledEllipse *c1Center; + VScaledEllipse *c2Center; + VScaledEllipse *c1Path; + VScaledEllipse *c2Path; }; #endif // VISTOOLPOINTOFINTERSECTIONCIRCLES_H diff --git a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp index 558c776d2..ac59f125f 100644 --- a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp +++ b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp @@ -50,11 +50,11 @@ VisToolShoulderPoint::VisToolShoulderPoint(const VContainer *data, QGraphicsItem { line1P1 = InitPoint(supportColor, this); line1P2 = InitPoint(supportColor, this); //-V656 - line1 = InitItem(supportColor, this); + line1 = InitItem(supportColor, this); line2P2 = InitPoint(supportColor, this); - line2 = InitItem(supportColor, this); - line3 = InitItem(supportColor, this); //-V656 + line2 = InitItem(supportColor, this); + line3 = InitItem(supportColor, this); //-V656 point = InitPoint(mainColor, this); } @@ -131,19 +131,3 @@ void VisToolShoulderPoint::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolShoulderPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(line1P1, scale); - ScalePoint(line1P2, scale); - ScalePenWidth(line1, scale); - ScalePoint(line2P2, scale); - ScalePenWidth(line2, scale); - ScalePenWidth(line3, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistoolshoulderpoint.h b/src/libs/vtools/visualization/line/vistoolshoulderpoint.h index f1547fece..4846ab160 100644 --- a/src/libs/vtools/visualization/line/vistoolshoulderpoint.h +++ b/src/libs/vtools/visualization/line/vistoolshoulderpoint.h @@ -52,21 +52,18 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolShoulderPoint)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolShoulderPoint) - quint32 lineP1Id; - quint32 lineP2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *line1P1; - QGraphicsEllipseItem *line1P2; - QGraphicsLineItem *line1; - QGraphicsEllipseItem *line2P2; - QGraphicsLineItem *line2; - QGraphicsLineItem *line3; - qreal length; + quint32 lineP1Id; + quint32 lineP2Id; + VScaledEllipse *point; + VScaledEllipse *line1P1; + VScaledEllipse *line1P2; + VScaledLine *line1; + VScaledEllipse *line2P2; + VScaledLine *line2; + VScaledLine *line3; + qreal length; }; #endif // VISTOOLSHOULDERPOINT_H diff --git a/src/libs/vtools/visualization/line/vistooltriangle.cpp b/src/libs/vtools/visualization/line/vistooltriangle.cpp index f98191971..0bc70d787 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.cpp +++ b/src/libs/vtools/visualization/line/vistooltriangle.cpp @@ -53,11 +53,11 @@ VisToolTriangle::VisToolTriangle(const VContainer *data, QGraphicsItem *parent) { axisP1 = InitPoint(supportColor, this); axisP2 = InitPoint(supportColor, this); - axis = InitItem(supportColor, this); + axis = InitItem(supportColor, this); hypotenuseP1 = InitPoint(supportColor, this); hypotenuseP2 = InitPoint(supportColor, this); - foot1 = InitItem(supportColor, this); - foot2 = InitItem(supportColor, this); //-V656 + foot1 = InitItem(supportColor, this); + foot2 = InitItem(supportColor, this); //-V656 point = InitPoint(mainColor, this); } @@ -144,24 +144,7 @@ void VisToolTriangle::setHypotenuseP2Id(const quint32 &value) } //--------------------------------------------------------------------------------------------------------------------- -void VisToolTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePoint(axisP1, scale); - ScalePoint(axisP2, scale); - ScalePenWidth(axis, scale); - ScalePoint(hypotenuseP1, scale); - ScalePoint(hypotenuseP2, scale); - ScalePenWidth(foot1, scale); - ScalePenWidth(foot2, scale); - - VisLine::paint(painter, option, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color, +void VisToolTriangle::DrawAimedAxis(VCurvePathItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style) { SCASSERT (item != nullptr) diff --git a/src/libs/vtools/visualization/line/vistooltriangle.h b/src/libs/vtools/visualization/line/vistooltriangle.h index 0939bc69a..3832954b0 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.h +++ b/src/libs/vtools/visualization/line/vistooltriangle.h @@ -57,24 +57,21 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolTriangle)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolTriangle) - quint32 object2Id;//axis second point - quint32 hypotenuseP1Id; - quint32 hypotenuseP2Id; - QGraphicsEllipseItem *point; - QGraphicsEllipseItem *axisP1; - QGraphicsEllipseItem *axisP2; - QGraphicsPathItem *axis; - QGraphicsEllipseItem *hypotenuseP1; - QGraphicsEllipseItem *hypotenuseP2; - QGraphicsLineItem *foot1; - QGraphicsLineItem *foot2; + quint32 object2Id;//axis second point + quint32 hypotenuseP1Id; + quint32 hypotenuseP2Id; + VScaledEllipse *point; + VScaledEllipse *axisP1; + VScaledEllipse *axisP2; + VCurvePathItem *axis; + VScaledEllipse *hypotenuseP1; + VScaledEllipse *hypotenuseP2; + VScaledLine *foot1; + VScaledLine *foot2; - void DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color, + void DrawAimedAxis(VCurvePathItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style = Qt::SolidLine); void DrawArrow(const QLineF &axis, QPainterPath &path, const qreal &arrow_size); }; diff --git a/src/libs/vtools/visualization/line/vistooltruedarts.cpp b/src/libs/vtools/visualization/line/vistooltruedarts.cpp index bf8fd19b4..e503fe724 100644 --- a/src/libs/vtools/visualization/line/vistooltruedarts.cpp +++ b/src/libs/vtools/visualization/line/vistooltruedarts.cpp @@ -67,10 +67,10 @@ VisToolTrueDarts::VisToolTrueDarts(const VContainer *data, QGraphicsItem *parent dartP2 = InitPoint(supportColor, this); dartP3 = InitPoint(supportColor, this); - lineblP1P1 = InitItem(supportColor, this); - lineblP2P2 = InitItem(supportColor, this); - p1d2 = InitItem(supportColor, this); - d2p2 = InitItem(supportColor, this); + lineblP1P1 = InitItem(supportColor, this); + lineblP2P2 = InitItem(supportColor, this); + p1d2 = InitItem(supportColor, this); + d2p2 = InitItem(supportColor, this); point1 = InitPoint(mainColor, this); point2 = InitPoint(mainColor, this); //-V656 @@ -163,24 +163,3 @@ void VisToolTrueDarts::setD3PointId(const quint32 &value) { dartP3Id = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolTrueDarts::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point1, scale); - ScalePoint(point2, scale); - ScalePoint(baseLineP1, scale); - ScalePoint(baseLineP2, scale); - ScalePoint(dartP1, scale); - ScalePoint(dartP2, scale); - ScalePoint(dartP3, scale); - - ScalePenWidth(lineblP1P1, scale); - ScalePenWidth(lineblP2P2, scale); - ScalePenWidth(p1d2, scale); - ScalePenWidth(d2p2, scale); - - VisLine::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/line/vistooltruedarts.h b/src/libs/vtools/visualization/line/vistooltruedarts.h index b8e6c2588..60b784c32 100644 --- a/src/libs/vtools/visualization/line/vistooltruedarts.h +++ b/src/libs/vtools/visualization/line/vistooltruedarts.h @@ -55,9 +55,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolTrueDarts)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolTrueDarts) quint32 baseLineP2Id; @@ -65,18 +62,18 @@ private: quint32 dartP2Id; quint32 dartP3Id; - QGraphicsEllipseItem *point1; - QGraphicsEllipseItem *point2; - QGraphicsEllipseItem *baseLineP1; - QGraphicsEllipseItem *baseLineP2; - QGraphicsEllipseItem *dartP1; - QGraphicsEllipseItem *dartP2; - QGraphicsEllipseItem *dartP3; + VScaledEllipse *point1; + VScaledEllipse *point2; + VScaledEllipse *baseLineP1; + VScaledEllipse *baseLineP2; + VScaledEllipse *dartP1; + VScaledEllipse *dartP2; + VScaledEllipse *dartP3; - QGraphicsLineItem *lineblP1P1; - QGraphicsLineItem *lineblP2P2; - QGraphicsLineItem *p1d2; - QGraphicsLineItem *d2p2; + VScaledLine *lineblP1P1; + VScaledLine *lineblP2P2; + VScaledLine *p1d2; + VScaledLine *d2p2; }; #endif // VISTOOLTRUEDARTS_H diff --git a/src/libs/vtools/visualization/path/vispath.cpp b/src/libs/vtools/visualization/path/vispath.cpp index 5fe62ec75..2b0a1c28f 100644 --- a/src/libs/vtools/visualization/path/vispath.cpp +++ b/src/libs/vtools/visualization/path/vispath.cpp @@ -45,22 +45,6 @@ VisPath::VisPath(const VContainer *data, QGraphicsItem *parent) InitPen(); } -//--------------------------------------------------------------------------------------------------------------------- -void VisPath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - ScalePenWidth(this, SceneScale(scene())); - - VCurvePathItem::paint(painter, option, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -QRectF VisPath::boundingRect() const -{ - QRectF recTool = VCurvePathItem::boundingRect(); - recTool = recTool.united(childrenBoundingRect()); - return recTool; -} - //--------------------------------------------------------------------------------------------------------------------- void VisPath::InitPen() { diff --git a/src/libs/vtools/visualization/path/vispath.h b/src/libs/vtools/visualization/path/vispath.h index 6d7ffb900..dcfd290e2 100644 --- a/src/libs/vtools/visualization/path/vispath.h +++ b/src/libs/vtools/visualization/path/vispath.h @@ -51,10 +51,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::Path)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; protected: virtual void InitPen() Q_DECL_OVERRIDE; virtual void AddOnScene() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/path/vistoolarc.cpp b/src/libs/vtools/visualization/path/vistoolarc.cpp index 4989c43da..bb0499b99 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolarc.cpp @@ -41,6 +41,7 @@ #include "../vpatterndb/vcontainer.h" #include "../visualization.h" #include "vispath.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolArc::VisToolArc(const VContainer *data, QGraphicsItem *parent) @@ -82,13 +83,3 @@ void VisToolArc::setF2(const QString &expression) { f2 = FindVal(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(arcCenter, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolarc.h b/src/libs/vtools/visualization/path/vistoolarc.h index 073a28fc2..a5435881a 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.h +++ b/src/libs/vtools/visualization/path/vistoolarc.h @@ -52,15 +52,12 @@ public: void setF2(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolArc)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolArc) - QGraphicsEllipseItem *arcCenter; - qreal radius; - qreal f1; - qreal f2; + VScaledEllipse *arcCenter; + qreal radius; + qreal f1; + qreal f2; }; #endif // VISTOOLARC_H diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp index 7b2968bab..becb6a7ce 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp @@ -82,13 +82,3 @@ void VisToolArcWithLength::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolArcWithLength::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(arcCenter, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.h b/src/libs/vtools/visualization/path/vistoolarcwithlength.h index 1f10686c5..e50ae6a21 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.h +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.h @@ -52,15 +52,12 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolArcWithLength)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolArcWithLength) - QGraphicsEllipseItem *arcCenter; - qreal radius; - qreal f1; - qreal length; + VScaledEllipse *arcCenter; + qreal radius; + qreal f1; + qreal length; }; #endif // VISTOOLARCWITHLENGTH_H diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp index 2c3159c32..950365181 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp @@ -43,6 +43,7 @@ #include "../vpatterndb/vcontainer.h" #include "../visualization.h" #include "vispath.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *parent) @@ -57,8 +58,8 @@ VisToolCubicBezier::VisToolCubicBezier(const VContainer *data, QGraphicsItem *pa helpLine1(nullptr), helpLine2(nullptr) { - helpLine1 = InitItem(mainColor, this); - helpLine2 = InitItem(mainColor, this); + helpLine1 = InitItem(mainColor, this); + helpLine2 = InitItem(mainColor, this); point1 = InitPoint(supportColor, this); point2 = InitPoint(supportColor, this); //-V656 @@ -135,18 +136,3 @@ void VisToolCubicBezier::setObject4Id(const quint32 &value) { object4Id = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolCubicBezier::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point1, scale); - ScalePoint(point2, scale); - ScalePoint(point3, scale); - ScalePoint(point4, scale); - ScalePenWidth(helpLine1, scale); - ScalePenWidth(helpLine2, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.h b/src/libs/vtools/visualization/path/vistoolcubicbezier.h index 5ba6555ff..a397f2434 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.h +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.h @@ -54,20 +54,17 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolCubicBezier)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCubicBezier) - quint32 object2Id; - quint32 object3Id; - quint32 object4Id; - QGraphicsEllipseItem *point1; - QGraphicsEllipseItem *point2; - QGraphicsEllipseItem *point3; - QGraphicsEllipseItem *point4; - QGraphicsLineItem *helpLine1; - QGraphicsLineItem *helpLine2; + quint32 object2Id; + quint32 object3Id; + quint32 object4Id; + VScaledEllipse *point1; + VScaledEllipse *point2; + VScaledEllipse *point3; + VScaledEllipse *point4; + VScaledLine *helpLine1; + VScaledLine *helpLine2; }; #endif // VISTOOLCUBICBEZIER_H diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp index ab4868809..304804129 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp @@ -41,6 +41,7 @@ #include "../vgeometry/vspline.h" #include "../visualization.h" #include "vispath.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent) @@ -53,8 +54,8 @@ VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphics helpLine1(nullptr), helpLine2(nullptr) { - helpLine1 = InitItem(mainColor, this); - helpLine2 = InitItem(mainColor, this); + helpLine1 = InitItem(mainColor, this); + helpLine2 = InitItem(mainColor, this); newCurveSegment = InitItem(mainColor, this); } @@ -77,7 +78,7 @@ void VisToolCubicBezierPath::RefreshGeometry() for (int i = 0; i < size; ++i) { - QGraphicsEllipseItem *point = this->getPoint(mainPoints, static_cast(i), 1/*zValue*/); + VScaledEllipse *point = this->getPoint(mainPoints, static_cast(i), 1/*zValue*/); DrawPoint(point, static_cast(pathPoints.at(i)), supportColor); } @@ -106,18 +107,18 @@ void VisToolCubicBezierPath::RefreshGeometry() const VSpline spl = path.GetSpline(i); - QGraphicsLineItem *ctrlLine1 = this->getLine(static_cast(preLastPoint)); + VScaledLine *ctrlLine1 = this->getLine(static_cast(preLastPoint)); DrawLine(ctrlLine1, QLineF(static_cast(spl.GetP1()), static_cast(spl.GetP2())), mainColor, Qt::DashLine); - QGraphicsEllipseItem *p2 = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + VScaledEllipse *p2 = this->getPoint(ctrlPoints, static_cast(preLastPoint)); DrawPoint(p2, static_cast(spl.GetP2()), Qt::green); - QGraphicsLineItem *ctrlLine2 = this->getLine(static_cast(lastPoint)); + VScaledLine *ctrlLine2 = this->getLine(static_cast(lastPoint)); DrawLine(ctrlLine2, QLineF(static_cast(spl.GetP4()), static_cast(spl.GetP3())), mainColor, Qt::DashLine); - QGraphicsEllipseItem *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); + VScaledEllipse *p3 = this->getPoint(ctrlPoints, static_cast(lastPoint)); DrawPoint(p3, static_cast(spl.GetP3()), Qt::green); } } @@ -142,34 +143,7 @@ VCubicBezierPath VisToolCubicBezierPath::getPath() } //--------------------------------------------------------------------------------------------------------------------- -void VisToolCubicBezierPath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - for (int i=0; i < mainPoints.size(); ++i) - { - ScalePoint(mainPoints[i], scale); - } - - for (int i=0; i < ctrlPoints.size(); ++i) - { - ScalePoint(ctrlPoints[i], scale); - } - - for (int i=0; i < lines.size(); ++i) - { - ScalePenWidth(lines[i], scale); - } - - ScalePenWidth(newCurveSegment, scale); - ScalePenWidth(helpLine1, scale); - ScalePenWidth(helpLine2, scale); - - VisPath::paint(painter, option, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector &points, quint32 i, qreal z) +VScaledEllipse *VisToolCubicBezierPath::getPoint(QVector &points, quint32 i, qreal z) { if (not points.isEmpty() && static_cast(points.size() - 1) >= i) { @@ -184,7 +158,7 @@ QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector(lines.size() - 1) >= i && lines.isEmpty() == false) { @@ -192,7 +166,7 @@ QGraphicsLineItem *VisToolCubicBezierPath::getLine(quint32 i) } else { - auto line = InitItem(mainColor, this); + auto line = InitItem(mainColor, this); lines.append(line); return line; } @@ -234,7 +208,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po DrawLine(helpLine1, p1p2, mainColor, Qt::DashLine); const int preLastPoint = subSplCount * 2; - QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + VScaledEllipse *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); DrawPoint(p2Ctrl, p2, Qt::green); } else @@ -263,7 +237,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); const int preLastPoint = subSplCount * 2; - QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + VScaledEllipse *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); DrawPoint(p2Ctrl, p2, Qt::green); break; } @@ -289,7 +263,7 @@ void VisToolCubicBezierPath::Creating(const QVector &pathPoints, int po DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); const int preLastPoint = subSplCount * 2; - QGraphicsEllipseItem *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); + VScaledEllipse *p2Ctrl = this->getPoint(ctrlPoints, static_cast(preLastPoint)); DrawPoint(p2Ctrl, p2, Qt::green); break; } diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.h b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.h index a96413423..2fe15cd06 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.h +++ b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.h @@ -55,22 +55,19 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolCubicBezierPath)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCubicBezierPath) - QVector mainPoints; - QVector ctrlPoints; - QVector lines; - VCurvePathItem *newCurveSegment; - VCubicBezierPath path; - QGraphicsLineItem *helpLine1; - QGraphicsLineItem *helpLine2; + QVector mainPoints; + QVector ctrlPoints; + QVector lines; + VCurvePathItem *newCurveSegment; + VCubicBezierPath path; + VScaledLine *helpLine1; + VScaledLine *helpLine2; private: - QGraphicsEllipseItem *getPoint(QVector &points, quint32 i, qreal z = 0); - QGraphicsLineItem *getLine(quint32 i); + VScaledEllipse *getPoint(QVector &points, quint32 i, qreal z = 0); + VScaledLine *getLine(quint32 i); void Creating(const QVector &pathPoints , int pointsLeft); void RefreshToolTip(); }; diff --git a/src/libs/vtools/visualization/path/vistoolcutarc.cpp b/src/libs/vtools/visualization/path/vistoolcutarc.cpp index 3f9f70e61..9061df301 100644 --- a/src/libs/vtools/visualization/path/vistoolcutarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutarc.cpp @@ -42,6 +42,7 @@ #include "../vpatterndb/vcontainer.h" #include "../visualization.h" #include "vispath.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolCutArc::VisToolCutArc(const VContainer *data, QGraphicsItem *parent) @@ -83,15 +84,3 @@ void VisToolCutArc::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolCutArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(arc1, scale); - ScalePenWidth(arc2, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolcutarc.h b/src/libs/vtools/visualization/path/vistoolcutarc.h index a6ac723bd..24f11e52c 100644 --- a/src/libs/vtools/visualization/path/vistoolcutarc.h +++ b/src/libs/vtools/visualization/path/vistoolcutarc.h @@ -50,15 +50,12 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolCutArc)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutArc) - QGraphicsEllipseItem *point; - VCurvePathItem *arc1; - VCurvePathItem *arc2; - qreal length; + VScaledEllipse *point; + VCurvePathItem *arc1; + VCurvePathItem *arc2; + qreal length; }; #endif // VISTOOLCUTARC_H diff --git a/src/libs/vtools/visualization/path/vistoolcutspline.cpp b/src/libs/vtools/visualization/path/vistoolcutspline.cpp index e7caf278f..114a1327e 100644 --- a/src/libs/vtools/visualization/path/vistoolcutspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutspline.cpp @@ -44,6 +44,7 @@ #include "../vpatterndb/vcontainer.h" #include "../visualization.h" #include "vispath.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolCutSpline::VisToolCutSpline(const VContainer *data, QGraphicsItem *parent) @@ -91,15 +92,3 @@ void VisToolCutSpline::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolCutSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(spl1, scale); - ScalePenWidth(spl2, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolcutspline.h b/src/libs/vtools/visualization/path/vistoolcutspline.h index c221ad59b..1f7f8f13b 100644 --- a/src/libs/vtools/visualization/path/vistoolcutspline.h +++ b/src/libs/vtools/visualization/path/vistoolcutspline.h @@ -50,15 +50,12 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutSpline) - QGraphicsEllipseItem *point; - VCurvePathItem *spl1; - VCurvePathItem *spl2; - qreal length; + VScaledEllipse *point; + VCurvePathItem *spl1; + VCurvePathItem *spl2; + qreal length; }; #endif // VISTOOLCUTSPLINE_H diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp index fc7fac909..200310c6b 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp @@ -93,15 +93,3 @@ void VisToolCutSplinePath::setLength(const QString &expression) { length = FindLength(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolCutSplinePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(splPath1, scale); - ScalePenWidth(splPath2, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.h b/src/libs/vtools/visualization/path/vistoolcutsplinepath.h index 6a9c6c182..7c95d8d16 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.h +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.h @@ -50,15 +50,12 @@ public: void setLength(const QString &expression); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutSplinePath) - QGraphicsEllipseItem *point; - VCurvePathItem *splPath1; - VCurvePathItem *splPath2; - qreal length; + VScaledEllipse *point; + VCurvePathItem *splPath1; + VCurvePathItem *splPath2; + qreal length; }; #endif // VISTOOLCUTSPLINEPATH_H diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp index 20b072fb1..612b39b2a 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp @@ -91,13 +91,3 @@ void VisToolEllipticalArc::setRotationAngle(const QString &expression) { rotationAngle = FindVal(expression, Visualization::data->PlainVariables()); } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolEllipticalArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(arcCenter, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.h b/src/libs/vtools/visualization/path/vistoolellipticalarc.h index 70087fad9..3e662e77c 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.h +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.h @@ -54,17 +54,14 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolEllipticalArc)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolEllipticalArc) - QGraphicsEllipseItem *arcCenter; - qreal radius1; - qreal radius2; - qreal f1; - qreal f2; - qreal rotationAngle; + VScaledEllipse *arcCenter; + qreal radius1; + qreal radius2; + qreal f1; + qreal f2; + qreal rotationAngle; }; #endif // VISTOOLELLIPTICALARC_H diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index 1d10d83e8..d359cfeda 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -29,6 +29,7 @@ #include "vistoolpiece.h" #include "../vpatterndb/vpiecepath.h" #include "../vgeometry/vpointf.h" +#include "../vwidgets/scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) @@ -38,8 +39,8 @@ VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) m_line2(nullptr), m_piece() { - m_line1 = InitItem(supportColor, this); - m_line2 = InitItem(supportColor, this); + m_line1 = InitItem(supportColor, this); + m_line2 = InitItem(supportColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -55,7 +56,7 @@ void VisToolPiece::RefreshGeometry() for (int i = 0; i < nodes.size(); ++i) { - QGraphicsEllipseItem *point = GetPoint(static_cast(i), supportColor); + VScaledEllipse *point = GetPoint(static_cast(i), supportColor); DrawPoint(point, nodes.at(i).toQPointF(), supportColor); } @@ -79,23 +80,7 @@ void VisToolPiece::SetPiece(const VPiece &piece) } //--------------------------------------------------------------------------------------------------------------------- -void VisToolPiece::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - for (int i=0; i < m_points.size(); ++i) - { - ScalePoint(m_points[i], scale); - } - - ScalePenWidth(m_line1, scale); - ScalePenWidth(m_line2, scale); - - VisPath::paint(painter, option, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolPiece::GetPoint(quint32 i, const QColor &color) +VScaledEllipse *VisToolPiece::GetPoint(quint32 i, const QColor &color) { return GetPointItem(m_points, i, color, this); } diff --git a/src/libs/vtools/visualization/path/vistoolpiece.h b/src/libs/vtools/visualization/path/vistoolpiece.h index 73bc9a11f..0863435f5 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.h +++ b/src/libs/vtools/visualization/path/vistoolpiece.h @@ -46,18 +46,15 @@ public: void SetPiece(const VPiece &piece); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPiece)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPiece) - QVector m_points; + QVector m_points; - QGraphicsLineItem *m_line1; - QGraphicsLineItem *m_line2; + VScaledLine *m_line1; + VScaledLine *m_line2; VPiece m_piece; - QGraphicsEllipseItem* GetPoint(quint32 i, const QColor &color); + VScaledEllipse* GetPoint(quint32 i, const QColor &color); void HideAllItems(); }; diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp index 8577d452a..df3cbc9fc 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -29,6 +29,7 @@ #include "vistoolpiecepath.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" +#include "../vwidgets/scalesceneitems.h" #include @@ -39,7 +40,7 @@ VisToolPiecePath::VisToolPiecePath(const VContainer *data, QGraphicsItem *parent m_line(nullptr), m_path() { - m_line = InitItem(supportColor, this); + m_line = InitItem(supportColor, this); } //--------------------------------------------------------------------------------------------------------------------- @@ -78,21 +79,6 @@ void VisToolPiecePath::SetPath(const VPiecePath &path) m_path = path; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPiecePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - for (int i=0; i < m_points.size(); ++i) - { - ScalePoint(m_points[i], scale); - } - - ScalePenWidth(m_line, scale); - - VisPath::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.h b/src/libs/vtools/visualization/path/vistoolpiecepath.h index 17e91e120..22ee8d0a0 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.h +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.h @@ -48,9 +48,6 @@ public: void SetPath(const VPiecePath &path); virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPiecePath)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; protected: virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; @@ -58,7 +55,7 @@ private: Q_DISABLE_COPY(VisToolPiecePath) QVector m_points; - QGraphicsLineItem *m_line; + VScaledLine *m_line; VPiecePath m_path; diff --git a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp index a91baeec0..525f356a5 100644 --- a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp @@ -107,14 +107,3 @@ void VisToolPointOfIntersectionCurves::setHCrossPoint(const HCrossCurvesPoint &v { hCrossPoint = value; } - -//--------------------------------------------------------------------------------------------------------------------- -void VisToolPointOfIntersectionCurves::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point, scale); - ScalePenWidth(visCurve2, scale); - - VisPath::paint(painter, option, widget); -} diff --git a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h index a5fad43af..b62eddd51 100644 --- a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h +++ b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h @@ -56,17 +56,13 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolPointOfIntersectionCurves)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionCurves) - quint32 object2Id; - VCrossCurvesPoint vCrossPoint; - HCrossCurvesPoint hCrossPoint; - - QGraphicsEllipseItem *point; - VCurvePathItem *visCurve2; + quint32 object2Id; + VCrossCurvesPoint vCrossPoint; + HCrossCurvesPoint hCrossPoint; + VScaledEllipse *point; + VCurvePathItem *visCurve2; }; diff --git a/src/libs/vtools/visualization/path/vistoolspline.cpp b/src/libs/vtools/visualization/path/vistoolspline.cpp index 65dc802d2..2c57da5f3 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolspline.cpp @@ -221,17 +221,6 @@ QPointF VisToolSpline::GetP3() const return p3; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - ScalePoint(point1, scale); - ScalePoint(point4, scale); - - VisPath::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolSpline::MouseLeftPressed() { diff --git a/src/libs/vtools/visualization/path/vistoolspline.h b/src/libs/vtools/visualization/path/vistoolspline.h index c2dee9daf..62640657d 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.h +++ b/src/libs/vtools/visualization/path/vistoolspline.h @@ -64,23 +64,20 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolSpline)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; public slots: void MouseLeftPressed(); void MouseLeftReleased(); protected: Q_DISABLE_COPY(VisToolSpline) - quint32 object4Id; - QGraphicsEllipseItem *point1; - QGraphicsEllipseItem *point4; - qreal angle1; - qreal angle2; - qreal kAsm1; - qreal kAsm2; - qreal kCurve; + quint32 object4Id; + VScaledEllipse *point1; + VScaledEllipse *point4; + qreal angle1; + qreal angle2; + qreal kAsm1; + qreal kAsm2; + qreal kCurve; bool isLeftMousePressed; bool p2Selected; diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp index 2782cfe89..62e8f1deb 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp @@ -48,10 +48,10 @@ //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) : VisPath(data, parent), - points(QVector()), - ctrlPoints(QVector()), + points(), + ctrlPoints(), newCurveSegment(nullptr), - path(VSplinePath()), + path(), isLeftMousePressed(false), pointSelected(false), ctrlPoint() @@ -62,8 +62,6 @@ VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *pare //--------------------------------------------------------------------------------------------------------------------- VisToolSplinePath::~VisToolSplinePath() { - qDeleteAll(ctrlPoints); - qDeleteAll(points); emit ToolTip(""); } @@ -77,7 +75,7 @@ void VisToolSplinePath::RefreshGeometry() for (int i = 0; i < size; ++i) { - QGraphicsEllipseItem *point = this->getPoint(static_cast(i)); + VScaledEllipse *point = this->getPoint(static_cast(i)); DrawPoint(point, static_cast(pathPoints.at(i).P()), supportColor); } @@ -139,19 +137,6 @@ VSplinePath VisToolSplinePath::getPath() return path; } -//--------------------------------------------------------------------------------------------------------------------- -void VisToolSplinePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - const qreal scale = SceneScale(scene()); - - for (int i=0; i < points.size(); ++i) - { - ScalePoint(points[i], scale); - } - - VisPath::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::MouseLeftPressed() { @@ -172,7 +157,7 @@ void VisToolSplinePath::MouseLeftReleased() } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) +VScaledEllipse *VisToolSplinePath::getPoint(quint32 i) { if (static_cast(points.size() - 1) >= i && points.isEmpty() == false) { diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.h b/src/libs/vtools/visualization/path/vistoolsplinepath.h index 60f09e4cd..97e20f01a 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.h @@ -58,9 +58,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ToolSplinePath)}; - - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; signals: void PathChanged(const VSplinePath &path); @@ -70,17 +67,17 @@ public slots: protected: Q_DISABLE_COPY(VisToolSplinePath) - QVector points; - QVector ctrlPoints; - VCurvePathItem *newCurveSegment; - VSplinePath path; + QVector points; + QVector ctrlPoints; + VCurvePathItem *newCurveSegment; + VSplinePath path; bool isLeftMousePressed; bool pointSelected; QPointF ctrlPoint; - QGraphicsEllipseItem * getPoint(quint32 i); + VScaledEllipse * getPoint(quint32 i); void Creating(const QPointF &pSpl, int size); }; diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 39f29e993..a80db6025 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -53,6 +53,7 @@ #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vcurvepathitem.h" +#include "../vwidgets/scalesceneitems.h" template class QHash; @@ -136,14 +137,7 @@ void Visualization::MousePos(const QPointF &scenePos) } //--------------------------------------------------------------------------------------------------------------------- -void Visualization::ScalePoint(QGraphicsEllipseItem *item, qreal scale) -{ - ScaleCircleSize(item, scale); - ScalePenWidth(item, scale); -} - -//--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const +VScaledEllipse *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const { return InitPointItem(color, parent, z); } @@ -192,7 +186,7 @@ qreal Visualization::FindVal(const QString &expression, const QHash &points, quint32 i, - const QColor &color, QGraphicsItem *parent) +VScaledEllipse *Visualization::GetPointItem(QVector &points, quint32 i, + const QColor &color, QGraphicsItem *parent) { if (not points.isEmpty() && static_cast(points.size() - 1) >= i) { @@ -262,9 +256,9 @@ QGraphicsEllipseItem *Visualization::GetPointItem(QVectorsetZValue(1); point->setBrush(QBrush(Qt::NoBrush)); diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index 177e822ff..d2530cbcb 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -44,6 +44,9 @@ Q_DECLARE_LOGGING_CATEGORY(vVis) +class VScaledEllipse; +class VScaledLine; + enum class Mode : char {Creation, Show}; class Visualization : public QObject @@ -86,15 +89,10 @@ protected: virtual void InitPen()=0; virtual void AddOnScene()=0; - template - void ScalePenWidth(Item *item, qreal scale); - - void ScalePoint(QGraphicsEllipseItem *item, qreal scale); - - QGraphicsEllipseItem *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const; - void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color, + VScaledEllipse *InitPoint(const QColor &color, QGraphicsItem *parent, qreal z = 0) const; + void DrawPoint(VScaledEllipse *point, const QPointF &pos, const QColor &color, Qt::PenStyle style = Qt::SolidLine); - virtual void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, + virtual void DrawLine(VScaledLine *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style = Qt::SolidLine); void DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, const QColor &color, Qt::PenStyle style = Qt::SolidLine, Qt::PenCapStyle cap = Qt::SquareCap); @@ -107,12 +105,12 @@ protected: template Item *InitItem(const QColor &color, QGraphicsItem *parent); - static QGraphicsEllipseItem* GetPointItem(QVector &points, quint32 i, const QColor &color, - QGraphicsItem *parent); + static VScaledEllipse *GetPointItem(QVector &points, quint32 i, const QColor &color, + QGraphicsItem *parent); private: Q_DISABLE_COPY(Visualization) - static QGraphicsEllipseItem* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0); + static VScaledEllipse* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0); }; //--------------------------------------------------------------------------------------------------------------------- @@ -143,18 +141,4 @@ inline Item *Visualization::InitItem(const QColor &color, QGraphicsItem *parent) return item; } -//--------------------------------------------------------------------------------------------------------------------- -template -void Visualization::ScalePenWidth(Item *item, qreal scale) -{ - SCASSERT(item != nullptr) - - const qreal width = ScaleWidth(widthMainLine, scale); - - QPen visPen = item->pen(); - visPen.setWidthF(width); - - item->setPen(visPen); -} - #endif // VISUALIZATION_H diff --git a/src/libs/vwidgets/scalesceneitems.cpp b/src/libs/vwidgets/scalesceneitems.cpp new file mode 100644 index 000000000..2418d9c70 --- /dev/null +++ b/src/libs/vwidgets/scalesceneitems.cpp @@ -0,0 +1,86 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 21 6, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "scalesceneitems.h" +#include "global.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VScaledLine::VScaledLine(QGraphicsItem *parent) + : QGraphicsLineItem(parent), + basicWidth(widthMainLine) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VScaledLine::VScaledLine(const QLineF &line, QGraphicsItem *parent) + : QGraphicsLineItem(line, parent), + basicWidth(widthMainLine) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VScaledLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QPen lPen = pen(); + lPen.setWidthF(ScaleWidth(basicWidth, SceneScale(scene()))); + setPen(lPen); + + QGraphicsLineItem::paint(painter, option, widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VScaledLine::GetBasicWidth() const +{ + return basicWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScaledLine::SetBasicWidth(const qreal &value) +{ + basicWidth = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VScaledEllipse::VScaledEllipse(QGraphicsItem *parent) + : QGraphicsEllipseItem(parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VScaledEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + const qreal scale = SceneScale(scene()); + const qreal width = ScaleWidth(widthMainLine, scale); + + QPen visPen = pen(); + visPen.setWidthF(width); + + setPen(visPen); + ScaleCircleSize(this, scale); + + QGraphicsEllipseItem::paint(painter, option, widget); +} diff --git a/src/libs/vwidgets/scalesceneitems.h b/src/libs/vwidgets/scalesceneitems.h new file mode 100644 index 000000000..e639ca747 --- /dev/null +++ b/src/libs/vwidgets/scalesceneitems.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 21 6, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef SCALESCENEITEMS_H +#define SCALESCENEITEMS_H + +#include + +#include "../vmisc/def.h" + +class VScaledLine : public QGraphicsLineItem +{ +public: + explicit VScaledLine(QGraphicsItem * parent = nullptr); + VScaledLine(const QLineF &line, QGraphicsItem * parent = nullptr); + virtual ~VScaledLine() = default; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ScaledLine)}; + + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + + qreal GetBasicWidth() const; + void SetBasicWidth(const qreal &value); + +private: + Q_DISABLE_COPY(VScaledLine) + + qreal basicWidth; +}; + +class VScaledEllipse : public QGraphicsEllipseItem +{ +public: + explicit VScaledEllipse(QGraphicsItem * parent = nullptr); + virtual ~VScaledEllipse() = default; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ScaledEllipse)}; + + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VScaledEllipse) +}; + +#endif // SCALESCENEITEMS_H diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index a547495b6..94a1171a5 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -48,6 +48,7 @@ #include "vmaingraphicsscene.h" #include "vmaingraphicsview.h" #include "vgraphicssimpletextitem.h" +#include "scalesceneitems.h" //--------------------------------------------------------------------------------------------------------------------- VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem *parent) @@ -100,21 +101,13 @@ VControlPointSpline::~VControlPointSpline() //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - const qreal scale = SceneScale(scene()); - - ScaleLinePenWidth(controlLine, scale); + QPen lPen = controlLine->pen(); + lPen.setColor(CorrectColor(controlLine, Qt::black)); + controlLine->setPen(lPen); VScenePoint::paint(painter, option, widget); } -//--------------------------------------------------------------------------------------------------------------------- -QRectF VControlPointSpline::boundingRect() const -{ - QRectF recTool = VScenePoint::boundingRect(); - recTool = recTool.united(childrenBoundingRect()); - return recTool; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief hoverEnterEvent handle hover enter events. @@ -267,12 +260,8 @@ void VControlPointSpline::Init() this->setBrush(QBrush(Qt::NoBrush)); this->setZValue(100); - controlLine = new QGraphicsLineItem(this); - - QPen cPen = controlLine->pen(); - cPen.setBrush(QBrush(Qt::red)); - - controlLine->setPen(cPen); + controlLine = new VScaledLine(this); + controlLine->SetBasicWidth(widthHairLine); controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index b10dbc334..d0409b282 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -55,12 +55,11 @@ public: const QPointF &splinePoint, bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr); virtual ~VControlPointSpline(); - virtual int type() const Q_DECL_OVERRIDE {return Type;} + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::ControlPointSpline)}; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; signals: /** * @brief ControlPointChangePosition emit when control point change position. @@ -81,7 +80,7 @@ public slots: void setEnabledPoint(bool enable); protected: /** @brief controlLine pointer to line control point. */ - QGraphicsLineItem *controlLine; + VScaledLine *controlLine; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vwidgets/vcurvepathitem.cpp b/src/libs/vwidgets/vcurvepathitem.cpp index e840e4bf3..dd7304269 100644 --- a/src/libs/vwidgets/vcurvepathitem.cpp +++ b/src/libs/vwidgets/vcurvepathitem.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "vcurvepathitem.h" +#include "../vwidgets/global.h" #include @@ -37,9 +38,49 @@ VCurvePathItem::VCurvePathItem(QGraphicsItem *parent) { } +//--------------------------------------------------------------------------------------------------------------------- +QPainterPath VCurvePathItem::shape() const +{ + QPainterPath itemPath = path(); + + if (m_direction != QPainterPath()) + { + itemPath.addPath(m_direction); + } + + itemPath.setFillRule(Qt::WindingFill); + + // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0 + // if we pass a value of 0.0 to QPainterPathStroker::setWidth() + const qreal penWidthZero = qreal(0.00000001); + + if (itemPath == QPainterPath() || pen() == Qt::NoPen) + { + return itemPath; + } + + QPainterPathStroker ps; + ps.setCapStyle(pen().capStyle()); + if (pen().widthF() <= 0.0) + { + ps.setWidth(penWidthZero); + } + else + { + ps.setWidth(pen().widthF()); + } + ps.setJoinStyle(pen().joinStyle()); + ps.setMiterLimit(pen().miterLimit()); + QPainterPath p = ps.createStroke(itemPath); + p.addPath(itemPath); + return p; +} + //--------------------------------------------------------------------------------------------------------------------- void VCurvePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + ScalePenWidth(); + if (m_direction != QPainterPath()) { painter->save(); @@ -62,3 +103,14 @@ void VCurvePathItem::SetDirectionPath(const QPainterPath &path) { m_direction = path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VCurvePathItem::ScalePenWidth() +{ + const qreal width = ScaleWidth(widthMainLine, SceneScale(scene())); + + QPen toolPen = pen(); + toolPen.setWidthF(width); + + setPen(toolPen); +} diff --git a/src/libs/vwidgets/vcurvepathitem.h b/src/libs/vwidgets/vcurvepathitem.h index 198c3c66d..b78db80f4 100644 --- a/src/libs/vwidgets/vcurvepathitem.h +++ b/src/libs/vwidgets/vcurvepathitem.h @@ -38,6 +38,9 @@ class VCurvePathItem : public QGraphicsPathItem { public: explicit VCurvePathItem(QGraphicsItem *parent = nullptr); + virtual ~VCurvePathItem() = default; + + virtual QPainterPath shape() const Q_DECL_OVERRIDE; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) Q_DECL_OVERRIDE; @@ -46,6 +49,8 @@ public: enum { Type = UserType + static_cast(Vis::CurvePathItem)}; void SetDirectionPath(const QPainterPath &path); +protected: + virtual void ScalePenWidth(); private: Q_DISABLE_COPY(VCurvePathItem) diff --git a/src/libs/vwidgets/vscenepoint.cpp b/src/libs/vwidgets/vscenepoint.cpp index 9bd183834..18ccf953a 100644 --- a/src/libs/vwidgets/vscenepoint.cpp +++ b/src/libs/vwidgets/vscenepoint.cpp @@ -31,6 +31,7 @@ #include "../vgeometry/vpointf.h" #include "global.h" #include "vgraphicssimpletextitem.h" +#include "scalesceneitems.h" #include #include @@ -46,7 +47,8 @@ VScenePoint::VScenePoint(QGraphicsItem *parent) m_baseColor(Qt::black) { m_namePoint = new VGraphicsSimpleTextItem(this); - m_lineName = new QGraphicsLineItem(this); + m_lineName = new VScaledLine(this); + m_lineName->SetBasicWidth(widthHairLine); this->setBrush(QBrush(Qt::NoBrush)); this->setAcceptHoverEvents(true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus @@ -72,7 +74,9 @@ void VScenePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio m_namePoint->setVisible(true); m_lineName->setVisible(true); - ScaleLinePenWidth(m_lineName, scale); + QPen lPen = m_lineName->pen(); + lPen.setColor(CorrectColor(m_lineName, Qt::black)); + m_lineName->setPen(lPen); RefreshLine(); } @@ -96,14 +100,6 @@ void VScenePoint::RefreshPointGeometry(const VPointF &point) RefreshLine(); } -//--------------------------------------------------------------------------------------------------------------------- -QRectF VScenePoint::boundingRect() const -{ - QRectF recTool = QGraphicsEllipseItem::boundingRect(); - recTool = recTool.united(childrenBoundingRect()); - return recTool; -} - //--------------------------------------------------------------------------------------------------------------------- void VScenePoint::SetOnlyPoint(bool value) { @@ -169,13 +165,3 @@ void VScenePoint::ScaleMainPenWidth(qreal scale) setPen(QPen(CorrectColor(this, m_baseColor), width)); } - -//--------------------------------------------------------------------------------------------------------------------- -void VScenePoint::ScaleLinePenWidth(QGraphicsLineItem *line, qreal scale) -{ - SCASSERT(line != nullptr) - const qreal width = ScaleWidth(widthHairLine, scale); - - line->setPen(QPen(CorrectColor(line, Qt::black), width)); -} - diff --git a/src/libs/vwidgets/vscenepoint.h b/src/libs/vwidgets/vscenepoint.h index 01ec0c18e..8d997d080 100644 --- a/src/libs/vwidgets/vscenepoint.h +++ b/src/libs/vwidgets/vscenepoint.h @@ -34,25 +34,24 @@ class VGraphicsSimpleTextItem; class VPointF; +class VScaledLine; class VScenePoint: public QGraphicsEllipseItem { public: explicit VScenePoint(QGraphicsItem *parent = nullptr); - ~VScenePoint() = default; + virtual ~VScenePoint() = default; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; - - virtual void RefreshPointGeometry(const VPointF &point); - virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual void RefreshPointGeometry(const VPointF &point); protected: /** @brief namePoint point label. */ VGraphicsSimpleTextItem *m_namePoint; /** @brief lineName line what we see if label moved too away from point. */ - QGraphicsLineItem *m_lineName; + VScaledLine *m_lineName; bool m_onlyPoint; bool m_isHovered; @@ -64,7 +63,6 @@ protected: virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; void RefreshLine(); - void ScaleLinePenWidth(QGraphicsLineItem *line, qreal scale); void SetOnlyPoint(bool value); bool IsOnlyPoint() const; diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index fbc30486b..3c47fa7a7 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -57,30 +57,6 @@ VSimpleCurve::VSimpleCurve(quint32 id, const QSharedPointer &cur this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus } -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - qreal width = 1; - if (m_isHovered) - { - width = widthMainLine; - } - else - { - width = widthHairLine; - } - - const qreal scale = SceneScale(scene()); - if (scale > 1) - { - width = qMax(1., width/scale); - } - - setPen(QPen(CorrectColor(this, m_curve->GetColor()), width, LineStyleToPenStyle(m_curve->GetPenStyle()))); - - VCurvePathItem::paint(painter, option, widget); -} - //--------------------------------------------------------------------------------------------------------------------- void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) { @@ -191,3 +167,20 @@ void VSimpleCurve::keyReleaseEvent(QKeyEvent *event) } QGraphicsPathItem::keyReleaseEvent ( event ); } + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::ScalePenWidth() +{ + qreal width = 1; + if (m_isHovered) + { + width = widthMainLine; + } + else + { + width = widthHairLine; + } + + width = ScaleWidth(width, SceneScale(scene())); + setPen(QPen(CorrectColor(this, m_curve->GetColor()), width, LineStyleToPenStyle(m_curve->GetPenStyle()))); +} diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h index db9c9aa44..6401f68d4 100644 --- a/src/libs/vwidgets/vsimplecurve.h +++ b/src/libs/vwidgets/vsimplecurve.h @@ -56,9 +56,6 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimpleCurve)}; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = nullptr) Q_DECL_OVERRIDE; - void RefreshGeometry(const QSharedPointer &curve); signals: /** @@ -80,6 +77,7 @@ protected: virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent ( QKeyEvent * event ) Q_DECL_OVERRIDE; + virtual void ScalePenWidth() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VSimpleCurve) diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 059b41e4e..36a06b93d 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -20,7 +20,8 @@ SOURCES += \ $$PWD/fancytabbar/stylehelper.cpp \ $$PWD/vcurvepathitem.cpp \ $$PWD/global.cpp \ - $$PWD/vscenepoint.cpp + $$PWD/vscenepoint.cpp \ + $$PWD/scalesceneitems.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -44,4 +45,5 @@ HEADERS += \ $$PWD/fancytabbar/stylehelper.h \ $$PWD/vcurvepathitem.h \ $$PWD/global.h \ - $$PWD/vscenepoint.h + $$PWD/vscenepoint.h \ + $$PWD/scalesceneitems.h