From 4e4deeb2e5ae3b71bc59b3199545723fae09e725 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 15 Jun 2015 12:32:27 +0300 Subject: [PATCH] Refactoring. More independent class VSimpleCurve. --HG-- branch : feature --- src/app/core/vapplication.cpp | 29 ++---------------- src/app/core/vapplication.h | 16 ---------- src/app/mainwindowsnogui.cpp | 22 +++++++------- src/app/tools/drawTools/vabstractspline.cpp | 15 ++++++---- src/app/tools/drawTools/vtoolarc.cpp | 5 ++-- .../tools/drawTools/vtoolarcwithlength.cpp | 5 ++-- src/app/tools/drawTools/vtoolcut.cpp | 6 ++-- src/app/tools/drawTools/vtoolline.cpp | 12 +++++--- src/app/tools/drawTools/vtoollinepoint.cpp | 9 ++++-- src/app/tools/drawTools/vtoolpoint.cpp | 16 ++++++---- src/app/tools/drawTools/vtoolsinglepoint.cpp | 4 +-- src/app/tools/drawTools/vtoolspline.cpp | 11 ++++--- src/app/tools/drawTools/vtoolsplinepath.cpp | 10 ++++--- src/app/tools/nodeDetails/vnodearc.cpp | 6 ++-- src/app/tools/nodeDetails/vnodepoint.cpp | 6 ++-- src/app/tools/nodeDetails/vnodespline.cpp | 6 ++-- src/app/tools/nodeDetails/vnodesplinepath.cpp | 6 ++-- src/app/visualization/vcontrolpointspline.cpp | 17 ++++++----- src/app/visualization/vcontrolpointspline.h | 4 ++- src/app/visualization/visline.cpp | 3 +- src/app/visualization/vispath.cpp | 3 +- src/app/visualization/vistoolline.cpp | 2 +- src/app/visualization/vistooltriangle.cpp | 2 +- src/app/visualization/visualization.cpp | 9 +++--- src/app/visualization/visualization.h | 5 ++-- src/app/visualization/vsimplecurve.cpp | 21 +++++++------ src/app/visualization/vsimplecurve.h | 6 ++-- src/libs/ifc/ifcdef.cpp | 30 +++++++++++++++++++ src/libs/ifc/ifcdef.h | 3 ++ 29 files changed, 156 insertions(+), 133 deletions(-) diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index ccbbeb309..e88a8e4cd 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -157,9 +157,8 @@ const QString VApplication::GistFileName = QStringLiteral("gist.json"); */ VApplication::VApplication(int &argc, char **argv) : QApplication(argc, argv), _patternUnit(Unit::Cm), _patternType(MeasurementsType::Individual), - _widthMainLine(DefWidth), _widthHairLine(DefWidth/3.0), trVars(nullptr), - undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), autoSaveTimer(nullptr), mainWindow(nullptr), - openingPattern(false), settings(nullptr), doc(nullptr), log(nullptr), + trVars(nullptr), undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), autoSaveTimer(nullptr), + mainWindow(nullptr), openingPattern(false), settings(nullptr), doc(nullptr), log(nullptr), #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) out(nullptr), logLock(nullptr) #else @@ -167,8 +166,6 @@ VApplication::VApplication(int &argc, char **argv) #endif { undoStack = new QUndoStack(this); - - InitLineWidth(); } //--------------------------------------------------------------------------------------------------------------------- @@ -349,27 +346,6 @@ QString VApplication::translationsPath() const #endif } -//--------------------------------------------------------------------------------------------------------------------- -void VApplication::InitLineWidth() -{ - switch (_patternUnit) - { - case Unit::Mm: - _widthMainLine = DefWidth; - break; - case Unit::Cm: - _widthMainLine = DefWidth/10.0; - break; - case Unit::Inch: - _widthMainLine = DefWidth/25.4; - break; - default: - _widthMainLine = DefWidth; - break; - } - _widthHairLine = _widthMainLine/3.0; -} - //--------------------------------------------------------------------------------------------------------------------- QString VApplication::LogDirPath() const { @@ -493,7 +469,6 @@ void VApplication::ClearOldLogs() const void VApplication::setPatternUnit(const Unit &patternUnit) { _patternUnit = patternUnit; - InitLineWidth(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 98ff39415..e3086722b 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -77,8 +77,6 @@ public: #endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) QString translationsPath() const; - qreal widthMainLine() const; - qreal widthHairLine() const; template QString LocaleToString(const T &value) @@ -133,8 +131,6 @@ private: Q_DISABLE_COPY(VApplication) Unit _patternUnit; MeasurementsType _patternType; - qreal _widthMainLine; - qreal _widthHairLine; VTranslateVars *trVars; QUndoStack *undoStack; VMainGraphicsView *sceneView; @@ -204,18 +200,6 @@ inline void VApplication::setPatternType(const MeasurementsType &patternType) _patternType = patternType; } -//--------------------------------------------------------------------------------------------------------------------- -inline qreal VApplication::widthMainLine() const -{ - return _widthMainLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline qreal VApplication::widthHairLine() const -{ - return _widthHairLine; -} - //--------------------------------------------------------------------------------------------------------------------- inline QUndoStack *VApplication::getUndoStack() const { diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index cc97757b1..55b3f5721 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -400,8 +400,8 @@ QIcon MainWindowsNoGUI::ScenePreview(int i) const QPainter painter(&image); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter); painter.end(); @@ -508,8 +508,8 @@ void MainWindowsNoGUI::SvgFile(const QString &name, int i) const painter.begin(&generator); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); painter.end(); @@ -533,8 +533,8 @@ void MainWindowsNoGUI::PngFile(const QString &name, int i) const QPainter painter(&image); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); image.save(name); @@ -577,8 +577,8 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const } painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); painter.end(); @@ -685,15 +685,15 @@ QVector MainWindowsNoGUI::AllSheets() QPainter painter(&image); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap, - Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter); painter.end(); images.append(image); // Resore - paper->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); + paper->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())))); brush->setColor( QColor( Qt::gray ) ); brush->setStyle( Qt::SolidPattern ); scenes[i]->setBackgroundBrush( *brush ); diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index b62894c23..8d5840880 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -75,7 +75,8 @@ void VAbstractSpline::Disable(bool disable, const QString &namePP) { enabled = !CorrectDisable(disable, namePP); this->setEnabled(enabled); - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor, Qt::SolidLine, + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine, Qt::RoundCap)); emit setEnabledPoint(enabled); } @@ -119,7 +120,8 @@ void VAbstractSpline::SetFactor(qreal factor) void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine, + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine, Qt::RoundCap)); this->setPath(ToolPath(PathDirection::Show)); isHovered = true; @@ -135,7 +137,8 @@ void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (detailsMode) { this->setPath(ToolPath(PathDirection::Show)); @@ -244,10 +247,12 @@ void VAbstractSpline::setEnabled(bool enabled) QGraphicsPathItem::setEnabled(enabled); if (enabled) { - setPen(QPen(QColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + setPen(QPen(QColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } else { - setPen(QPen(Qt::gray, qApp->toPixel(qApp->widthHairLine())/factor)); + setPen(QPen(Qt::gray, + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } } diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index b4c77d517..3bcc3c0ab 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -55,7 +55,7 @@ VToolArc::VToolArc(VPattern *doc, VContainer *data, quint32 id, const QString &c lineColor = color; this->setPath(ToolPath()); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); @@ -358,7 +358,8 @@ void VToolArc::SetVisualization() */ void VToolArc::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setPath(ToolPath()); SetVisualization(); diff --git a/src/app/tools/drawTools/vtoolarcwithlength.cpp b/src/app/tools/drawTools/vtoolarcwithlength.cpp index af2a1ed3c..17e03582f 100644 --- a/src/app/tools/drawTools/vtoolarcwithlength.cpp +++ b/src/app/tools/drawTools/vtoolarcwithlength.cpp @@ -47,7 +47,7 @@ VToolArcWithLength::VToolArcWithLength(VPattern *doc, VContainer *data, quint32 lineColor = color; this->setPath(ToolPath()); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); @@ -312,7 +312,8 @@ void VToolArcWithLength::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- void VToolArcWithLength::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setPath(ToolPath()); SetVisualization(); diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index 746533674..e6a2fce65 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -43,14 +43,16 @@ VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QSt lineColor = color; - firstCurve = new VSimpleCurve(curve1id, QColor(lineColor), SimpleCurvePoint::ForthPoint, &factor); + firstCurve = new VSimpleCurve(curve1id, QColor(lineColor), SimpleCurvePoint::ForthPoint, *data->GetPatternUnit(), + &factor); firstCurve->setParentItem(this); connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); // TODO: Now we only hide simple curves, but in future need totally delete them all. firstCurve->setVisible(false); - secondCurve = new VSimpleCurve(curve2id, QColor(lineColor), SimpleCurvePoint::FirstPoint, &factor); + secondCurve = new VSimpleCurve(curve2id, QColor(lineColor), SimpleCurvePoint::FirstPoint, *data->GetPatternUnit(), + &factor); secondCurve->setParentItem(this); connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index d8de28978..0ef1cbfe7 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -62,7 +62,8 @@ VToolLine::VToolLine(VPattern *doc, VContainer *data, quint32 id, quint32 firstP this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setAcceptHoverEvents(true); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, + LineStyleToPenStyle(typeLine))); ToolCreation(typeCreation); } @@ -218,7 +219,8 @@ void VToolLine::Disable(bool disable, const QString &namePP) { enabled = !CorrectDisable(disable, namePP); this->setEnabled(enabled); - this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor, + this->setPen(QPen(CorrectColor(baseColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); } @@ -270,7 +272,8 @@ void VToolLine::RefreshDataInFile() void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthMainLine())/factor, + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); } @@ -284,7 +287,8 @@ void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if (vis == nullptr) { - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor, + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); } } diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 698bfcb85..2a13dbc0b 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -54,7 +54,8 @@ VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &i QPointF point1 = data->GeometricObject(basePointId)->toQPointF(); QPointF point2 = data->GeometricObject(id)->toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor, LineStyleToPenStyle(typeLine))); + mainLine->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, + LineStyleToPenStyle(typeLine))); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -70,7 +71,8 @@ VToolLinePoint::~VToolLinePoint() */ void VToolLinePoint::RefreshGeometry() { - mainLine->setPen(QPen(CorrectColor(QColor(lineColor)), qApp->toPixel(qApp->widthHairLine())/factor, + mainLine->setPen(QPen(CorrectColor(QColor(lineColor)), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); @@ -111,7 +113,8 @@ void VToolLinePoint::SetFactor(qreal factor) void VToolLinePoint::Disable(bool disable, const QString &namePP) { VToolPoint::Disable(disable, namePP); - mainLine->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor, + mainLine->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, LineStyleToPenStyle(typeLine))); mainLine->setEnabled(enabled); } diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 33a9fac30..d25bb9f07 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -221,7 +221,8 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthMainLine())/factor)); + this->setPen(QPen(CorrectColor(baseColor), + qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor)); QGraphicsEllipseItem::hoverEnterEvent(event); } @@ -233,7 +234,8 @@ void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(baseColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); QGraphicsEllipseItem::hoverLeaveEvent(event); } @@ -245,7 +247,8 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolPoint::RefreshPointGeometry(const VPointF &point) { this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(baseColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); @@ -277,7 +280,8 @@ void VToolPoint::RefreshLine() VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - lineName->setPen(QPen(CorrectColor(Qt::black), qApp->toPixel(qApp->widthHairLine())/factor)); + lineName->setPen(QPen(CorrectColor(Qt::black), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) { @@ -362,10 +366,10 @@ void VToolPoint::setEnabled(bool enabled) QGraphicsEllipseItem::setEnabled(enabled); if (enabled) { - setPen(QPen(QColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); + setPen(QPen(QColor(baseColor), qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } else { - setPen(QPen(Qt::gray, qApp->toPixel(qApp->widthHairLine())/factor)); + setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } } diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 5c025facc..7e5ec1a34 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -53,7 +53,7 @@ VToolSinglePoint::VToolSinglePoint (VPattern *doc, VContainer *data, quint32 id, :VToolPoint(doc, data, id, parent), namePP(namePP), mPath(mPath) { baseColor = Qt::red; - this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, false); @@ -258,7 +258,7 @@ void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VToolSinglePoint::SetColorLabel(const Qt::GlobalColor &color) { namePoint->setBrush(color); - lineName->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); + lineName->setPen(QPen(color, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index d87d5d2bb..5ab843269 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -57,7 +57,7 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const QStr sceneType = SceneObject::Spline; lineColor = color; - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -66,7 +66,8 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const QStr const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); VControlPointSpline *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, spl->GetP2(), - spl->GetP1().toQPointF(), this); + spl->GetP1().toQPointF(), *data->GetPatternUnit(), + this); connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); connect(this, &VToolSpline::RefreshLine, controlPoint1, &VControlPointSpline::RefreshLine); @@ -75,7 +76,8 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const QStr controlPoints.append(controlPoint1); VControlPointSpline *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, spl->GetP3(), - spl->GetP4().toQPointF(), this); + spl->GetP4().toQPointF(), *data->GetPatternUnit(), + this); connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); connect(this, &VToolSpline::RefreshLine, controlPoint2, &VControlPointSpline::RefreshLine); @@ -467,7 +469,8 @@ void VToolSpline::SetVisualization() */ void VToolSpline::RefreshGeometry() { - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); if (isHovered || detailsMode) { this->setPath(ToolPath(PathDirection::Show)); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 6e6915041..45c0a6fa1 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -56,7 +56,7 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co lineColor = color; this->setPath(ToolPath()); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -67,7 +67,8 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co { VSpline spl = splPath->GetSpline(i); VControlPointSpline *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, spl.GetP2(), - spl.GetP1().toQPointF(), this); + spl.GetP1().toQPointF(), *data->GetPatternUnit(), + this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); @@ -76,7 +77,7 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co controlPoints.append(controlPoint); controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, spl.GetP3(), spl.GetP4().toQPointF(), - this); + *data->GetPatternUnit(), this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); connect(this, &VToolSplinePath::RefreshLine, controlPoint, &VControlPointSpline::RefreshLine); @@ -548,7 +549,8 @@ void VToolSplinePath::RefreshGeometry() { this->setPath(ToolPath()); } - this->setPen(QPen(CorrectColor(lineColor), qApp->toPixel(qApp->widthHairLine())/factor)); + this->setPen(QPen(CorrectColor(lineColor), + qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); const QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); for (qint32 i = 1; i<=splPath->Count(); ++i) { diff --git a/src/app/tools/nodeDetails/vnodearc.cpp b/src/app/tools/nodeDetails/vnodearc.cpp index 23158b6da..0c760a23a 100644 --- a/src/app/tools/nodeDetails/vnodearc.cpp +++ b/src/app/tools/nodeDetails/vnodearc.cpp @@ -53,7 +53,7 @@ VNodeArc::VNodeArc(VPattern *doc, VContainer *data, quint32 id, quint32 idArc, c :VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); ToolCreation(typeCreation); } @@ -191,7 +191,7 @@ void VNodeArc::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- @@ -202,7 +202,7 @@ void VNodeArc::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index 3318a0e63..93a521acf 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -60,7 +60,7 @@ VNodePoint::VNodePoint(VPattern *doc, VContainer *data, quint32 id, quint32 idPo lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VNodePoint::NameChangePosition); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setAcceptHoverEvents(true); @@ -208,7 +208,7 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- @@ -219,7 +219,7 @@ void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/nodeDetails/vnodespline.cpp b/src/app/tools/nodeDetails/vnodespline.cpp index ce231ed51..8d2e52b59 100644 --- a/src/app/tools/nodeDetails/vnodespline.cpp +++ b/src/app/tools/nodeDetails/vnodespline.cpp @@ -54,7 +54,7 @@ VNodeSpline::VNodeSpline(VPattern *doc, VContainer *data, quint32 id, quint32 id :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); ToolCreation(typeCreation); } @@ -193,7 +193,7 @@ void VNodeSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- @@ -204,7 +204,7 @@ void VNodeSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/nodeDetails/vnodesplinepath.cpp b/src/app/tools/nodeDetails/vnodesplinepath.cpp index c3aac3c0c..6614c09a0 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/app/tools/nodeDetails/vnodesplinepath.cpp @@ -54,7 +54,7 @@ VNodeSplinePath::VNodeSplinePath(VPattern *doc, VContainer *data, quint32 id, qu :VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent) { RefreshGeometry(); - this->setPen(QPen(baseColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); ToolCreation(typeCreation); } @@ -196,7 +196,7 @@ void VNodeSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- @@ -207,7 +207,7 @@ void VNodeSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index 5b1a91d48..469f9328d 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -44,16 +44,17 @@ * @param parent parent object. */ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, - const QPointF &controlPoint, const QPointF &splinePoint, + const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit, QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position) + :QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position), + patternUnit(patternUnit) { //create circle radius = (1.5/*mm*/ / 25.4) * PrintDPI; QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); this->setBrush(QBrush(Qt::NoBrush)); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -65,7 +66,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP QPointF p1, p2; VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); controlLine = new QGraphicsLineItem(QLineF(splinePoint-controlPoint, p1), this); - controlLine->setPen(QPen(Qt::red, qApp->toPixel(qApp->widthHairLine()))); + controlLine->setPen(QPen(Qt::red, qApp->toPixel(WidthHairLine(patternUnit)))); controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -96,7 +97,7 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte */ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(patternUnit)))); VApplication::setOverrideCursor(cursorArrowOpenHand, 1, 1); QGraphicsEllipseItem::hoverEnterEvent(event); } @@ -104,7 +105,7 @@ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); //Disable cursor-arrow-openhand VApplication::restoreOverrideCursor(cursorArrowOpenHand); QGraphicsEllipseItem::hoverLeaveEvent(event); @@ -183,14 +184,14 @@ void VControlPointSpline::setEnabledPoint(bool enable) { if (enable == true) { - this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(patternUnit)))); this->setFlag(QGraphicsItem::ItemIsSelectable, true); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setAcceptHoverEvents(true); } else { - this->setPen(QPen(Qt::gray, qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(patternUnit)))); this->setFlag(QGraphicsItem::ItemIsSelectable, false); this->setFlag(QGraphicsItem::ItemIsMovable, false); this->setAcceptHoverEvents(false); diff --git a/src/app/visualization/vcontrolpointspline.h b/src/app/visualization/vcontrolpointspline.h index 1b5c99ded..f4416a6c2 100644 --- a/src/app/visualization/vcontrolpointspline.h +++ b/src/app/visualization/vcontrolpointspline.h @@ -42,7 +42,7 @@ class VControlPointSpline : public QObject, public QGraphicsEllipseItem Q_OBJECT public: VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, - const QPointF &splinePoint, QGraphicsItem * parent = nullptr); + const QPointF &splinePoint, Unit patternUnit, QGraphicsItem * parent = nullptr); virtual ~VControlPointSpline(); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual int type() const {return Type;} @@ -85,6 +85,8 @@ private: /** @brief position position point in spline. */ SplinePointPosition position; + + Unit patternUnit; }; #endif // VCONTROLPOINTSPLINE_H diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index 82009a6e4..c87778efc 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -120,7 +120,8 @@ QLineF VisLine::Axis(const QPointF &p1, const QPointF &p2) const //--------------------------------------------------------------------------------------------------------------------- void VisLine::InitPen() { - this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); + this->setPen(QPen(mainColor, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, + lineStyle)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vispath.cpp b/src/app/visualization/vispath.cpp index b93549394..5fd99a48c 100644 --- a/src/app/visualization/vispath.cpp +++ b/src/app/visualization/vispath.cpp @@ -43,7 +43,8 @@ VisPath::~VisPath() //--------------------------------------------------------------------------------------------------------------------- void VisPath::InitPen() { - this->setPen(QPen(mainColor, qApp->toPixel(qApp->widthHairLine())/factor, lineStyle)); + this->setPen(QPen(mainColor, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, + lineStyle)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolline.cpp b/src/app/visualization/vistoolline.cpp index 3f41397aa..2d5ffa637 100644 --- a/src/app/visualization/vistoolline.cpp +++ b/src/app/visualization/vistoolline.cpp @@ -70,6 +70,6 @@ void VisToolLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, cons { SCASSERT (lineItem != nullptr); - lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style)); + lineItem->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style)); lineItem->setLine(line); } diff --git a/src/app/visualization/vistooltriangle.cpp b/src/app/visualization/vistooltriangle.cpp index db490e095..5177aabe9 100644 --- a/src/app/visualization/vistooltriangle.cpp +++ b/src/app/visualization/vistooltriangle.cpp @@ -135,7 +135,7 @@ void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, { SCASSERT (item != nullptr); - item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); + item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style)); QPainterPath path; path.moveTo(line.p1()); diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp index 90cc7797f..8b78e2d08 100644 --- a/src/app/visualization/visualization.cpp +++ b/src/app/visualization/visualization.cpp @@ -109,7 +109,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); point->setZValue(1); point->setBrush(QBrush(Qt::NoBrush)); - point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor)); + point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor)); point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); point->setFlags(QGraphicsItem::ItemStacksBehindParent); point->setVisible(false); @@ -169,7 +169,7 @@ void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, c SCASSERT (point != nullptr); point->setPos(pos); - point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style)); + point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style)); point->setVisible(true); } @@ -178,7 +178,7 @@ void Visualization::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, co { SCASSERT (lineItem != nullptr); - lineItem->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor, style)); + lineItem->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style)); lineItem->setLine(line); lineItem->setVisible(true); } @@ -189,7 +189,8 @@ void Visualization::DrawPath(QGraphicsPathItem *pathItem, const QPainterPath &pa { SCASSERT (pathItem != nullptr); - pathItem->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor, style, cap)); + pathItem->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style, + cap)); pathItem->setPath(path); pathItem->setVisible(true); } diff --git a/src/app/visualization/visualization.h b/src/app/visualization/visualization.h index 5596084db..3f9a414b9 100644 --- a/src/app/visualization/visualization.h +++ b/src/app/visualization/visualization.h @@ -35,11 +35,10 @@ #include "../core/vapplication.h" #include "../widgets/vmaingraphicsscene.h" #include "../../utils/logging.h" +#include "../../libs/vpatterndb/vcontainer.h" Q_DECLARE_LOGGING_CATEGORY(vVis) -class VContainer; - class Visualization : public QObject { Q_OBJECT @@ -99,7 +98,7 @@ protected: Item *InitItem(const QColor &color, QGraphicsItem *parent) { Item *item = new Item(parent); - item->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); + item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*data->GetPatternUnit()))/factor)); item->setZValue(1); item->setFlags(QGraphicsItem::ItemStacksBehindParent); item->setVisible(false); diff --git a/src/app/visualization/vsimplecurve.cpp b/src/app/visualization/vsimplecurve.cpp index 729539d1d..aecd703c5 100644 --- a/src/app/visualization/vsimplecurve.cpp +++ b/src/app/visualization/vsimplecurve.cpp @@ -27,7 +27,6 @@ *************************************************************************/ #include "vsimplecurve.h" -#include "../core/vapplication.h" #include #include #include @@ -40,18 +39,18 @@ * @param currentColor current color. * @param parent parent object. */ -VSimpleCurve::VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint pointPosition, qreal *factor, - QObject *parent) +VSimpleCurve::VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint pointPosition, Unit patternUnit, + qreal *factor, QObject *parent) :QObject(parent), QGraphicsPathItem(), id (id), factor(factor), currentColor(currentColor), - curvePosition(pointPosition), enabled(true) + curvePosition(pointPosition), enabled(true), patternUnit(patternUnit) { if (factor == nullptr) { - setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine()))); + setPen(QPen(currentColor, ToPixel(WidthHairLine(patternUnit), patternUnit))); } else { - setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); + setPen(QPen(currentColor, ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor)); } setFlag(QGraphicsItem::ItemIsSelectable, true); setAcceptHoverEvents(true); @@ -62,7 +61,7 @@ void VSimpleCurve::ChangedActivDraw(const bool &flag) { enabled = flag; setEnabled(enabled); - setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); + setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor)); } //--------------------------------------------------------------------------------------------------------------------- @@ -102,11 +101,11 @@ void VSimpleCurve::hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if (factor == nullptr) { - this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthMainLine()))); + this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthMainLine(patternUnit), patternUnit))); } else { - this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthMainLine())/ *factor)); + this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthMainLine(patternUnit), patternUnit)/ *factor)); } emit HoverPath(id, curvePosition, PathDirection::Show); } @@ -121,11 +120,11 @@ void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if (factor == nullptr) { - this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine()))); + this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit))); } else { - this->setPen(QPen(CorrectColor(currentColor), qApp->toPixel(qApp->widthHairLine())/ *factor)); + this->setPen(QPen(CorrectColor(currentColor), ToPixel(WidthHairLine(patternUnit), patternUnit)/ *factor)); } emit HoverPath(id, curvePosition, PathDirection::Hide); diff --git a/src/app/visualization/vsimplecurve.h b/src/app/visualization/vsimplecurve.h index 78279336c..4c2b6ff80 100644 --- a/src/app/visualization/vsimplecurve.h +++ b/src/app/visualization/vsimplecurve.h @@ -31,7 +31,7 @@ #include #include "../libs/vgeometry/vabstractcurve.h" -#include "../options.h" +#include "../../utils/def.h" enum class SimpleCurvePoint : char { FirstPoint, ForthPoint }; @@ -42,7 +42,7 @@ class VSimpleCurve : public QObject, public QGraphicsPathItem { Q_OBJECT public: - VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint curvePosition, + VSimpleCurve(quint32 id, QColor currentColor, SimpleCurvePoint curvePosition, Unit patternUnit, qreal *factor = nullptr, QObject *parent = 0); void ChangedActivDraw(const bool &flag); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); @@ -80,6 +80,8 @@ private: bool enabled; + Unit patternUnit; + QColor CorrectColor(const QColor &color) const; }; diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index 75410d596..5ed716df4 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -29,3 +29,33 @@ #include "ifcdef.h" const qreal PrintDPI = 96.0; + +#define DefWidth 1.2//mm + +//--------------------------------------------------------------------------------------------------------------------- +qreal WidthMainLine(Unit patternUnit) +{ + qreal _widthMainLine = DefWidth; + switch (patternUnit) + { + case Unit::Mm: + _widthMainLine = DefWidth; + break; + case Unit::Cm: + _widthMainLine = DefWidth/10.0; + break; + case Unit::Inch: + _widthMainLine = DefWidth/25.4; + break; + default: + _widthMainLine = DefWidth; + break; + } + return _widthMainLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal WidthHairLine(Unit patternUnit) +{ + return WidthMainLine(patternUnit)/3.0; +} diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 7777bd572..adac8e6d2 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -61,6 +61,9 @@ static const quint32 null_id = 0; extern const qreal PrintDPI; +qreal WidthMainLine(Unit patternUnit); +qreal WidthHairLine(Unit patternUnit); + //--------------------------------------------------------------------------------------------------------------------- inline double ToPixel(double val, const Unit &unit) {