diff --git a/ChangeLog.txt b/ChangeLog.txt index 13044b5cc..0227fb844 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,7 @@ - [#682] New feature. Export increments to Excel .csv. - [#681] Enhance feature: Dashed line options for curves, arcs, etc. - [#684] Proposal: Add option to only show outer edges on detail. +- [#244] New feature: Adjust line and point thickness and label size. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 4ef3a00c5..95f172b87 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -281,7 +281,6 @@ void MainWindow::AddPP(const QString &PPName) // Show best for new PP VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view); ui->view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio); - ui->view->NewFactor(ui->view->transform().m11()); ui->actionNewDraw->setEnabled(true); helpLabel->setText(""); @@ -356,7 +355,6 @@ void MainWindow::InitScenes() sceneDraw->setTransform(ui->view->transform()); sceneDetails->setTransform(ui->view->transform()); - connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); connect(ui->view, &VMainGraphicsView::MouseRelease, this, [this](){EndVisualization(true);}); QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); policy.setHorizontalStretch(12); @@ -2261,8 +2259,6 @@ void MainWindow::ActionDraw(bool checked) currentScene = sceneDraw; ui->view->setScene(currentScene); - connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor, - Qt::UniqueConnection); RestoreCurrentScene(); mode = Draw::Calculation; @@ -2336,7 +2332,6 @@ void MainWindow::ActionDetails(bool checked) currentScene = sceneDetails; ui->view->itemClicked(nullptr); ui->view->setScene(currentScene); - disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); if (mode == Draw::Calculation) @@ -2451,7 +2446,6 @@ void MainWindow::ActionLayout(bool checked) currentScene = tempSceneLayout; ui->view->itemClicked(nullptr); ui->view->setScene(currentScene); - disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); if (mode == Draw::Calculation) { @@ -4587,7 +4581,6 @@ void MainWindow::ChangePP(int index, bool zoomBestFit) if (zoomBestFit) { ui->view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio); - ui->view->NewFactor(ui->view->transform().m11()); } } toolOptions->itemClicked(nullptr);//hide options for tool in previous pattern piece diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index b644fcd07..76a521000 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -302,8 +302,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); int count = 0; @@ -518,8 +517,7 @@ 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(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); painter.end(); @@ -599,8 +597,7 @@ 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(WidthHairLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthHairLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); painter.end(); @@ -624,8 +621,7 @@ 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(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); image.save(name); @@ -671,8 +667,7 @@ 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(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); painter.end(); @@ -827,7 +822,7 @@ void MainWindowsNoGUI::RestorePaper(int index) const if (paper) { // Restore - paper->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())))); + paper->setPen(QPen(Qt::black, widthMainLine)); QBrush brush(Qt::gray); scenes.at(index)->setBackgroundBrush(brush); shadows.at(index)->setVisible(true); @@ -1063,8 +1058,7 @@ bool MainWindowsNoGUI::IsLayoutGrayscale() const QImage image(target.size(), QImage::Format_RGB32); image.fill(Qt::white); QPainter painter(&image); - painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); + painter.setPen(QPen(Qt::black, widthMainLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); scenes.at(i)->render(&painter, target, paper->rect(), Qt::KeepAspectRatio); painter.end(); diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index c757c5c86..81e2dbf5a 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -43,33 +43,7 @@ const QString CustomMSign = QStringLiteral("@"); const QString CustomIncrSign = QStringLiteral("#"); -#define DefWidth 1.2//mm -//--------------------------------------------------------------------------------------------------------------------- -qreal WidthMainLine(Unit patternUnit) -{ - qreal _widthMainLine = DefWidth; - switch (patternUnit) - { - case Unit::Cm: - _widthMainLine = DefWidth/10.0; - break; - case Unit::Inch: - _widthMainLine = DefWidth/25.4; - break; - case Unit::Mm: - default: - _widthMainLine = DefWidth; - break; - } - return _widthMainLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal WidthHairLine(Unit patternUnit) -{ - return WidthMainLine(patternUnit)/3.0; -} const QString AttrType = QStringLiteral("type"); const QString AttrMx = QStringLiteral("mx"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 3db1f37ba..404857ba1 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -63,9 +63,6 @@ static const quint32 null_id = 0; # define V_NOEXCEPT_EXPR(x) # endif -qreal WidthMainLine(Unit patternUnit); -qreal WidthHairLine(Unit patternUnit); - extern const QString AttrType; extern const QString AttrMx; extern const QString AttrMy; diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 3e8e424e9..e9e7b3736 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -322,15 +322,6 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) return 0; } -//--------------------------------------------------------------------------------------------------------------------- -void CheckFactor(qreal &oldFactor, const qreal &Newfactor) -{ - if (Newfactor <= 2 && Newfactor >= 0.5) - { - oldFactor = Newfactor; - } -} - //--------------------------------------------------------------------------------------------------------------------- QStringList SupportedLocales() { diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 875a07272..ee1d0e805 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -53,7 +53,6 @@ class QMarginsF; class VTranslateMeasurements; #define SceneSize 50000 -#define DefPointRadius 1.5//mm enum class NodeDetail : char { Contour, Modeling }; enum class SceneObject : char { Point, Line, Spline, Arc, ElArc, SplinePath, Detail, Unknown }; @@ -374,8 +373,6 @@ double FromPixel(double pix, const Unit &unit) Q_REQUIRED_RESULT; qreal UnitConvertor(qreal value, const Unit &from, const Unit &to) Q_REQUIRED_RESULT; -void CheckFactor(qreal &oldFactor, const qreal &Newfactor); - void InitLanguages(QComboBox *combobox); QStringList SupportedLocales() Q_REQUIRED_RESULT; diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index aa8f0745a..07af45d5b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -206,8 +206,7 @@ void DialogCurveIntersectAxis::ShowDialog(bool click) QLineF line = QLineF(static_cast(*point), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; - if (line.length() <= radius) + if (line.length() <= defPointRadiusPixel*1.5) { return; } diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index 9de1fb0d2..43f76af37 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -316,8 +316,7 @@ void DialogEndLine::ShowDialog(bool click) QLineF line = QLineF(static_cast(*point), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - const qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; - if (line.length() <= radius) + if (line.length() <= defPointRadiusPixel*1.5) { return; } diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp index 74e0c5f6f..ee112c50b 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp @@ -236,8 +236,7 @@ void DialogLineIntersectAxis::ShowDialog(bool click) QLineF line = QLineF(static_cast(*point), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; - if (line.length() <= radius) + if (line.length() <= defPointRadiusPixel*1.5) { return; } diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 075b8f2a7..476e27e2a 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -216,8 +216,7 @@ void DialogRotation::ShowDialog(bool click) const QLineF line = QLineF(static_cast(*point), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - const qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; - if (line.length() <= radius) + if (line.length() <= defPointRadiusPixel*1.5) { return; } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index d6d60f1e7..aeaeeb57d 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -394,7 +394,6 @@ inline void DialogTool::AddVisualization() if (not scene->items().contains(toolVis)) { - connect(scene, &VMainGraphicsScene::NewFactor, toolVis, &Visualization::SetFactor); scene->addItem(toolVis); } diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 5cb6bd504..0eba8ab0c 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -40,12 +40,6 @@ QString VAbstractOperation::getTagName() const return VAbstractPattern::TagOperation; } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::SetEnabled(bool enabled) -{ - this->setEnabled(enabled); -} - //--------------------------------------------------------------------------------------------------------------------- QString VAbstractOperation::Suffix() const { @@ -144,7 +138,7 @@ void VAbstractOperation::FullUpdateFromFile() { VSimplePoint *item = qobject_cast(i.value()); SCASSERT(item != nullptr) - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); + item->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(i.key())); } else { @@ -156,29 +150,6 @@ void VAbstractOperation::FullUpdateFromFile() SetVisualization(); } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractOperation::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - QMapIterator i(operatedObjects); - while (i.hasNext()) - { - i.next(); - if (i.value()->GetType() == GOType::Point) - { - VSimplePoint *item = qobject_cast(i.value()); - SCASSERT(item != nullptr) - item->RefreshGeometry(*VAbstractTool::data.GeometricObject(i.key())); - } - else - { - VSimpleCurve *item = qobject_cast(i.value()); - SCASSERT(item != nullptr) - item->RefreshGeometry(VAbstractTool::data.GeometricObject(i.key())); - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::AllowHover(bool enabled) { @@ -371,14 +342,25 @@ void VAbstractOperation::ToolSelectionType(const SelectionType &type) //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::Disable(bool disable, const QString &namePP) { - enabled = !CorrectDisable(disable, namePP); - SetEnabled(enabled); + const bool enabled = !CorrectDisable(disable, namePP); + setEnabled(enabled); QMapIterator i(operatedObjects); while (i.hasNext()) { i.next(); - i.value()->SetEnabled(enabled); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr) + item->SetEnabled(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr) + item->setEnabled(enabled); + } } } @@ -499,7 +481,7 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag) VSimpleCurve *VAbstractOperation::InitCurve(quint32 id, VContainer *data, GOType curveType) { const QSharedPointer initCurve = data->GeometricObject(id); - VSimpleCurve *curve = new VSimpleCurve(id, initCurve, *data->GetPatternUnit(), &factor); + VSimpleCurve *curve = new VSimpleCurve(id, initCurve); curve->setParentItem(this); curve->SetType(curveType); connect(curve, &VSimpleCurve::Selected, this, &VAbstractOperation::ObjectSelected); @@ -526,7 +508,7 @@ void VAbstractOperation::DoChangePosition(quint32 id, qreal mx, qreal my) VSimplePoint *item = qobject_cast(operatedObjects.value(id)); SCASSERT(item != nullptr) - item->RefreshGeometry(*point); + item->RefreshPointGeometry(*point); } } @@ -593,8 +575,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") { case GOType::Point: { - VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), - *VAbstractTool::data.GetPatternUnit(), &factor); + VSimplePoint *point = new VSimplePoint(object.id, QColor(Qt::black)); point->setParentItem(this); point->SetType(GOType::Point); connect(point, &VSimplePoint::Choosed, this, [this](quint32 id) @@ -609,7 +590,7 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") }); connect(point, &VSimplePoint::Delete, this, &VAbstractOperation::DeleteFromLabel); connect(point, &VSimplePoint::NameChangedPosition, this, &VAbstractOperation::LabelChangePosition); - point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + point->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(object.id)); operatedObjects.insert(object.id, point); break; } diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 689bf28c8..fdc61dea7 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -67,8 +67,6 @@ public: virtual QString getTagName() const Q_DECL_OVERRIDE; - void SetEnabled(bool enabled); - QString Suffix() const; void SetSuffix(const QString &suffix); @@ -79,7 +77,6 @@ public: QVector &destination); public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 8e8c36a6c..f1cab38eb 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -44,7 +44,6 @@ #include "../ifc/exception/vexceptionbadid.h" #include "../ifc/xml/vabstractpattern.h" #include "../qmuparser/qmutokenparser.h" -#include "../vgeometry/../ifc/ifcdef.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" #include "../vgeometry/vspline.h" @@ -56,8 +55,12 @@ //--------------------------------------------------------------------------------------------------------------------- VAbstractSpline::VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()), - sceneType(SceneObject::Unknown), isHovered(false), detailsMode(false) + :VDrawTool(doc, data, id), + QGraphicsPathItem(parent), + controlPoints(), + sceneType(SceneObject::Unknown), + m_isHovered(false), + detailsMode(false) { InitDefShape(); setAcceptHoverEvents(true); @@ -76,7 +79,7 @@ QPainterPath VAbstractSpline::shape() const path.lineTo(points.at(i+1)); } - if (isHovered || detailsMode) + if (m_isHovered || detailsMode) { path.addPath(curve->GetDirectionPath()); } @@ -111,7 +114,14 @@ QPainterPath VAbstractSpline::shape() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (isHovered || detailsMode) + const qreal width = ScaleWidth(m_isHovered ? widthMainLine : widthHairLine, SceneScale(scene())); + + const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); + setPen(QPen(CorrectColor(this, curve->GetColor()), width, LineStyleToPenStyle(curve->GetPenStyle()), Qt::RoundCap)); + + RefreshCtrlPoints(); + + if (m_isHovered || detailsMode) { painter->save(); @@ -121,7 +131,6 @@ void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen(arrowPen); painter->setBrush(brush()); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); painter->drawPath(curve->GetDirectionPath()); painter->restore(); @@ -149,12 +158,8 @@ void VAbstractSpline::FullUpdateFromFile() //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::Disable(bool disable, const QString &namePP) { - enabled = !CorrectDisable(disable, namePP); + const bool enabled = !CorrectDisable(disable, namePP); this->setEnabled(enabled); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(curve->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()), Qt::RoundCap)); emit setEnabledPoint(enabled); } @@ -189,21 +194,11 @@ void VAbstractSpline::ShowTool(quint32 id, bool enable) ShowItem(this, id, enable); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VAbstractSpline::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::RefreshGeometry() { InitDefShape(); + RefreshCtrlPoints(); SetVisualization(); } @@ -215,13 +210,7 @@ void VAbstractSpline::RefreshGeometry() // cppcheck-suppress unusedFunction void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event) - const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(curve->GetColor()), - qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()), Qt::RoundCap)); - this->setPath(curve->GetPath()); - isHovered = true; + m_isHovered = true; QGraphicsPathItem::hoverEnterEvent(event); } @@ -233,13 +222,7 @@ void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) // cppcheck-suppress unusedFunction void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event) - const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(curve->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()), Qt::RoundCap)); - this->setPath(curve->GetPath()); - isHovered = false; + m_isHovered = false; QGraphicsPathItem::hoverLeaveEvent(event); } @@ -331,6 +314,12 @@ void VAbstractSpline::SaveOptions(QDomElement &tag, QSharedPointer &ob doc->SetAttribute(tag, AttrPenStyle, curve->GetPenStyle()); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::RefreshCtrlPoints() +{ + // do nothing +} + //--------------------------------------------------------------------------------------------------------------------- VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePointPosition &position, const QPointF &pos) const @@ -403,9 +392,6 @@ VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePoin void VAbstractSpline::InitDefShape() { const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(curve->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()))); this->setPath(curve->GetPath()); } @@ -418,26 +404,6 @@ void VAbstractSpline::ShowHandles(bool show) } } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractSpline::setEnabled(bool enabled) -{ - QGraphicsPathItem::setEnabled(enabled); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(id); - - if (enabled) - { - setPen(QPen(QColor(curve->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()))); - } - else - { - setPen(QPen(Qt::gray, - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(curve->GetPenStyle()))); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VAbstractSpline::GetLineColor() const { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index c52c107fc..d67fec2c4 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -68,8 +68,6 @@ public: virtual QString getTagName() const Q_DECL_OVERRIDE; void ShowHandles(bool show); - void setEnabled(bool enabled); - QString GetLineColor() const; void SetLineColor(const QString &value); @@ -85,7 +83,6 @@ public slots: virtual void DetailsMode(bool mode) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; signals: /** * @brief setEnabledPoint disable control points. @@ -98,7 +95,7 @@ protected: */ QVector controlPoints; SceneObject sceneType; - bool isHovered; + bool m_isHovered; bool detailsMode; /** * @brief RefreshGeometry refresh item on scene. @@ -113,11 +110,10 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void RefreshCtrlPoints(); VSpline CorrectedSpline(const VSpline &spline, const SplinePointPosition &position, const QPointF &pos) const; - void InitDefShape(); - template void ShowToolVisualization(bool show); @@ -135,6 +131,8 @@ protected: private: Q_DISABLE_COPY(VAbstractSpline) + + void InitDefShape(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp index e6684c0d8..ad40ce8e2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp @@ -259,9 +259,6 @@ void VToolCubicBezier::SetVisualization() void VToolCubicBezier::RefreshGeometry() { const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(spl->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(spl->GetPenStyle()))); this->setPath(spl->GetPath()); SetVisualization(); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp index 80341c4f2..34cbd80c7 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezierpath.cpp @@ -241,10 +241,6 @@ void VToolCubicBezierPath::RefreshGeometry() QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); setPath(splPath->GetPath()); - this->setPen(QPen(CorrectColor(splPath->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(splPath->GetPenStyle()))); - SetVisualization(); } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 8e13d286e..86758caba 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -96,7 +96,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, static_cast(spl->GetP2()), - static_cast(spl->GetP1()), *data->GetPatternUnit(), + static_cast(spl->GetP1()), freeAngle1, freeLength1, this); connect(controlPoint1, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); @@ -109,7 +109,7 @@ VToolSpline::VToolSpline(VAbstractPattern *doc, VContainer *data, quint32 id, co auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, static_cast(spl->GetP3()), - static_cast(spl->GetP4()), *data->GetPatternUnit(), + static_cast(spl->GetP4()), freeAngle2, freeLength2, this); connect(controlPoint2, &VControlPointSpline::ControlPointChangePosition, this, &VToolSpline::ControlPointChangePosition); @@ -533,10 +533,7 @@ bool VToolSpline::IsMovable() const } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshGeometry refresh item on scene. - */ -void VToolSpline::RefreshGeometry() +void VToolSpline::RefreshCtrlPoints() { // Very important to disable control points. Without it the pogram can't move the curve. foreach (auto *point, controlPoints) @@ -546,11 +543,6 @@ void VToolSpline::RefreshGeometry() const auto spl = VAbstractTool::data.GeometricObject(id); - this->setPen(QPen(CorrectColor(spl->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(spl->GetPenStyle()))); - this->setPath(spl->GetPath()); - controlPoints[0]->blockSignals(true); controlPoints[1]->blockSignals(true); @@ -577,8 +569,6 @@ void VToolSpline::RefreshGeometry() controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); - SetVisualization(); - foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h index 4dcfdb3d0..83f9b24e2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.h @@ -86,7 +86,7 @@ protected: virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; - virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void RefreshCtrlPoints() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolSpline) QPointF oldPosition; diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index 6b7d94ab8..b4f21f940 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -106,7 +106,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 auto *controlPoint = new VControlPointSpline(i, SplinePointPosition::FirstPoint, static_cast(spl.GetP2()), - static_cast(spl.GetP1()), *data->GetPatternUnit(), + static_cast(spl.GetP1()), freeAngle1, freeLength1, this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); @@ -118,8 +118,7 @@ VToolSplinePath::VToolSplinePath(VAbstractPattern *doc, VContainer *data, quint3 const bool freeLength2 = qmu::QmuTokenParser::IsSingle(spl.GetC2LengthFormula()); controlPoint = new VControlPointSpline(i, SplinePointPosition::LastPoint, static_cast(spl.GetP3()), - static_cast(spl.GetP4()), *data->GetPatternUnit(), freeAngle2, - freeLength2, this); + static_cast(spl.GetP4()), freeAngle2, freeLength2, this); connect(controlPoint, &VControlPointSpline::ControlPointChangePosition, this, &VToolSplinePath::ControlPointChangePosition); connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); @@ -661,10 +660,7 @@ bool VToolSplinePath::IsMovable(int index) const } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshGeometry refresh item on scene. - */ -void VToolSplinePath::RefreshGeometry() +void VToolSplinePath::RefreshCtrlPoints() { // Very important to disable control points. Without it the pogram can't move the curve. foreach (auto *point, controlPoints) @@ -673,11 +669,6 @@ void VToolSplinePath::RefreshGeometry() } const auto splPath = VAbstractTool::data.GeometricObject(id); - this->setPath(splPath->GetPath()); - - this->setPen(QPen(CorrectColor(splPath->GetColor()), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(splPath->GetPenStyle()))); for (qint32 i = 1; i<=splPath->CountSubSpl(); ++i) { @@ -710,8 +701,6 @@ void VToolSplinePath::RefreshGeometry() controlPoints[j-1]->blockSignals(false); } - SetVisualization(); - foreach (auto *point, controlPoints) { point->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h index 2182c2e45..35be7af14 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.h @@ -91,16 +91,17 @@ public slots: const QPointF &pos); virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; - virtual void RemoveReferens() Q_DECL_OVERRIDE; - virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; - virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; - virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + virtual void RemoveReferens() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void RefreshCtrlPoints() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolSplinePath) QPointF oldPosition; @@ -110,7 +111,6 @@ private: QGraphicsItem *parent = nullptr); bool IsMovable(int index) const; - virtual void RefreshGeometry() Q_DECL_OVERRIDE; static void AddPathPoint(VAbstractPattern *doc, QDomElement &domElement, const VSplinePoint &splPoint); void UpdateControlPoints(const VSpline &spl, VSplinePath &splPath, const qint32 &indexSpline) const; void SetSplinePathAttributes(QDomElement &domElement, const VSplinePath &path); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 85aa7d3d3..95c49549c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -56,26 +56,30 @@ //--------------------------------------------------------------------------------------------------------------------- VToolDoublePoint::VToolDoublePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 p1id, quint32 p2id, QGraphicsItem *parent) - :VAbstractPoint(doc, data, id), QGraphicsPathItem(parent), firstPoint(nullptr), secondPoint(nullptr), p1id(p1id), + :VAbstractPoint(doc, data, id), + QGraphicsPathItem(parent), + firstPoint(nullptr), + secondPoint(nullptr), + p1id(p1id), p2id(p2id) { - firstPoint = new VSimplePoint(p1id, QColor(baseColor), *data->GetPatternUnit(), &factor); + firstPoint = new VSimplePoint(p1id, QColor(Qt::black)); firstPoint->setParentItem(this); connect(firstPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point1Choosed); connect(firstPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point1Selected); connect(firstPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(firstPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(firstPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label1ChangePosition); - firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p1id)); + firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p1id)); - secondPoint = new VSimplePoint(p2id, QColor(baseColor), *data->GetPatternUnit(), &factor); + secondPoint = new VSimplePoint(p2id, QColor(Qt::black)); secondPoint->setParentItem(this); connect(secondPoint, &VSimplePoint::Choosed, this, &VToolDoublePoint::Point2Choosed); connect(secondPoint, &VSimplePoint::Selected, this, &VToolDoublePoint::Point2Selected); connect(secondPoint, &VSimplePoint::ShowContextMenu, this, &VToolDoublePoint::contextMenuEvent); connect(secondPoint, &VSimplePoint::Delete, this, &VToolDoublePoint::DeleteFromLabel); connect(secondPoint, &VSimplePoint::NameChangedPosition, this, &VToolDoublePoint::Label2ChangePosition); - secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p2id)); + secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p2id)); } //--------------------------------------------------------------------------------------------------------------------- @@ -102,12 +106,6 @@ void VToolDoublePoint::setNameP2(const QString &name) SetPointName(p2id, name); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::SetEnabled(bool enabled) -{ - SetToolEnabled(this, baseColor, enabled); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::GroupVisibility(quint32 object, bool visible) { @@ -133,19 +131,11 @@ void VToolDoublePoint::Label2ChangePosition(const QPointF &pos) ChangePosition(secondPoint, p2id, pos); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p1id)); - secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p2id)); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::Disable(bool disable, const QString &namePP) { - enabled = !CorrectDisable(disable, namePP); - this->SetEnabled(enabled); + const bool enabled = !CorrectDisable(disable, namePP); + this->setEnabled(enabled); firstPoint->SetEnabled(enabled); secondPoint->SetEnabled(enabled); } @@ -185,8 +175,8 @@ void VToolDoublePoint::Point2Selected(bool selected) void VToolDoublePoint::FullUpdateFromFile() { ReadAttributes(); - firstPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p1id)); - secondPoint->RefreshGeometry(*VAbstractTool::data.GeometricObject(p2id)); + firstPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p1id)); + secondPoint->RefreshPointGeometry(*VAbstractTool::data.GeometricObject(p2id)); SetVisualization(); } @@ -199,7 +189,7 @@ void VToolDoublePoint::DoChangePosition(quint32 id, qreal mx, qreal my) point->setMx(mx); point->setMy(my); VAbstractTool::data.UpdateGObject(p1id, point); - firstPoint->RefreshGeometry(*point); + firstPoint->RefreshPointGeometry(*point); } else if (id == p2id) { @@ -207,7 +197,7 @@ void VToolDoublePoint::DoChangePosition(quint32 id, qreal mx, qreal my) point->setMx(mx); point->setMy(my); VAbstractTool::data.UpdateGObject(p2id, point); - secondPoint->RefreshGeometry(*point); + secondPoint->RefreshPointGeometry(*point); } } @@ -268,19 +258,6 @@ void VToolDoublePoint::UpdateNamePosition(quint32 id) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolDoublePoint::RefreshLine(quint32 id) -{ - if (id == p1id) - { - firstPoint->RefreshLine(); - } - else if (id == p2id) - { - secondPoint->RefreshLine(); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange hadle item change. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index e40584e22..0531d531c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -62,13 +62,10 @@ public: QString nameP2() const; void setNameP2(const QString &name); - void SetEnabled(bool enabled); - virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: void Label1ChangePosition(const QPointF &pos); void Label2ChangePosition(const QPointF &pos); - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; void Point1Choosed(); @@ -91,7 +88,6 @@ protected: quint32 p2id; virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; - virtual void RefreshLine(quint32 id) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 5ed0a4e40..989fc1769 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -80,17 +80,6 @@ VToolAlongLine::VToolAlongLine(VAbstractPattern *doc, VContainer *data, quint32 ToolCreation(typeCreation); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolAlongLine::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. handle context menu event. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h index 13f73a07a..b1bb43494 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.h @@ -68,8 +68,6 @@ public: quint32 GetSecondPointId() const; void SetSecondPointId(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp index e562a08a7..9ae59a10f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp @@ -241,17 +241,6 @@ QString VToolBisector::ThirdPointName() const return VAbstractTool::data.GetGObject(thirdPointId)->name(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolBisector::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h index 8611b7d4b..3a413775e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.h @@ -77,8 +77,6 @@ public: void SetThirdPointId(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; 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 7e2cdc3a5..02533d4b9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp @@ -75,9 +75,6 @@ VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const qu QPointF point1 = static_cast(*data->GeometricObject(basePointId)); QPointF point2 = static_cast(*data->GeometricObject(id)); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(typeLine))); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -87,15 +84,30 @@ VToolLinePoint::~VToolLinePoint() delete mainLine; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + const qreal width = ScaleWidth(m_isHovered ? widthMainLine : widthHairLine, SceneScale(scene())); + + mainLine->setPen(QPen(CorrectColor(this, lineColor), width, LineStyleToPenStyle(m_lineType))); + + VToolSinglePoint::paint(painter, option, widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VToolLinePoint::boundingRect() const +{ + QRectF rect = VToolSinglePoint::boundingRect(); + rect = rect.united(mainLine->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. */ void VToolLinePoint::RefreshGeometry() { - mainLine->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(m_lineType))); VToolSinglePoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); QPointF point = static_cast(*VDrawTool::data.GeometricObject(id)); QPointF basePoint = static_cast(*VDrawTool::data.GeometricObject(basePointId)); @@ -121,25 +133,11 @@ void VToolLinePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj doc->SetAttribute(tag, AttrLineColor, lineColor); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolLinePoint::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::Disable(bool disable, const QString &namePP) { VToolSinglePoint::Disable(disable, namePP); - mainLine->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(m_lineType))); - mainLine->setEnabled(enabled); + mainLine->setEnabled(isEnabled()); } //--------------------------------------------------------------------------------------------------------------------- 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 424cfad6e..e195eb864 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.h @@ -56,6 +56,10 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::LinePoint)}; + 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); @@ -71,7 +75,6 @@ public: void SetLineColor(const QString &value); public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; protected: diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp index 6a8902c1d..5976f73be 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp @@ -217,17 +217,6 @@ QString VToolNormal::SecondPointName() const return VAbstractTool::data.GetGObject(secondPointId)->name(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolNormal::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h index 00e62ab9c..3218bad9f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.h @@ -72,8 +72,6 @@ public: void SetSecondPointId(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index 85bd0ab1f..b38ea8ef7 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -259,17 +259,6 @@ QString VToolShoulderPoint::ShoulderPointName() const return VAbstractTool::data.GetGObject(pShoulder)->name(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolShoulderPoint::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h index 0866429bf..e26efdaae 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.h @@ -77,8 +77,6 @@ public: void setPShoulder(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index ba9334c9c..ce9c2ace8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -83,11 +83,10 @@ VToolBasePoint::VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 const QString &namePP, QGraphicsItem * parent ) :VToolSinglePoint(doc, data, id, parent), namePP(namePP) { - baseColor = Qt::red; - this->setPen(QPen(baseColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); + m_baseColor = Qt::red; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - SetColorLabel(Qt::black); + m_namePoint->setBrush(Qt::black); ToolCreation(typeCreation); } @@ -360,17 +359,6 @@ void VToolBasePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) VToolSinglePoint::mouseReleaseEvent(event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetColorLabel change color for label and label line. - * @param color new color. - */ -void VToolBasePoint::SetColorLabel(const Qt::GlobalColor &color) -{ - namePoint->setBrush(color); - lineName->setPen(QPen(color, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolBasePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) { @@ -435,17 +423,6 @@ void VToolBasePoint::FullUpdateFromFile() RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolBasePoint::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshPointGeometry(*(VAbstractTool::data.GeometricObject(id))); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolBasePoint::EnableToolMove(bool move) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 2c3e91648..c6ef49140 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -68,7 +68,6 @@ public: void SetBasePointPos(const QPointF &pos); public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; signals: /** @@ -95,8 +94,6 @@ private: VToolBasePoint (VAbstractPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, const QString &namePP, QGraphicsItem * parent = nullptr ); - - void SetColorLabel(const Qt::GlobalColor & color); }; #endif // VTOOLBASEPOINT_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp index c54ec77f1..bc5158238 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp @@ -223,17 +223,6 @@ QString VToolLineIntersect::Line2P2Name() const return VAbstractTool::data.GetGObject(p2Line2)->name(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolLineIntersect::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h index a70708ab5..22e30962d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.h @@ -80,8 +80,6 @@ public: void SetP2Line2(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index 217e34c5f..da11c31bf 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -269,17 +269,6 @@ QString VToolPointOfContact::SecondPointName() const return VAbstractTool::data.GetGObject(secondPointId)->name(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolPointOfContact::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h index f60ca15c3..567b6373e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.h @@ -84,8 +84,6 @@ public: void SetSecondPointId(const quint32 &value); virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void RemoveReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 47cf50a70..05caecd7a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -76,19 +76,14 @@ QT_WARNING_POP * @param parent parent object. */ VToolSinglePoint::VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) - :VAbstractPoint(doc, data, id), QGraphicsEllipseItem(parent), radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), - namePoint(nullptr), lineName(nullptr) + : VAbstractPoint(doc, data, id), + VScenePoint(parent) { - namePoint = new VGraphicsSimpleTextItem(this); - connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolSinglePoint::contextMenuEvent); - connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolSinglePoint::DeleteFromLabel); - connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VToolSinglePoint::PointChoosed); - connect(namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VToolSinglePoint::PointSelected); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolSinglePoint::NameChangePosition); - lineName = new QGraphicsLineItem(this); - this->setBrush(QBrush(Qt::NoBrush)); - this->setAcceptHoverEvents(true); - this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus + connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolSinglePoint::contextMenuEvent); + connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolSinglePoint::DeleteFromLabel); + connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VToolSinglePoint::PointChoosed); + connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VToolSinglePoint::PointSelected); + connect(m_namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolSinglePoint::NameChangePosition); RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); } @@ -107,8 +102,8 @@ void VToolSinglePoint::setName(const QString &name) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::SetEnabled(bool enabled) { - SetToolEnabled(this, baseColor, enabled); - SetToolEnabled(lineName, Qt::black, enabled); + setEnabled(enabled); + m_lineName->setEnabled(enabled); } //--------------------------------------------------------------------------------------------------------------------- @@ -144,7 +139,7 @@ void VToolSinglePoint::UpdateNamePosition(quint32 id) void VToolSinglePoint::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()) @@ -165,29 +160,18 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolSinglePoint::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::Disable(bool disable, const QString &namePP) { - enabled = !CorrectDisable(disable, namePP); - this->SetEnabled(enabled); - namePoint->setEnabled(enabled); + const bool enabled = !CorrectDisable(disable, namePP); + SetEnabled(enabled); + m_namePoint->setEnabled(enabled); } //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::EnableToolMove(bool move) { - namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); + m_namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); } //--------------------------------------------------------------------------------------------------------------------- @@ -227,71 +211,7 @@ void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) PointChoosed(); } } - QGraphicsEllipseItem::mouseReleaseEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverEnterEvent handle hover enter events. - * @param event hover enter event. - */ -void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - this->setPen(QPen(CorrectColor(baseColor), - qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - QGraphicsEllipseItem::hoverEnterEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ -void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - this->setPen(QPen(CorrectColor(baseColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - QGraphicsEllipseItem::hoverLeaveEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshPointGeometry refresh point on scene. - * @param point point. - */ -void VToolSinglePoint::RefreshPointGeometry(const VPointF &point) -{ - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - 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); - this->setPos(static_cast(point)); - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - namePoint->blockSignals(true); - QFont font = namePoint->font(); - font.setPointSize(static_cast(namePoint->FontSize()/factor)); - namePoint->setFont(font); - namePoint->setText(point.name()); - namePoint->setPos(QPointF(point.mx(), point.my())); - namePoint->blockSignals(false); - RefreshLine(id); - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshLine refresh line to label on scene. - */ -void VToolSinglePoint::RefreshLine(quint32 id) -{ - Q_UNUSED(id) - VAbstractTool::RefreshLine(this, namePoint, lineName, radius); - lineName->setPen(QPen(CorrectColor(Qt::black), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); + VScenePoint::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -305,13 +225,13 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, { if (change == QGraphicsItem::ItemSelectedChange) { - namePoint->blockSignals(true); - namePoint->setSelected(value.toBool()); - namePoint->blockSignals(false); + m_namePoint->blockSignals(true); + m_namePoint->setSelected(value.toBool()); + m_namePoint->blockSignals(false); emit ChangedToolSelection(value.toBool(), id, id); } - return QGraphicsEllipseItem::itemChange(change, value); + return VScenePoint::itemChange(change, value); } //--------------------------------------------------------------------------------------------------------------------- @@ -337,7 +257,7 @@ void VToolSinglePoint::keyReleaseEvent(QKeyEvent *event) default: break; } - QGraphicsEllipseItem::keyReleaseEvent ( event ); + VScenePoint::keyReleaseEvent ( event ); } //--------------------------------------------------------------------------------------------------------------------- @@ -366,10 +286,10 @@ void VToolSinglePoint::DoChangePosition(quint32 id, qreal mx, qreal my) point->setMx(mx); point->setMy(my); VAbstractTool::data.UpdateGObject(id, point); - namePoint->blockSignals(true); - namePoint->setPos(QPointF(mx, my)); - namePoint->blockSignals(false); - RefreshLine(id); + m_namePoint->blockSignals(true); + m_namePoint->setPos(QPointF(mx, my)); + m_namePoint->blockSignals(false); + RefreshLine(); } //--------------------------------------------------------------------------------------------------------------------- @@ -387,18 +307,18 @@ void VToolSinglePoint::AllowSelecting(bool enabled) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::AllowLabelHover(bool enabled) { - namePoint->setAcceptHoverEvents(enabled); + m_namePoint->setAcceptHoverEvents(enabled); } //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::AllowLabelSelecting(bool enabled) { - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + m_namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); } //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::ToolSelectionType(const SelectionType &type) { VAbstractTool::ToolSelectionType(type); - namePoint->LabelSelectionType(type); + m_namePoint->LabelSelectionType(type); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index a3dd9ff73..401be1a5a 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -30,7 +30,6 @@ #define VTOOLSINGLEPOINT_H #include -#include #include #include #include @@ -41,63 +40,50 @@ #include "../vabstractpoint.h" #include "../vmisc/def.h" +#include "../vwidgets/vscenepoint.h" template class QSharedPointer; /** * @brief The VToolSinglePoint class parent for all tools what create points. */ -class VToolSinglePoint: public VAbstractPoint, public QGraphicsEllipseItem +class VToolSinglePoint: public VAbstractPoint, public VScenePoint { Q_OBJECT public: VToolSinglePoint(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); virtual ~VToolSinglePoint() Q_DECL_EQ_DEFAULT; - virtual int type() const Q_DECL_OVERRIDE {return Type;} + virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::SinglePoint)}; - QString name() const; - void setName(const QString &name); + QString name() const; + void setName(const QString &name); - void SetEnabled(bool enabled); + void SetEnabled(bool enabled); virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; public slots: - void NameChangePosition(const QPointF &pos); - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; - virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; - virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; - void PointChoosed(); - void PointSelected(bool selected); - virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; - virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; - virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; - virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - void AllowLabelHover(bool enabled); - void AllowLabelSelecting(bool enabled); - virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; + void NameChangePosition(const QPointF &pos); + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + virtual void EnableToolMove(bool move) Q_DECL_OVERRIDE; + void PointChoosed(); + void PointSelected(bool selected); + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + virtual void DoChangePosition(quint32 id, qreal mx, qreal my) Q_DECL_OVERRIDE; + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + void AllowLabelHover(bool enabled); + void AllowLabelSelecting(bool enabled); + virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; protected: - /** @brief radius radius circle. */ - qreal radius; - - /** @brief namePoint point label. */ - VGraphicsSimpleTextItem *namePoint; - - /** @brief lineName line what we see if label moved too away from point. */ - QGraphicsLineItem *lineName; - - virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void RefreshPointGeometry(const VPointF &point); - virtual void RefreshLine(quint32 id) Q_DECL_OVERRIDE; - virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; - virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; - virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void UpdateNamePosition(quint32 id) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; + virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; + virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VToolSinglePoint) }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index 36d41fd6a..c5b45f9d9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -74,10 +74,6 @@ protected: virtual void UpdateNamePosition(quint32 id)=0; - virtual void RefreshLine(quint32 id)=0; - - template - void SetToolEnabled(T *item, const QColor &color, bool enabled); template static void InitToolConnections(VMainGraphicsScene *scene, T *tool); @@ -111,22 +107,6 @@ void VAbstractPoint::ShowToolVisualization(bool show) } } -//--------------------------------------------------------------------------------------------------------------------- -template -void VAbstractPoint::SetToolEnabled(T *item, const QColor &color, bool enabled) -{ - item->setEnabled(enabled); - if (enabled) - { - item->setPen(QPen(color, - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - } - else - { - item->setPen(QPen(Qt::gray, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor)); - } -} - //--------------------------------------------------------------------------------------------------------------------- template void VAbstractPoint::ChangePosition(T *item, quint32 id, const QPointF &pos) diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index c5686393c..6235634f9 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -49,8 +49,6 @@ template class QSharedPointer; -qreal VDrawTool::factor = 1; - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VDrawTool constructor. @@ -61,8 +59,7 @@ qreal VDrawTool::factor = 1; VDrawTool::VDrawTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent) : VInteractiveTool(doc, data, id, parent), nameActivDraw(doc->GetNameActivPP()), - m_lineType(TypeLineLine), - enabled(true) + m_lineType(TypeLineLine) { connect(this->doc, &VAbstractPattern::ChangedActivPP, this, &VDrawTool::ChangedActivDraw); connect(this->doc, &VAbstractPattern::ChangedNameDraw, this, &VDrawTool::ChangedNameDraw); @@ -184,19 +181,6 @@ void VDrawTool::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, VDomDocument::AttrId, id); } -//--------------------------------------------------------------------------------------------------------------------- -QColor VDrawTool::CorrectColor(const QColor &color) const -{ - if (enabled) - { - return color; - } - else - { - return Qt::gray; - } -} - //--------------------------------------------------------------------------------------------------------------------- bool VDrawTool::CorrectDisable(bool disable, const QString &namePP) const { @@ -224,16 +208,6 @@ void VDrawTool::ReadAttributes() } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VDrawTool::SetFactor(qreal factor) -{ - CheckFactor(VDrawTool::factor, factor); -} - //--------------------------------------------------------------------------------------------------------------------- void VDrawTool::EnableToolMove(bool move) { diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index f2d52c90d..c4a179bd3 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -63,9 +63,6 @@ public: VDrawTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr); virtual ~VDrawTool() Q_DECL_EQ_DEFAULT; - /** @brief factor scene scale factor. */ - static qreal factor; - QString getLineType() const; virtual void SetTypeLine(const QString &value); @@ -76,7 +73,6 @@ public slots: virtual void ShowTool(quint32 id, bool enable); virtual void ChangedActivDraw(const QString &newName); void ChangedNameDraw(const QString &oldName, const QString &newName); - virtual void SetFactor(qreal factor); virtual void EnableToolMove(bool move); virtual void Disable(bool disable, const QString &namePP)=0; virtual void DetailsMode(bool mode); @@ -91,8 +87,6 @@ protected: /** @brief typeLine line type. */ QString m_lineType; - bool enabled; - void AddToCalculation(const QDomElement &domElement); /** @brief SaveDialog save options into file after change in dialog. */ @@ -103,7 +97,6 @@ protected: void SaveOption(QSharedPointer &obj); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); - QColor CorrectColor(const QColor &color) const; bool CorrectDisable(bool disable, const QString &namePP) const; void ReadAttributes(); @@ -247,7 +240,6 @@ void VDrawTool::InitDrawToolConnections(VMainGraphicsScene *scene, T *tool) QObject::connect(tool, &T::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); QObject::connect(tool, &T::ChangedToolSelection, scene, &VMainGraphicsScene::SelectedItem); - QObject::connect(scene, &VMainGraphicsScene::NewFactor, tool, &T::SetFactor); QObject::connect(scene, &VMainGraphicsScene::DisableItem, tool, &T::Disable); QObject::connect(scene, &VMainGraphicsScene::EnableToolMove, tool, &T::EnableToolMove); QObject::connect(scene, &VMainGraphicsScene::CurveDetailsMode, tool, &T::DetailsMode); diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index cbe8d3641..f51f388c0 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -69,8 +69,12 @@ template class QSharedPointer; VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, const QString &typeLine, const QString &lineColor, const Source &typeCreation, QGraphicsItem *parent) - :VDrawTool(doc, data, id), QGraphicsLineItem(parent), firstPoint(firstPoint), secondPoint(secondPoint), - lineColor(lineColor) + :VDrawTool(doc, data, id), + QGraphicsLineItem(parent), + firstPoint(firstPoint), + secondPoint(secondPoint), + lineColor(lineColor), + m_isHovered(false) { this->m_lineType = typeLine; //Line @@ -80,9 +84,6 @@ VToolLine::VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint3 this->setFlag(QGraphicsItem::ItemStacksBehindParent, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setAcceptHoverEvents(true); - this->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(typeLine))); ToolCreation(typeCreation); } @@ -193,6 +194,16 @@ QString VToolLine::getTagName() const return VAbstractPattern::TagLine; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + const qreal width = ScaleWidth(m_isHovered ? widthMainLine : widthHairLine, SceneScale(scene())); + + setPen(QPen(CorrectColor(this, lineColor), width, LineStyleToPenStyle(m_lineType))); + + QGraphicsLineItem::paint(painter, option, widget); +} + //--------------------------------------------------------------------------------------------------------------------- QString VToolLine::FirstPointName() const { @@ -227,25 +238,11 @@ void VToolLine::ShowTool(quint32 id, bool enable) ShowItem(this, id, enable); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. - */ -void VToolLine::SetFactor(qreal factor) -{ - VDrawTool::SetFactor(factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolLine::Disable(bool disable, const QString &namePP) { - enabled = !CorrectDisable(disable, namePP); + const bool enabled = !CorrectDisable(disable, namePP); this->setEnabled(enabled); - this->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(m_lineType))); } //--------------------------------------------------------------------------------------------------------------------- @@ -315,10 +312,8 @@ void VToolLine::RefreshDataInFile() */ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event) - this->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(m_lineType))); + m_isHovered = true; + QGraphicsLineItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -328,12 +323,10 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) */ void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event) if (vis.isNull()) { - this->setPen(QPen(CorrectColor(lineColor), - qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, - LineStyleToPenStyle(m_lineType))); + m_isHovered = false; + QGraphicsLineItem::hoverLeaveEvent(event); } } @@ -544,5 +537,4 @@ void VToolLine::RefreshGeometry() const QSharedPointer first = VAbstractTool::data.GeometricObject(firstPoint); const QSharedPointer second = VAbstractTool::data.GeometricObject(secondPoint); this->setLine(QLineF(static_cast(*first), static_cast(*second))); - this->setPen(QPen(CorrectColor(lineColor), pen().widthF(), LineStyleToPenStyle(m_lineType))); } diff --git a/src/libs/vtools/tools/drawTools/vtoolline.h b/src/libs/vtools/tools/drawTools/vtoolline.h index 469cce5cb..71d5063a5 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.h +++ b/src/libs/vtools/tools/drawTools/vtoolline.h @@ -64,6 +64,9 @@ public: enum { Type = UserType + static_cast(Tool::Line)}; virtual QString getTagName() const Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + QString FirstPointName() const; QString SecondPointName() const; @@ -83,7 +86,6 @@ public: public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE; - virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; @@ -112,6 +114,8 @@ private: /** @brief lineColor color of a line. */ QString lineColor; + bool m_isHovered; + VToolLine(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 firstPoint, quint32 secondPoint, const QString &typeLine, const QString &lineColor, const Source &typeCreation, QGraphicsItem * parent = nullptr); diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index 906e3df5d..93a9f62fc 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -62,7 +62,6 @@ VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quin parentType(ParentType::Item), idNode(idNode), idTool(idTool), - currentColor(Qt::black), m_drawName(drawName), m_exluded(false) { diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 3af8b0124..42fe59a36 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -73,9 +73,6 @@ protected: /** @brief idTool id tool. */ quint32 idTool; - /** @brief currentColor current tool color. */ - QColor currentColor; - QString m_drawName; bool m_exluded; diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index 8b5fd2026..8ac1931f7 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -71,24 +71,16 @@ const QString VNodePoint::ToolType = QStringLiteral("modeling"); */ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idPoint, const Source &typeCreation, const QString &drawName, const quint32 &idTool, QObject *qoParent, QGraphicsItem *parent) - :VAbstractNode(doc, data, id, idPoint, drawName, idTool, qoParent), QGraphicsEllipseItem(parent), radius(0), - namePoint(nullptr), lineName(nullptr) + : VAbstractNode(doc, data, id, idPoint, drawName, idTool, qoParent), + VScenePoint(parent) { - radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm); - namePoint = new VGraphicsSimpleTextItem(this); - connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VNodePoint::PointChoosed); - lineName = new QGraphicsLineItem(this); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VNodePoint::NameChangePosition); - connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, + connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VNodePoint::PointChoosed); + connect(m_namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VNodePoint::NameChangePosition); + connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, [this](QGraphicsSceneContextMenuEvent *event) { emit ShowContextMenu(event); }); - this->setPen(QPen(Qt::black, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); - this->setBrush(QBrush(Qt::NoBrush)); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setAcceptHoverEvents(true); RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); ToolCreation(typeCreation); } @@ -234,28 +226,6 @@ void VNodePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) QGraphicsEllipseItem::mouseReleaseEvent(event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. - */ -void VNodePoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - this->setPen(QPen(currentColor, qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit())))); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ -void VNodePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition label change position. @@ -289,35 +259,6 @@ void VNodePoint::UpdateNamePosition(qreal mx, qreal my) } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshPointGeometry refresh point on scene. - * @param point point position. - */ -void VNodePoint::RefreshPointGeometry(const VPointF &point) -{ - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPos(static_cast(point)); - - namePoint->blockSignals(true); - namePoint->setText(point.name()); - namePoint->setPos(QPointF(point.mx(), point.my())); - namePoint->blockSignals(false); - - RefreshLine(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshLine refresh label line on scene. - */ -void VNodePoint::RefreshLine() -{ - VAbstractTool::RefreshLine(this, namePoint, lineName, radius); -} - //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::ShowNode() { @@ -336,7 +277,7 @@ void VNodePoint::HideNode() //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::EnableToolMove(bool move) { - namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); + m_namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); } //--------------------------------------------------------------------------------------------------------------------- @@ -354,11 +295,11 @@ void VNodePoint::AllowSelecting(bool enabled) //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::AllowLabelHover(bool enabled) { - namePoint->setAcceptHoverEvents(enabled); + m_namePoint->setAcceptHoverEvents(enabled); } //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::AllowLabelSelecting(bool enabled) { - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + m_namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); } diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 89417d017..e0bae7067 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -41,11 +41,12 @@ #include "../ifc/xml/vabstractpattern.h" #include "../vmisc/def.h" #include "vabstractnode.h" +#include "../vwidgets/vscenepoint.h" /** * @brief The VNodePoint class point detail node. */ -class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem +class VNodePoint: public VAbstractNode, public VScenePoint { Q_OBJECT public: @@ -75,24 +76,11 @@ public slots: void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); protected: - /** @brief radius radius circle. */ - qreal radius; - - /** @brief namePoint label name. */ - VGraphicsSimpleTextItem *namePoint; - - /** @brief lineName pointer to label line. */ - QGraphicsLineItem *lineName; - virtual void AddToFile() Q_DECL_OVERRIDE; virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void UpdateNamePosition(qreal mx, qreal my); - virtual void RefreshPointGeometry(const VPointF &point); - void RefreshLine(); virtual void ShowNode() Q_DECL_OVERRIDE; virtual void HideNode() Q_DECL_OVERRIDE; private: diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 9615f1e12..ba4703b07 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -112,6 +112,25 @@ QString VToolPiecePath::getTagName() const return VAbstractPattern::TagPath; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPiecePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + qreal width = widthHairLine; + + const qreal scale = SceneScale(scene()); + if (scale > 1) + { + width = qMax(1., width/scale); + } + + QPen toolPen = pen(); + toolPen.setWidthF(width); + + setPen(toolPen); + + QGraphicsPathItem::paint(painter, option, widget); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolPiecePath::incrementReferens() { diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h index b6fda5b08..c95d8f318 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.h @@ -50,6 +50,9 @@ public: enum { Type = UserType + static_cast(Tool::PiecePath)}; virtual QString getTagName() const Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual void incrementReferens() Q_DECL_OVERRIDE; virtual void decrementReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 5bce7706c..d26219066 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -121,7 +121,10 @@ quint32 CreateNodeSplinePath(VContainer *data, quint32 id) * @param parent parent object. */ VAbstractTool::VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent) - :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), vis(), + :VDataTool(data, parent), + doc(doc), + id(id), + vis(), selectionType(SelectionType::ByMouseRelease) { SCASSERT(doc != nullptr) @@ -470,43 +473,6 @@ void VAbstractTool::AddNodes(VAbstractPattern *doc, QDomElement &domElement, con AddNodes(doc, domElement, piece.GetPath()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshLine refresh line to label on scene. - */ -void VAbstractTool::RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, - QGraphicsLineItem *lineName, const qreal radius) -{ - SCASSERT(point != nullptr) - SCASSERT(namePoint != nullptr) - SCASSERT(lineName != nullptr) - - QRectF nRec = namePoint->sceneBoundingRect(); - nRec.translate(- point->scenePos()); - if (point->rect().intersects(nRec) == false) - { - const QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - point->scenePos()), p1, - p2); - const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(point->scenePos(), nameRec.center())); - lineName->setLine(QLineF(p1, pRec - point->scenePos())); - - if (QLineF(p1, pRec - point->scenePos()).length() <= ToPixel(4, Unit::Mm)) - { - lineName->setVisible(false); - } - else - { - lineName->setVisible(true); - } - } - else - { - lineName->setVisible(false); - } -} - //--------------------------------------------------------------------------------------------------------------------- QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node) { diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index 8d71098e0..750e6c92c 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -111,9 +111,6 @@ protected: /** @brief id object id. */ const quint32 id; - /** @brief baseColor base color for tool. */ - Qt::GlobalColor baseColor; - QPointer vis; SelectionType selectionType; @@ -138,9 +135,6 @@ protected: virtual void SetVisualization()=0; virtual void ToolCreation(const Source &typeCreation); - static void RefreshLine(QGraphicsEllipseItem *point, VGraphicsSimpleTextItem *namePoint, - QGraphicsLineItem *lineName, const qreal radius); - static QDomElement AddSANode(VAbstractPattern *doc, const QString &tagName, const VPieceNode &node); static void AddNode(VAbstractPattern *doc, QDomElement &domElement, const VPieceNode &node); @@ -179,7 +173,6 @@ inline void VAbstractTool::AddVisualization() T *visual = new T(getData()); VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); SCASSERT(scene != nullptr) - connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); scene->addItem(visual); connect(visual, &Visualization::ToolTip, this, &VAbstractTool::ToolTip); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index c7e07b7e7..db4aad286 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -788,6 +788,12 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) */ void VToolSeamAllowance::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + QPen toolPen = pen(); + toolPen.setWidthF(ScaleWidth(widthHairLine, SceneScale(scene()))); + + setPen(toolPen); + m_seamAllowance->setPen(toolPen); + if ((m_dataLabel->IsIdle() == false || m_patternInfo->IsIdle() == false || m_grainLine->IsIdle() == false) && not isSelected()) @@ -979,22 +985,22 @@ void VToolSeamAllowance::hoverMoveEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event); if (flags() & QGraphicsItem::ItemIsMovable) { SetOverrideCursor(cursorArrowOpenHand, 1, 1); } + QGraphicsPathItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event); //Disable cursor-arrow-openhand if (flags() & QGraphicsItem::ItemIsMovable) { RestoreOverrideCursor(cursorArrowOpenHand); } + QGraphicsPathItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 7733a2824..9b7b5ad82 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -94,6 +94,8 @@ public: virtual QString getTagName() const Q_DECL_OVERRIDE; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile () Q_DECL_OVERRIDE; void EnableToolMove(bool move); @@ -117,8 +119,6 @@ protected slots: void SaveResizeGrainline(qreal dLength); void SaveRotateGrainline(qreal dRot, const QPointF& ptPos); protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) Q_DECL_OVERRIDE; virtual void AddToFile () Q_DECL_OVERRIDE; virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index 12fbf0b07..6887bae6c 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -77,7 +77,7 @@ void VisOperation::VisualMode(const quint32 &pointId) //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisOperation::GetPoint(quint32 i, const QColor &color) { - return GetPointItem(Visualization::data, factor, points, i, color, this); + return GetPointItem(points, i, color, this); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp index f3c4dcb9c..03d884f86 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.cpp @@ -38,11 +38,6 @@ VisToolFlippingByAxis::VisToolFlippingByAxis(const VContainer *data, QGraphicsIt point1 = InitPoint(supportColor2, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolFlippingByAxis::~VisToolFlippingByAxis() -{ -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolFlippingByAxis::RefreshGeometry() { @@ -85,3 +80,21 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolFlippingByAxis::boundingRect() const +{ + QRectF rect = VisOperation::boundingRect(); + rect = rect.united(point1->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h index 301f33dcd..58e04a5f0 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyaxis.h @@ -39,7 +39,7 @@ class VisToolFlippingByAxis : public VisOperation Q_OBJECT public: explicit VisToolFlippingByAxis(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolFlippingByAxis(); + virtual ~VisToolFlippingByAxis() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -48,6 +48,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolFlippingByAxis) diff --git a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp index 6af7965d2..1e008c286 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.cpp @@ -40,11 +40,6 @@ VisToolFlippingByLine::VisToolFlippingByLine(const VContainer *data, QGraphicsIt point2 = InitPoint(supportColor2, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolFlippingByLine::~VisToolFlippingByLine() -{ -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolFlippingByLine::RefreshGeometry() { @@ -77,6 +72,26 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolFlippingByLine::boundingRect() const +{ + QRectF rect = VisOperation::boundingRect(); + rect = rect.united(point1->boundingRect()); + rect = rect.united(point2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 21768a03a..3d7f531a3 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h +++ b/src/libs/vtools/visualization/line/operation/vistoolflippingbyline.h @@ -38,9 +38,12 @@ class VisToolFlippingByLine : public VisOperation Q_OBJECT public: explicit VisToolFlippingByLine(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolFlippingByLine(); + virtual ~VisToolFlippingByLine() = default; - virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; void SetFirstLinePointId(quint32 value); void SetSecondLinePointId(quint32 value); diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp index dc381c2dc..ec6fed065 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.cpp @@ -128,6 +128,26 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolMove::boundingRect() const +{ + QRectF rect = VisOperation::boundingRect(); + rect = rect.united(pointOrigin->boundingRect()); + rect = rect.united(pointFinish->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- QString VisToolMove::Angle() const { diff --git a/src/libs/vtools/visualization/line/operation/vistoolmove.h b/src/libs/vtools/visualization/line/operation/vistoolmove.h index e1da85f92..b9721d23c 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolmove.h +++ b/src/libs/vtools/visualization/line/operation/vistoolmove.h @@ -50,7 +50,10 @@ public: explicit VisToolMove(const VContainer *data, QGraphicsItem *parent = nullptr); virtual ~VisToolMove(); - virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; QString Angle() const; void SetAngle(const QString &expression); diff --git a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp index 520cde2cb..a533eb1a8 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.cpp @@ -116,7 +116,7 @@ void VisToolRotation::RefreshGeometry() DrawLine(xAxis, QLineF(static_cast(*origin), Ray(static_cast(*origin), 0)), supportColor2, Qt::DashLine); - VArc arc(*origin, ToPixel(DefPointRadius/*mm*/*2, Unit::Mm), 0, tempAngle); + VArc arc(*origin, defPointRadiusPixel*2, 0, tempAngle); DrawPath(angleArc, arc.GetPath(PathDirection::Hide), supportColor2, Qt::SolidLine, Qt::RoundCap); Visualization::toolTip = tr("Rotating angle = %1°, Shift - sticking angle, " @@ -188,9 +188,30 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolRotation::boundingRect() const +{ + QRectF rect = VisOperation::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(angleArc->boundingRect()); + rect = rect.united(xAxis->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 99e9e0edd..199aceaa7 100644 --- a/src/libs/vtools/visualization/line/operation/vistoolrotation.h +++ b/src/libs/vtools/visualization/line/operation/vistoolrotation.h @@ -50,7 +50,10 @@ public: explicit VisToolRotation(const VContainer *data, QGraphicsItem *parent = nullptr); virtual ~VisToolRotation(); - virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; void SetOriginPointId(quint32 value); diff --git a/src/libs/vtools/visualization/line/visline.cpp b/src/libs/vtools/visualization/line/visline.cpp index 1c129856e..d0f06e3c4 100644 --- a/src/libs/vtools/visualization/line/visline.cpp +++ b/src/libs/vtools/visualization/line/visline.cpp @@ -47,10 +47,6 @@ VisLine::VisLine(const VContainer *data, QGraphicsItem *parent) InitPen(); } -//--------------------------------------------------------------------------------------------------------------------- -VisLine::~VisLine() -{} - //--------------------------------------------------------------------------------------------------------------------- qreal VisLine::CorrectAngle(const qreal &angle) { @@ -82,6 +78,14 @@ 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); +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const { @@ -138,8 +142,11 @@ QLineF VisLine::Axis(const QPointF &p1, const QPointF &p2) const //--------------------------------------------------------------------------------------------------------------------- void VisLine::InitPen() { - this->setPen(QPen(mainColor, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, - lineStyle)); + QPen visPen = pen(); + visPen.setColor(mainColor); + visPen.setStyle(lineStyle); + + setPen(visPen); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/line/visline.h b/src/libs/vtools/visualization/line/visline.h index 036837b96..553305ad0 100644 --- a/src/libs/vtools/visualization/line/visline.h +++ b/src/libs/vtools/visualization/line/visline.h @@ -48,12 +48,15 @@ class VisLine: public Visualization, public QGraphicsLineItem { Q_OBJECT public: - explicit VisLine(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisLine() Q_DECL_OVERRIDE; + explicit VisLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisLine() = default; 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; protected: QPointF Ray(const QPointF &firstPoint, const qreal &angle) const; QPointF Ray(const QPointF &firstPoint) const; diff --git a/src/libs/vtools/visualization/line/vistoolalongline.cpp b/src/libs/vtools/visualization/line/vistoolalongline.cpp index 677270660..ad5f128e2 100644 --- a/src/libs/vtools/visualization/line/vistoolalongline.cpp +++ b/src/libs/vtools/visualization/line/vistoolalongline.cpp @@ -57,10 +57,6 @@ VisToolAlongLine::VisToolAlongLine(const VContainer *data, QGraphicsItem *parent point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolAlongLine::~VisToolAlongLine() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolAlongLine::setObject2Id(const quint32 &value) { @@ -73,6 +69,30 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolAlongLine::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(lineP1->boundingRect()); + rect = rect.united(lineP2->boundingRect()); + rect = rect.united(line->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolAlongLine::RefreshGeometry() { diff --git a/src/libs/vtools/visualization/line/vistoolalongline.h b/src/libs/vtools/visualization/line/vistoolalongline.h index ed89fd874..a70a70ea3 100644 --- a/src/libs/vtools/visualization/line/vistoolalongline.h +++ b/src/libs/vtools/visualization/line/vistoolalongline.h @@ -43,14 +43,18 @@ class VisToolAlongLine :public VisLine { Q_OBJECT public: - explicit VisToolAlongLine(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolAlongLine() Q_DECL_OVERRIDE; + explicit VisToolAlongLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolAlongLine() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void setObject2Id(const quint32 &value); 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolAlongLine) quint32 object2Id; diff --git a/src/libs/vtools/visualization/line/vistoolbisector.cpp b/src/libs/vtools/visualization/line/vistoolbisector.cpp index 2f836e110..92ffbc3cd 100644 --- a/src/libs/vtools/visualization/line/vistoolbisector.cpp +++ b/src/libs/vtools/visualization/line/vistoolbisector.cpp @@ -76,8 +76,32 @@ void VisToolBisector::setLength(const QString &expression) } //--------------------------------------------------------------------------------------------------------------------- -VisToolBisector::~VisToolBisector() -{} +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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolBisector::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(line1P1->boundingRect()); + rect = rect.united(line1P2->boundingRect()); + rect = rect.united(line1->boundingRect()); + rect = rect.united(line2P2->boundingRect()); + rect = rect.united(line2->boundingRect()); + return rect; +} //--------------------------------------------------------------------------------------------------------------------- void VisToolBisector::RefreshGeometry() diff --git a/src/libs/vtools/visualization/line/vistoolbisector.h b/src/libs/vtools/visualization/line/vistoolbisector.h index 105b13054..3d8e5d40a 100644 --- a/src/libs/vtools/visualization/line/vistoolbisector.h +++ b/src/libs/vtools/visualization/line/vistoolbisector.h @@ -43,8 +43,8 @@ class VisToolBisector :public VisLine { Q_OBJECT public: - explicit VisToolBisector(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolBisector() Q_DECL_OVERRIDE; + explicit VisToolBisector(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolBisector() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void setObject2Id(const quint32 &value); @@ -52,6 +52,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolBisector) quint32 object2Id; diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp index d70282b03..6bba9c89e 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.cpp @@ -60,10 +60,6 @@ VisToolCurveIntersectAxis::VisToolCurveIntersectAxis(const VContainer *data, QGr point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolCurveIntersectAxis::~VisToolCurveIntersectAxis() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolCurveIntersectAxis::RefreshGeometry() { @@ -117,3 +113,29 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCurveIntersectAxis::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(basePoint->boundingRect()); + rect = rect.united(baseLine->boundingRect()); + rect = rect.united(axisLine->boundingRect()); + rect = rect.united(visCurve->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h index c82d6aa38..8138b47cc 100644 --- a/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h +++ b/src/libs/vtools/visualization/line/vistoolcurveintersectaxis.h @@ -43,8 +43,8 @@ class VisToolCurveIntersectAxis : public VisLine { Q_OBJECT public: - explicit VisToolCurveIntersectAxis(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolCurveIntersectAxis() Q_DECL_OVERRIDE; + explicit VisToolCurveIntersectAxis(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolCurveIntersectAxis() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -54,6 +54,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolCurveIntersectAxis) quint32 axisPointId; diff --git a/src/libs/vtools/visualization/line/vistoolendline.cpp b/src/libs/vtools/visualization/line/vistoolendline.cpp index cb875f437..7dd246cff 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.cpp +++ b/src/libs/vtools/visualization/line/vistoolendline.cpp @@ -55,10 +55,6 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent) point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolEndLine::~VisToolEndLine() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolEndLine::RefreshGeometry() { @@ -114,3 +110,21 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolEndLine::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolendline.h b/src/libs/vtools/visualization/line/vistoolendline.h index 37e377da4..9d464c706 100644 --- a/src/libs/vtools/visualization/line/vistoolendline.h +++ b/src/libs/vtools/visualization/line/vistoolendline.h @@ -43,8 +43,8 @@ class VisToolEndLine : public VisLine { Q_OBJECT public: - explicit VisToolEndLine(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolEndLine() Q_DECL_OVERRIDE; + explicit VisToolEndLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolEndLine() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -56,6 +56,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolEndLine) qreal length; diff --git a/src/libs/vtools/visualization/line/vistoolheight.cpp b/src/libs/vtools/visualization/line/vistoolheight.cpp index a2988d29d..4e63b7e63 100644 --- a/src/libs/vtools/visualization/line/vistoolheight.cpp +++ b/src/libs/vtools/visualization/line/vistoolheight.cpp @@ -56,10 +56,6 @@ VisToolHeight::VisToolHeight(const VContainer *data, QGraphicsItem *parent) point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolHeight::~VisToolHeight() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolHeight::RefreshGeometry() { @@ -116,6 +112,34 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolHeight::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(base_point->boundingRect()); + rect = rect.united(lineP1->boundingRect()); + rect = rect.united(lineP2->boundingRect()); + rect = rect.united(line->boundingRect()); + rect = rect.united(line_intersection->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 cc048d8bc..31b87b269 100644 --- a/src/libs/vtools/visualization/line/vistoolheight.h +++ b/src/libs/vtools/visualization/line/vistoolheight.h @@ -44,8 +44,8 @@ class VisToolHeight : public VisLine { Q_OBJECT public: - explicit VisToolHeight(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolHeight() Q_DECL_OVERRIDE; + explicit VisToolHeight(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolHeight() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -53,6 +53,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolHeight) //base point in parent class diff --git a/src/libs/vtools/visualization/line/vistoolline.cpp b/src/libs/vtools/visualization/line/vistoolline.cpp index 7b120c306..a591061af 100644 --- a/src/libs/vtools/visualization/line/vistoolline.cpp +++ b/src/libs/vtools/visualization/line/vistoolline.cpp @@ -48,10 +48,6 @@ VisToolLine::VisToolLine(const VContainer *data, QGraphicsItem *parent) this->mainColor = Qt::red; } -//--------------------------------------------------------------------------------------------------------------------- -VisToolLine::~VisToolLine() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolLine::RefreshGeometry() { @@ -80,6 +76,10 @@ void VisToolLine::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, cons { SCASSERT (lineItem != nullptr) - lineItem->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style)); + QPen visPen = lineItem->pen(); + visPen.setColor(color); + visPen.setStyle(style); + + lineItem->setPen(visPen); lineItem->setLine(line); } diff --git a/src/libs/vtools/visualization/line/vistoolline.h b/src/libs/vtools/visualization/line/vistoolline.h index 6c5d28cb1..5ca5f8d92 100644 --- a/src/libs/vtools/visualization/line/vistoolline.h +++ b/src/libs/vtools/visualization/line/vistoolline.h @@ -46,8 +46,8 @@ class VisToolLine : public VisLine { Q_OBJECT public: - explicit VisToolLine(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolLine() Q_DECL_OVERRIDE; + explicit VisToolLine(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolLine() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void setPoint2Id(const quint32 &value); diff --git a/src/libs/vtools/visualization/line/vistoollineintersect.cpp b/src/libs/vtools/visualization/line/vistoollineintersect.cpp index d416ecd63..7b09273b8 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersect.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersect.cpp @@ -56,10 +56,6 @@ VisToolLineIntersect::VisToolLineIntersect(const VContainer *data, QGraphicsItem point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolLineIntersect::~VisToolLineIntersect() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolLineIntersect::RefreshGeometry() { @@ -139,3 +135,31 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolLineIntersect::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(line1P1->boundingRect()); + rect = rect.united(line1P2->boundingRect()); + rect = rect.united(line1->boundingRect()); + rect = rect.united(line2P1->boundingRect()); + rect = rect.united(line2P2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoollineintersect.h b/src/libs/vtools/visualization/line/vistoollineintersect.h index 8eb710f2a..c70af6f76 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersect.h +++ b/src/libs/vtools/visualization/line/vistoollineintersect.h @@ -43,8 +43,8 @@ class VisToolLineIntersect :public VisLine { Q_OBJECT public: - explicit VisToolLineIntersect(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolLineIntersect() Q_DECL_OVERRIDE; + explicit VisToolLineIntersect(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolLineIntersect() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -53,6 +53,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolLineIntersect) quint32 line1P2Id; diff --git a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp index daa3489bf..0acb02502 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.cpp @@ -59,10 +59,6 @@ VisToolLineIntersectAxis::VisToolLineIntersectAxis(const VContainer *data, QGrap point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolLineIntersectAxis::~VisToolLineIntersectAxis() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolLineIntersectAxis::RefreshGeometry() { @@ -137,6 +133,36 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolLineIntersectAxis::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(lineP1->boundingRect()); + rect = rect.united(lineP2->boundingRect()); + rect = rect.united(basePoint->boundingRect()); + rect = rect.united(baseLine->boundingRect()); + rect = rect.united(axisLine->boundingRect()); + rect = rect.united(line_intersection->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 a23e14762..a499b87aa 100644 --- a/src/libs/vtools/visualization/line/vistoollineintersectaxis.h +++ b/src/libs/vtools/visualization/line/vistoollineintersectaxis.h @@ -44,8 +44,8 @@ class VisToolLineIntersectAxis : public VisLine { Q_OBJECT public: - explicit VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolLineIntersectAxis() Q_DECL_OVERRIDE; + explicit VisToolLineIntersectAxis(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolLineIntersectAxis() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -56,6 +56,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolLineIntersectAxis) quint32 point2Id; diff --git a/src/libs/vtools/visualization/line/vistoolnormal.cpp b/src/libs/vtools/visualization/line/vistoolnormal.cpp index 168f38eb2..8b4add163 100644 --- a/src/libs/vtools/visualization/line/vistoolnormal.cpp +++ b/src/libs/vtools/visualization/line/vistoolnormal.cpp @@ -57,10 +57,6 @@ VisToolNormal::VisToolNormal(const VContainer *data, QGraphicsItem *parent) point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolNormal::~VisToolNormal() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolNormal::RefreshGeometry() { @@ -128,3 +124,27 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolNormal::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(lineP1->boundingRect()); + rect = rect.united(lineP2->boundingRect()); + rect = rect.united(line->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolnormal.h b/src/libs/vtools/visualization/line/vistoolnormal.h index 697c14492..8fea0df51 100644 --- a/src/libs/vtools/visualization/line/vistoolnormal.h +++ b/src/libs/vtools/visualization/line/vistoolnormal.h @@ -43,8 +43,8 @@ class VisToolNormal : public VisLine { Q_OBJECT public: - explicit VisToolNormal(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolNormal() Q_DECL_OVERRIDE; + explicit VisToolNormal(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolNormal() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -54,6 +54,10 @@ public: void SetAngle(const qreal &value); 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolNormal) quint32 object2Id; diff --git a/src/libs/vtools/visualization/line/vistoolpin.cpp b/src/libs/vtools/visualization/line/vistoolpin.cpp index edc6b2df5..369a0d60f 100644 --- a/src/libs/vtools/visualization/line/vistoolpin.cpp +++ b/src/libs/vtools/visualization/line/vistoolpin.cpp @@ -38,7 +38,7 @@ VisToolPin::VisToolPin(const VContainer *data, QGraphicsItem *parent) this->mainColor = Qt::red; this->setZValue(2);// Show on top real tool - m_point = new VSimplePoint(NULL_ID, mainColor, *Visualization::data->GetPatternUnit(), &factor); + m_point = new VSimplePoint(NULL_ID, mainColor); m_point->SetPointHighlight(true); m_point->setParentItem(this); m_point->SetVisualizationMode(true); @@ -62,7 +62,7 @@ void VisToolPin::RefreshGeometry() const QSharedPointer point = Visualization::data->GeometricObject(object1Id); m_point->SetOnlyPoint(mode == Mode::Creation); - m_point->RefreshGeometry(*point); + m_point->RefreshPointGeometry(*point); m_point->setVisible(true); } } diff --git a/src/libs/vtools/visualization/line/vistoolpin.h b/src/libs/vtools/visualization/line/vistoolpin.h index abb013a44..089ada9ea 100644 --- a/src/libs/vtools/visualization/line/vistoolpin.h +++ b/src/libs/vtools/visualization/line/vistoolpin.h @@ -38,7 +38,7 @@ class VisToolPin : public VisLine Q_OBJECT public: explicit VisToolPin(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolPin() Q_DECL_OVERRIDE; + virtual ~VisToolPin(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp index a19011796..2a2ae8859 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.cpp @@ -57,10 +57,6 @@ VisToolPointFromArcAndTangent::VisToolPointFromArcAndTangent(const VContainer *d tangentLine2 = InitItem(supportColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointFromArcAndTangent::~VisToolPointFromArcAndTangent() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointFromArcAndTangent::RefreshGeometry() { @@ -95,6 +91,30 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointFromArcAndTangent::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(tangent->boundingRect()); + rect = rect.united(arcPath->boundingRect()); + rect = rect.united(tangentLine2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 934486e07..53d1aa5f6 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h @@ -45,8 +45,8 @@ class VisToolPointFromArcAndTangent : public VisLine { Q_OBJECT public: - explicit VisToolPointFromArcAndTangent(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointFromArcAndTangent() Q_DECL_OVERRIDE; + explicit VisToolPointFromArcAndTangent(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointFromArcAndTangent() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -55,6 +55,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointFromArcAndTangent) quint32 arcId; diff --git a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp index 1f5fbcb00..8178b2ae7 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.cpp @@ -54,10 +54,6 @@ VisToolPointFromCircleAndTangent::VisToolPointFromCircleAndTangent(const VContai tangent2 = InitItem(supportColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointFromCircleAndTangent::~VisToolPointFromCircleAndTangent() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointFromCircleAndTangent::RefreshGeometry() { @@ -105,6 +101,32 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointFromCircleAndTangent::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(tangent->boundingRect()); + rect = rect.united(cCenter->boundingRect()); + rect = rect.united(cPath->boundingRect()); + rect = rect.united(tangent2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 56707572f..b8bb5e509 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h +++ b/src/libs/vtools/visualization/line/vistoolpointfromcircleandtangent.h @@ -45,8 +45,8 @@ class VisToolPointFromCircleAndTangent : public VisLine { Q_OBJECT public: - explicit VisToolPointFromCircleAndTangent(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointFromCircleAndTangent() Q_DECL_OVERRIDE; + explicit VisToolPointFromCircleAndTangent(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointFromCircleAndTangent() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -56,6 +56,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointFromCircleAndTangent) quint32 object2Id; diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp index 598117425..2d8467df6 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.cpp @@ -55,10 +55,6 @@ VisToolPointOfContact::VisToolPointOfContact(const VContainer *data, QGraphicsIt point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointOfContact::~VisToolPointOfContact() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfContact::RefreshGeometry() { @@ -118,3 +114,29 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointOfContact::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(lineP1->boundingRect()); + rect = rect.united(lineP2->boundingRect()); + rect = rect.united(arc_point->boundingRect()); + rect = rect.united(circle->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolpointofcontact.h b/src/libs/vtools/visualization/line/vistoolpointofcontact.h index 094745963..ea31fd70c 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofcontact.h +++ b/src/libs/vtools/visualization/line/vistoolpointofcontact.h @@ -43,8 +43,8 @@ class VisToolPointOfContact : public VisLine { Q_OBJECT public: - explicit VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointOfContact() Q_DECL_OVERRIDE; + explicit VisToolPointOfContact(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointOfContact() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void setLineP2Id(const quint32 &value); @@ -52,6 +52,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfContact) quint32 lineP2Id; diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp index 9b333e399..77bf81bcc 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersection.cpp @@ -53,10 +53,6 @@ VisToolPointOfIntersection::VisToolPointOfIntersection(const VContainer *data, Q point = InitPoint(mainColor, this); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointOfIntersection::~VisToolPointOfIntersection() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersection::RefreshGeometry() { @@ -97,6 +93,30 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointOfIntersection::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(axisP1->boundingRect()); + rect = rect.united(axisP2->boundingRect()); + rect = rect.united(axis2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- 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 51be1e3cd..7b534b93c 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersection.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersection.h @@ -45,14 +45,18 @@ class VisToolPointOfIntersection : public VisLine { Q_OBJECT public: - explicit VisToolPointOfIntersection(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointOfIntersection() Q_DECL_OVERRIDE; + explicit VisToolPointOfIntersection(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointOfIntersection() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersection) quint32 point2Id; diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp index 0c1b43a75..431454eb3 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.cpp @@ -65,10 +65,6 @@ VisToolPointOfIntersectionArcs::VisToolPointOfIntersectionArcs(const VContainer point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointOfIntersectionArcs::~VisToolPointOfIntersectionArcs() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersectionArcs::RefreshGeometry() { @@ -118,3 +114,25 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointOfIntersectionArcs::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(arc1Path->boundingRect()); + rect = rect.united(arc2Path->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h index b781578da..9ad1a271d 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectionarcs.h @@ -44,8 +44,8 @@ class VisToolPointOfIntersectionArcs : public VisLine { Q_OBJECT public: - explicit VisToolPointOfIntersectionArcs(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointOfIntersectionArcs() Q_DECL_OVERRIDE; + explicit VisToolPointOfIntersectionArcs(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointOfIntersectionArcs() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; virtual void VisualMode(const quint32 &id) Q_DECL_OVERRIDE; @@ -56,6 +56,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionArcs) quint32 arc1Id; diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp index f40af28f8..d920fcb22 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.cpp @@ -59,10 +59,6 @@ VisToolPointOfIntersectionCircles::VisToolPointOfIntersectionCircles(const VCont c2Center = InitPoint(supportColor, this); //-V656 } -//--------------------------------------------------------------------------------------------------------------------- -VisToolPointOfIntersectionCircles::~VisToolPointOfIntersectionCircles() -{} - //--------------------------------------------------------------------------------------------------------------------- void VisToolPointOfIntersectionCircles::RefreshGeometry() { @@ -129,3 +125,30 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointOfIntersectionCircles::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(c1Center->boundingRect()); + rect = rect.united(c2Center->boundingRect()); + rect = rect.united(c1Path->boundingRect()); + rect = rect.united(c2Path->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h index cdc56b5cb..eb89a8e91 100644 --- a/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h +++ b/src/libs/vtools/visualization/line/vistoolpointofintersectioncircles.h @@ -44,8 +44,8 @@ class VisToolPointOfIntersectionCircles : public VisLine { Q_OBJECT public: - explicit VisToolPointOfIntersectionCircles(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolPointOfIntersectionCircles() Q_DECL_OVERRIDE; + explicit VisToolPointOfIntersectionCircles(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPointOfIntersectionCircles() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; virtual void VisualMode(const quint32 &id) Q_DECL_OVERRIDE; @@ -57,6 +57,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionCircles) quint32 object2Id; diff --git a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp index 3e63c1043..ec8b43da9 100644 --- a/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp +++ b/src/libs/vtools/visualization/line/vistoolshoulderpoint.cpp @@ -131,3 +131,33 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolShoulderPoint::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(line1P1->boundingRect()); + rect = rect.united(line1P2->boundingRect()); + rect = rect.united(line1->boundingRect()); + rect = rect.united(line2P2->boundingRect()); + rect = rect.united(line2->boundingRect()); + rect = rect.united(line3->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistoolshoulderpoint.h b/src/libs/vtools/visualization/line/vistoolshoulderpoint.h index 4e3280fe3..1cd946e03 100644 --- a/src/libs/vtools/visualization/line/vistoolshoulderpoint.h +++ b/src/libs/vtools/visualization/line/vistoolshoulderpoint.h @@ -44,7 +44,7 @@ class VisToolShoulderPoint : public VisLine Q_OBJECT public: explicit VisToolShoulderPoint(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolShoulderPoint() Q_DECL_EQ_DEFAULT; + virtual ~VisToolShoulderPoint() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; void setLineP1Id(const quint32 &value); @@ -52,6 +52,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolShoulderPoint) quint32 lineP1Id; diff --git a/src/libs/vtools/visualization/line/vistooltriangle.cpp b/src/libs/vtools/visualization/line/vistooltriangle.cpp index 627b52d7b..de2ec4566 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.cpp +++ b/src/libs/vtools/visualization/line/vistooltriangle.cpp @@ -143,20 +143,56 @@ void VisToolTriangle::setHypotenuseP2Id(const quint32 &value) hypotenuseP2Id = 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolTriangle::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(axisP1->boundingRect()); + rect = rect.united(axisP2->boundingRect()); + rect = rect.united(axis->boundingRect()); + rect = rect.united(hypotenuseP1->boundingRect()); + rect = rect.united(hypotenuseP2->boundingRect()); + rect = rect.united(foot1->boundingRect()); + rect = rect.united(foot2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolTriangle::DrawAimedAxis(QGraphicsPathItem *item, const QLineF &line, const QColor &color, Qt::PenStyle style) { SCASSERT (item != nullptr) - item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style)); + QPen visPen = item->pen(); + visPen.setColor(color); + visPen.setStyle(style); + + item->setPen(visPen); QPainterPath path; path.moveTo(line.p1()); path.lineTo(line.p2()); - qreal arrow_step = 60/factor; - qreal arrow_size = 10/factor; + qreal arrow_step = 60; + qreal arrow_size = 10; if (line.length() < arrow_step) { diff --git a/src/libs/vtools/visualization/line/vistooltriangle.h b/src/libs/vtools/visualization/line/vistooltriangle.h index a0f527231..b90fbcd7f 100644 --- a/src/libs/vtools/visualization/line/vistooltriangle.h +++ b/src/libs/vtools/visualization/line/vistooltriangle.h @@ -47,7 +47,7 @@ class VisToolTriangle : public VisLine Q_OBJECT public: explicit VisToolTriangle(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolTriangle() Q_DECL_EQ_DEFAULT; + virtual ~VisToolTriangle() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -57,6 +57,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolTriangle) quint32 object2Id;//axis second point diff --git a/src/libs/vtools/visualization/line/vistooltruedarts.cpp b/src/libs/vtools/visualization/line/vistooltruedarts.cpp index 5cc603f0a..88c095f96 100644 --- a/src/libs/vtools/visualization/line/vistooltruedarts.cpp +++ b/src/libs/vtools/visualization/line/vistooltruedarts.cpp @@ -163,3 +163,42 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolTrueDarts::boundingRect() const +{ + QRectF rect = VisLine::boundingRect(); + rect = rect.united(point1->boundingRect()); + rect = rect.united(point2->boundingRect()); + rect = rect.united(baseLineP1->boundingRect()); + rect = rect.united(baseLineP2->boundingRect()); + rect = rect.united(dartP1->boundingRect()); + rect = rect.united(dartP2->boundingRect()); + rect = rect.united(dartP3->boundingRect()); + rect = rect.united(lineblP1P1->boundingRect()); + rect = rect.united(lineblP2P2->boundingRect()); + rect = rect.united(p1d2->boundingRect()); + rect = rect.united(d2p2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/line/vistooltruedarts.h b/src/libs/vtools/visualization/line/vistooltruedarts.h index 07c538f69..fa89c8a67 100644 --- a/src/libs/vtools/visualization/line/vistooltruedarts.h +++ b/src/libs/vtools/visualization/line/vistooltruedarts.h @@ -44,7 +44,7 @@ class VisToolTrueDarts :public VisLine Q_OBJECT public: explicit VisToolTrueDarts(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolTrueDarts() Q_DECL_EQ_DEFAULT; + virtual ~VisToolTrueDarts() = default; virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -55,6 +55,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolTrueDarts) quint32 baseLineP2Id; diff --git a/src/libs/vtools/visualization/path/vispath.cpp b/src/libs/vtools/visualization/path/vispath.cpp index 0b72bf396..539c86b0f 100644 --- a/src/libs/vtools/visualization/path/vispath.cpp +++ b/src/libs/vtools/visualization/path/vispath.cpp @@ -45,11 +45,22 @@ 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); +} + //--------------------------------------------------------------------------------------------------------------------- void VisPath::InitPen() { - this->setPen(QPen(mainColor, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, - lineStyle)); + QPen visPen = pen(); + visPen.setColor(mainColor); + visPen.setStyle(lineStyle); + + setPen(visPen); } //--------------------------------------------------------------------------------------------------------------------- @@ -67,7 +78,7 @@ VSimplePoint *VisPath::GetPoint(QVector &points, quint32 i, cons } else { - VSimplePoint *point = new VSimplePoint(NULL_ID, color, *Visualization::data->GetPatternUnit(), &factor); + VSimplePoint *point = new VSimplePoint(NULL_ID, color); point->SetPointHighlight(true); point->setParentItem(this); point->SetVisualizationMode(true); diff --git a/src/libs/vtools/visualization/path/vispath.h b/src/libs/vtools/visualization/path/vispath.h index f5ae641df..6eb382e05 100644 --- a/src/libs/vtools/visualization/path/vispath.h +++ b/src/libs/vtools/visualization/path/vispath.h @@ -47,10 +47,13 @@ class VisPath : public Visualization, public VCurvePathItem Q_OBJECT public: explicit VisPath(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisPath() Q_DECL_EQ_DEFAULT; + virtual ~VisPath() = default; 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; protected: virtual void InitPen() Q_DECL_OVERRIDE; virtual void AddOnScene() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/path/vispiecepins.cpp b/src/libs/vtools/visualization/path/vispiecepins.cpp index c1a05a812..0bc203128 100644 --- a/src/libs/vtools/visualization/path/vispiecepins.cpp +++ b/src/libs/vtools/visualization/path/vispiecepins.cpp @@ -48,7 +48,7 @@ void VisPiecePins::RefreshGeometry() VSimplePoint *point = GetPoint(static_cast(i), supportColor); point->SetOnlyPoint(false); const QSharedPointer p = Visualization::data->GeometricObject(m_pins.at(i)); - point->RefreshGeometry(*p); + point->RefreshPointGeometry(*p); point->setVisible(true); } } diff --git a/src/libs/vtools/visualization/path/vistoolarc.cpp b/src/libs/vtools/visualization/path/vistoolarc.cpp index 46b66688c..0d8bf8180 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolarc.cpp @@ -82,3 +82,21 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolArc::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(arcCenter->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolarc.h b/src/libs/vtools/visualization/path/vistoolarc.h index 7b2702d27..bd799a71e 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.h +++ b/src/libs/vtools/visualization/path/vistoolarc.h @@ -52,6 +52,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolArc) QGraphicsEllipseItem *arcCenter; diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp index becb6a7ce..d6c2c26c3 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp @@ -82,3 +82,21 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolArcWithLength::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(arcCenter->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.h b/src/libs/vtools/visualization/path/vistoolarcwithlength.h index 53cc179bf..af7e76bd6 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.h +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.h @@ -52,6 +52,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolArcWithLength) QGraphicsEllipseItem *arcCenter; diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp index 2bed2ff9f..ec79ff46b 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.cpp @@ -135,3 +135,31 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCubicBezier::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(point1->boundingRect()); + rect = rect.united(point2->boundingRect()); + rect = rect.united(point3->boundingRect()); + rect = rect.united(point4->boundingRect()); + rect = rect.united(helpLine1->boundingRect()); + rect = rect.united(helpLine2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezier.h b/src/libs/vtools/visualization/path/vistoolcubicbezier.h index a59468db8..01215248f 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezier.h +++ b/src/libs/vtools/visualization/path/vistoolcubicbezier.h @@ -55,6 +55,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + protected: Q_DISABLE_COPY(VisToolCubicBezier) quint32 object2Id; diff --git a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp index 20e0adbc1..20b7cff37 100644 --- a/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcubicbezierpath.cpp @@ -141,6 +141,59 @@ VCubicBezierPath VisToolCubicBezierPath::getPath() return path; } +//--------------------------------------------------------------------------------------------------------------------- +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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCubicBezierPath::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + for (int i=0; i < mainPoints.size(); ++i) + { + rect = rect.united(mainPoints.at(i)->boundingRect()); + } + + for (int i=0; i < ctrlPoints.size(); ++i) + { + rect = rect.united(ctrlPoints.at(i)->boundingRect()); + } + + for (int i=0; i < lines.size(); ++i) + { + rect = rect.united(lines.at(i)->boundingRect()); + } + + rect = rect.united(newCurveSegment->boundingRect()); + rect = rect.united(helpLine1->boundingRect()); + rect = rect.united(helpLine2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector &points, quint32 i, qreal z) { @@ -154,7 +207,6 @@ QGraphicsEllipseItem *VisToolCubicBezierPath::getPoint(QVector(Vis::ToolCubicBezierPath)}; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + protected: Q_DISABLE_COPY(VisToolCubicBezierPath) QVector mainPoints; diff --git a/src/libs/vtools/visualization/path/vistoolcutarc.cpp b/src/libs/vtools/visualization/path/vistoolcutarc.cpp index 1952e8ba0..7bad09ee7 100644 --- a/src/libs/vtools/visualization/path/vistoolcutarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutarc.cpp @@ -83,3 +83,25 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCutArc::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(arc1->boundingRect()); + rect = rect.united(arc2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolcutarc.h b/src/libs/vtools/visualization/path/vistoolcutarc.h index 7a6c50da5..dc1784086 100644 --- a/src/libs/vtools/visualization/path/vistoolcutarc.h +++ b/src/libs/vtools/visualization/path/vistoolcutarc.h @@ -50,6 +50,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutArc) QGraphicsEllipseItem *point; diff --git a/src/libs/vtools/visualization/path/vistoolcutspline.cpp b/src/libs/vtools/visualization/path/vistoolcutspline.cpp index bf78d1eae..d38bac09f 100644 --- a/src/libs/vtools/visualization/path/vistoolcutspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutspline.cpp @@ -91,3 +91,25 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCutSpline::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(spl1->boundingRect()); + rect = rect.united(spl2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolcutspline.h b/src/libs/vtools/visualization/path/vistoolcutspline.h index 5f767ae49..6f4052ba4 100644 --- a/src/libs/vtools/visualization/path/vistoolcutspline.h +++ b/src/libs/vtools/visualization/path/vistoolcutspline.h @@ -50,6 +50,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutSpline) QGraphicsEllipseItem *point; diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp index 200310c6b..1b39c4d51 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.cpp @@ -93,3 +93,25 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolCutSplinePath::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(point->boundingRect()); + rect = rect.united(splPath1->boundingRect()); + rect = rect.united(splPath2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolcutsplinepath.h b/src/libs/vtools/visualization/path/vistoolcutsplinepath.h index 95ad6ca55..2c4166d46 100644 --- a/src/libs/vtools/visualization/path/vistoolcutsplinepath.h +++ b/src/libs/vtools/visualization/path/vistoolcutsplinepath.h @@ -50,6 +50,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; protected: Q_DISABLE_COPY(VisToolCutSplinePath) QGraphicsEllipseItem *point; diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp index 612b39b2a..c4cb6845c 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.cpp @@ -91,3 +91,21 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolEllipticalArc::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + rect = rect.united(arcCenter->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolellipticalarc.h b/src/libs/vtools/visualization/path/vistoolellipticalarc.h index a3432213e..0163f276f 100644 --- a/src/libs/vtools/visualization/path/vistoolellipticalarc.h +++ b/src/libs/vtools/visualization/path/vistoolellipticalarc.h @@ -54,6 +54,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolEllipticalArc) QGraphicsEllipseItem *arcCenter; diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index 38cdef19f..26b350fa3 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -78,10 +78,41 @@ void VisToolPiece::SetPiece(const VPiece &piece) m_piece = 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPiece::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + for (int i=0; i < m_points.size(); ++i) + { + rect = rect.united(m_points.at(i)->boundingRect()); + } + + rect = rect.united(m_line1->boundingRect()); + rect = rect.united(m_line2->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- QGraphicsEllipseItem *VisToolPiece::GetPoint(quint32 i, const QColor &color) { - return GetPointItem(Visualization::data, factor, m_points, i, color, this); + 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 5e35e2969..ce5cc32c4 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.h +++ b/src/libs/vtools/visualization/path/vistoolpiece.h @@ -46,6 +46,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPiece) QVector m_points; diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp index feade2a23..b74faa643 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -57,7 +57,7 @@ void VisToolPiecePath::RefreshGeometry() { VSimplePoint *point = GetPoint(static_cast(i), supportColor); point->SetOnlyPoint(mode == Mode::Creation); - point->RefreshGeometry(nodes.at(i)); + point->RefreshPointGeometry(nodes.at(i)); point->setVisible(true); } @@ -78,6 +78,35 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPiecePath::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + for (int i=0; i < m_points.size(); ++i) + { + rect = rect.united(m_points.at(i)->boundingRect()); + } + + rect = rect.united(m_line->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolPiecePath::mousePressEvent(QGraphicsSceneMouseEvent *event) { diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.h b/src/libs/vtools/visualization/path/vistoolpiecepath.h index 4d411ca8b..da33d27c9 100644 --- a/src/libs/vtools/visualization/path/vistoolpiecepath.h +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.h @@ -49,6 +49,10 @@ public: 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + protected: virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp index 525f356a5..7d67a4551 100644 --- a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp +++ b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.cpp @@ -107,3 +107,24 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolPointOfIntersectionCurves::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + rect = rect.united(point->boundingRect()); + rect = rect.united(visCurve2->boundingRect()); + return rect; +} diff --git a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h index b7550f3d8..9dfbf176f 100644 --- a/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h +++ b/src/libs/vtools/visualization/path/vistoolpointofintersectioncurves.h @@ -56,6 +56,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VisToolPointOfIntersectionCurves) quint32 object2Id; diff --git a/src/libs/vtools/visualization/path/vistoolspline.cpp b/src/libs/vtools/visualization/path/vistoolspline.cpp index bde97bc1b..d0091b34f 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.cpp +++ b/src/libs/vtools/visualization/path/vistoolspline.cpp @@ -67,11 +67,11 @@ VisToolSpline::VisToolSpline(const VContainer *data, QGraphicsItem *parent) point1 = InitPoint(supportColor, this); point4 = InitPoint(supportColor, this); //-V656 - auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, *data->GetPatternUnit(), this); + auto *controlPoint1 = new VControlPointSpline(1, SplinePointPosition::FirstPoint, this); controlPoint1->hide(); controlPoints.append(controlPoint1); - auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, *data->GetPatternUnit(), this); + auto *controlPoint2 = new VControlPointSpline(1, SplinePointPosition::LastPoint, this); controlPoint2->hide(); controlPoints.append(controlPoint2); } @@ -86,7 +86,7 @@ VisToolSpline::~VisToolSpline() void VisToolSpline::RefreshGeometry() { //Radius of point circle, but little bigger. Need handle with hover sizes. - const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + const static qreal radius = defPointRadiusPixel*1.5; if (object1Id > NULL_ID) { @@ -221,6 +221,27 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolSpline::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + rect = rect.united(point1->boundingRect()); + rect = rect.united(point4->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolSpline::MouseLeftPressed() { diff --git a/src/libs/vtools/visualization/path/vistoolspline.h b/src/libs/vtools/visualization/path/vistoolspline.h index 11d480ce7..cdc8c6e82 100644 --- a/src/libs/vtools/visualization/path/vistoolspline.h +++ b/src/libs/vtools/visualization/path/vistoolspline.h @@ -47,8 +47,8 @@ class VisToolSpline : public VisPath { Q_OBJECT public: - explicit VisToolSpline(const VContainer *data, QGraphicsItem *parent = 0); - virtual ~VisToolSpline() Q_DECL_OVERRIDE; + explicit VisToolSpline(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolSpline(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -65,6 +65,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + public slots: void MouseLeftPressed(); void MouseLeftReleased(); diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp index 6f1215bfd..fb3f4eb43 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.cpp @@ -139,6 +139,32 @@ 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); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VisToolSplinePath::boundingRect() const +{ + QRectF rect = VisPath::boundingRect(); + + for (int i=0; i < points.size(); ++i) + { + rect = rect.united(points.at(i)->boundingRect()); + } + + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::MouseLeftPressed() { @@ -174,23 +200,17 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) if (points.size() == 1) { - auto *controlPoint1 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, - *Visualization::data->GetPatternUnit(), - this); + auto *controlPoint1 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, this); controlPoint1->hide(); ctrlPoints.append(controlPoint1); } else { - auto *controlPoint1 = new VControlPointSpline(points.size()-1, SplinePointPosition::LastPoint, - *Visualization::data->GetPatternUnit(), - this); + auto *controlPoint1 = new VControlPointSpline(points.size()-1, SplinePointPosition::LastPoint, this); controlPoint1->hide(); ctrlPoints.append(controlPoint1); - auto *controlPoint2 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, - *Visualization::data->GetPatternUnit(), - this); + auto *controlPoint2 = new VControlPointSpline(points.size(), SplinePointPosition::FirstPoint, this); controlPoint2->hide(); ctrlPoints.append(controlPoint2); } @@ -203,9 +223,6 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::Creating(const QPointF &pSpl, int size) { - //Radius of point circle, but little bigger. Need handle with hover sizes. - const static qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; - int lastPoint = 0; int preLastPoint = 0; @@ -223,7 +240,8 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) if (not ctrlPoints[lastPoint]->isVisible()) { - if (QLineF(pSpl, ctrlPoint).length() > radius) + //Radius of point circle, but little bigger. Need handle with hover sizes. + if (QLineF(pSpl, ctrlPoint).length() > defPointRadiusPixel*1.5) { if (size == 1) { diff --git a/src/libs/vtools/visualization/path/vistoolsplinepath.h b/src/libs/vtools/visualization/path/vistoolsplinepath.h index fe9ef0f04..3a34f0033 100644 --- a/src/libs/vtools/visualization/path/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/path/vistoolsplinepath.h @@ -49,7 +49,7 @@ class VisToolSplinePath : public VisPath Q_OBJECT public: explicit VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = nullptr); - virtual ~VisToolSplinePath() Q_DECL_OVERRIDE; + virtual ~VisToolSplinePath(); virtual void RefreshGeometry() Q_DECL_OVERRIDE; @@ -59,6 +59,10 @@ 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; + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + signals: void PathChanged(const VSplinePath &path); diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index daa7b2aee..39f29e993 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -62,7 +62,6 @@ Q_LOGGING_CATEGORY(vVis, "v.visualization") Visualization::Visualization(const VContainer *data) :QObject(), data(data), - factor(VDrawTool::factor), scenePos(QPointF()), mainColor(Qt::red), supportColor(Qt::magenta), @@ -125,13 +124,6 @@ void Visualization::SetData(const VContainer *data) this->data = data; } -//--------------------------------------------------------------------------------------------------------------------- -void Visualization::SetFactor(qreal factor) -{ - CheckFactor(this->factor, factor); - RefreshGeometry(); -} - //--------------------------------------------------------------------------------------------------------------------- void Visualization::MousePos(const QPointF &scenePos) { @@ -144,17 +136,16 @@ void Visualization::MousePos(const QPointF &scenePos) } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const +void Visualization::ScalePoint(QGraphicsEllipseItem *item, qreal scale) { - return InitPointItem(Visualization::data, factor, color, parent, z); + ScaleCircleSize(item, scale); + ScalePenWidth(item, scale); } //--------------------------------------------------------------------------------------------------------------------- -QRectF Visualization::PointRect(qreal radius) +QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsItem *parent, qreal z) const { - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - return rec; + return InitPointItem(color, parent, z); } //--------------------------------------------------------------------------------------------------------------------- @@ -206,7 +197,12 @@ void Visualization::DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, c SCASSERT (point != nullptr) point->setPos(pos); - point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style)); + + QPen visPen = point->pen(); + visPen.setColor(color); + visPen.setStyle(style); + + point->setPen(visPen); point->setVisible(true); } @@ -215,7 +211,11 @@ void Visualization::DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, co { SCASSERT (lineItem != nullptr) - lineItem->setPen(QPen(color, qApp->toPixel(WidthHairLine(*Visualization::data->GetPatternUnit()))/factor, style)); + QPen visPen = lineItem->pen(); + visPen.setColor(color); + visPen.setStyle(style); + + lineItem->setPen(visPen); lineItem->setLine(line); lineItem->setVisible(true); } @@ -233,16 +233,19 @@ void Visualization::DrawPath(VCurvePathItem *pathItem, const QPainterPath &path, { SCASSERT (pathItem != nullptr) - pathItem->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor, style, - cap)); + QPen visPen = pathItem->pen(); + visPen.setColor(color); + visPen.setStyle(style); + visPen.setCapStyle(cap); + + pathItem->setPen(visPen); pathItem->setPath(path); pathItem->SetDirectionPath(direction); pathItem->setVisible(true); } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::GetPointItem(const VContainer *data, qreal factor, - QVector &points, quint32 i, +QGraphicsEllipseItem *Visualization::GetPointItem(QVector &points, quint32 i, const QColor &color, QGraphicsItem *parent) { if (not points.isEmpty() && static_cast(points.size() - 1) >= i) @@ -251,7 +254,7 @@ QGraphicsEllipseItem *Visualization::GetPointItem(const VContainer *data, qreal } else { - auto point = InitPointItem(data, factor, color, parent); + auto point = InitPointItem(color, parent); points.append(point); return point; } @@ -259,14 +262,17 @@ QGraphicsEllipseItem *Visualization::GetPointItem(const VContainer *data, qreal } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsEllipseItem *Visualization::InitPointItem(const VContainer *data, qreal factor, const QColor &color, - QGraphicsItem *parent, qreal z) +QGraphicsEllipseItem *Visualization::InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z) { QGraphicsEllipseItem *point = new QGraphicsEllipseItem(parent); point->setZValue(1); point->setBrush(QBrush(Qt::NoBrush)); - point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*data->GetPatternUnit()))/factor)); - point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); + + QPen visPen = point->pen(); + visPen.setColor(color); + + point->setPen(visPen); + point->setRect(PointRect(defPointRadiusPixel)); point->setPos(QPointF()); point->setFlags(QGraphicsItem::ItemStacksBehindParent); point->setZValue(z); diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index 201f3323e..177e822ff 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -40,6 +40,7 @@ #include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vcurvepathitem.h" +#include "../vwidgets/global.h" Q_DECLARE_LOGGING_CATEGORY(vVis) @@ -71,11 +72,9 @@ public: signals: void ToolTip(const QString &toolTip); public slots: - void SetFactor(qreal factor); void MousePos(const QPointF &scenePos); protected: const VContainer *data; - qreal factor; QPointF scenePos; QColor mainColor; QColor supportColor; @@ -87,6 +86,11 @@ 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, Qt::PenStyle style = Qt::SolidLine); @@ -103,15 +107,12 @@ protected: template Item *InitItem(const QColor &color, QGraphicsItem *parent); - static QRectF PointRect(qreal radius); - static QGraphicsEllipseItem* GetPointItem(const VContainer *data, qreal factor, - QVector &points, quint32 i, const QColor &color, + static QGraphicsEllipseItem* GetPointItem(QVector &points, quint32 i, const QColor &color, QGraphicsItem *parent); private: Q_DISABLE_COPY(Visualization) - static QGraphicsEllipseItem* InitPointItem(const VContainer *data, qreal factor, const QColor &color, - QGraphicsItem *parent, qreal z = 0); + static QGraphicsEllipseItem* InitPointItem(const QColor &color, QGraphicsItem *parent, qreal z = 0); }; //--------------------------------------------------------------------------------------------------------------------- @@ -123,7 +124,6 @@ inline void Visualization::AddItem(Item *item) SCASSERT(scene != nullptr) scene->addItem(item); - connect(scene, &VMainGraphicsScene::NewFactor, item, &Visualization::SetFactor); connect(scene, &VMainGraphicsScene::mouseMove, item, &Visualization::MousePos); } @@ -132,11 +132,29 @@ template inline Item *Visualization::InitItem(const QColor &color, QGraphicsItem *parent) { Item *item = new Item(parent); - item->setPen(QPen(color, qApp->toPixel(WidthHairLine(*data->GetPatternUnit()))/factor)); + + QPen visPen = item->pen(); + visPen.setColor(color); + + item->setPen(visPen); item->setZValue(1); item->setFlags(QGraphicsItem::ItemStacksBehindParent); item->setVisible(false); 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/global.cpp b/src/libs/vwidgets/global.cpp new file mode 100644 index 000000000..0620c4e4b --- /dev/null +++ b/src/libs/vwidgets/global.cpp @@ -0,0 +1,106 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 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 "global.h" +#include "../vmisc/def.h" + +#include +#include +#include + +const qreal defPointRadiusPixel = (2./*mm*/ / 25.4) * PrintDPI; +const qreal widthMainLine = (1.2/*mm*/ / 25.4) * PrintDPI; +const qreal widthHairLine = widthMainLine/3.0; + +qreal SceneScale(QGraphicsScene *scene) +{ + qreal scale = 1; + + if (scene) + { + const QList views = scene->views(); + if (not views.isEmpty()) + { + scale = views.first()->transform().m11(); + } + } + + return scale; +} + +//--------------------------------------------------------------------------------------------------------------------- +QColor CorrectColor(const QGraphicsItem *item, const QColor &color) +{ + SCASSERT(item != nullptr) + + if (item->isEnabled()) + { + return color; + } + else + { + return Qt::gray; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF PointRect(qreal radius) +{ + QRectF rec = QRectF(0, 0, radius*2, radius*2); + rec.translate(-rec.center().x(), -rec.center().y()); + return rec; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal ScaledRadius(qreal scale) +{ + qreal scaledRadius = defPointRadiusPixel; + if (scale > 1) + { + scaledRadius = qMax(defPointRadiusPixel/12, defPointRadiusPixel/scale); + } + return scaledRadius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void ScaleCircleSize(QGraphicsEllipseItem *item, qreal scale) +{ + SCASSERT(item != nullptr) + + item->setRect(PointRect(ScaledRadius(scale))); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal ScaleWidth(qreal width, qreal scale) +{ + if (scale > 1) + { + width = qMax(0.1, width/scale); + } + return width; +} diff --git a/src/libs/vwidgets/global.h b/src/libs/vwidgets/global.h new file mode 100644 index 000000000..13e761a07 --- /dev/null +++ b/src/libs/vwidgets/global.h @@ -0,0 +1,54 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 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 GLOBAL_H +#define GLOBAL_H + +#include + +extern const qreal defPointRadiusPixel; +extern const qreal widthMainLine; +extern const qreal widthHairLine; + +class QGraphicsScene; +class QGraphicsItem; +class QGraphicsEllipseItem; +class QGraphicsLineItem; +class QColor; +class QRectF; + +qreal SceneScale(QGraphicsScene *scene); + +QColor CorrectColor(const QGraphicsItem *item, const QColor &color); + +QRectF PointRect(qreal radius); +qreal ScaledRadius(qreal scale); +void ScaleCircleSize(QGraphicsEllipseItem *item, qreal scale); +qreal ScaleWidth(qreal width, qreal scale); + +#endif // GLOBAL_H diff --git a/src/libs/vwidgets/vabstractsimple.cpp b/src/libs/vwidgets/vabstractsimple.cpp index 81cd29828..7ac7409f6 100644 --- a/src/libs/vwidgets/vabstractsimple.cpp +++ b/src/libs/vwidgets/vabstractsimple.cpp @@ -28,53 +28,21 @@ #include "vabstractsimple.h" -const qreal VAbstractSimple::m_defFactor = 1; - //--------------------------------------------------------------------------------------------------------------------- -VAbstractSimple::VAbstractSimple(quint32 id, Unit patternUnit, qreal *factor, QObject *parent) +VAbstractSimple::VAbstractSimple(quint32 id, QObject *parent) : QObject(parent), id (id), - factor(factor), - enabled(true), - patternUnit(patternUnit), selectionType(SelectionType::ByMouseRelease), type(GOType::Unknown) { - if (this->factor == nullptr) - { - this->factor = const_cast(&m_defFactor); - } } -//--------------------------------------------------------------------------------------------------------------------- -VAbstractSimple::~VAbstractSimple() -{} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractSimple::ToolSelectionType(const SelectionType &type) { selectionType = type; } -//--------------------------------------------------------------------------------------------------------------------- -QColor VAbstractSimple::CorrectColor(const QColor &color) const -{ - if (enabled) - { - return color; - } - else - { - return Qt::gray; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractSimple::SetEnabled(bool enabled) -{ - this->enabled = enabled; -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) { diff --git a/src/libs/vwidgets/vabstractsimple.h b/src/libs/vwidgets/vabstractsimple.h index 6d4e97eda..23b624777 100644 --- a/src/libs/vwidgets/vabstractsimple.h +++ b/src/libs/vwidgets/vabstractsimple.h @@ -47,11 +47,10 @@ class VAbstractSimple : public QObject { Q_OBJECT public: - VAbstractSimple(quint32 id, Unit patternUnit, qreal *factor = nullptr, QObject *parent = nullptr); - virtual ~VAbstractSimple(); + VAbstractSimple(quint32 id, QObject *parent = nullptr); + virtual ~VAbstractSimple() = default; virtual void ToolSelectionType(const SelectionType &type); - virtual void SetEnabled(bool enabled); GOType GetType() const; void SetType(const GOType &value); @@ -67,34 +66,12 @@ protected: /** @brief id spline id. */ quint32 id; - /** @brief factor scale factor. */ - qreal *factor; - - bool enabled; - - Unit patternUnit; - SelectionType selectionType; GOType type; - QColor CorrectColor(const QColor &color) const; - - template - void SetPen(T *item, const QColor &color, qreal width, Qt::PenStyle penStyle = Qt::SolidLine); - private: Q_DISABLE_COPY(VAbstractSimple) - - const static qreal m_defFactor; }; -//--------------------------------------------------------------------------------------------------------------------- -template -void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width, Qt::PenStyle penStyle) -{ - SCASSERT(item) - item->setPen(QPen(CorrectColor(color), ToPixel(width, patternUnit)/ *factor, penStyle, Qt::RoundCap)); -} - #endif // VABSTRACTSIMPLE_H diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index afcf0a4a8..f4e161dc9 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -43,20 +43,18 @@ #include #include -#include "../ifc/ifcdef.h" +#include "../vwidgets/global.h" #include "../vgeometry/vgobject.h" #include "vmaingraphicsscene.h" #include "vmaingraphicsview.h" +#include "vgraphicssimpletextitem.h" //--------------------------------------------------------------------------------------------------------------------- -VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit, - QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), - radius(CircleRadius()), +VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem *parent) + : VScenePoint(parent), controlLine(nullptr), indexSpline(indexSpline), position(position), - patternUnit(patternUnit), freeAngle(true), freeLength(true) { @@ -73,14 +71,12 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP * @param parent parent object. */ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, - const QPointF &controlPoint, const QPointF &splinePoint, Unit patternUnit, - bool freeAngle, bool freeLength, QGraphicsItem *parent) - :QGraphicsEllipseItem(parent), - radius(CircleRadius()), + const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle, + bool freeLength, QGraphicsItem *parent) + : VScenePoint(parent), controlLine(nullptr), indexSpline(indexSpline), position(position), - patternUnit(patternUnit), freeAngle(freeAngle), freeLength(freeLength) { @@ -101,6 +97,24 @@ VControlPointSpline::~VControlPointSpline() RestoreOverrideCursor(cursorArrowOpenHand); } +//--------------------------------------------------------------------------------------------------------------------- +void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + const qreal scale = SceneScale(scene()); + + ScaleLinePenWidth(controlLine, scale); + + VScenePoint::paint(painter, option, widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VControlPointSpline::boundingRect() const +{ + QRectF rect = VScenePoint::boundingRect(); + rect = rect.united(controlLine->boundingRect()); + return rect; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief hoverEnterEvent handle hover enter events. @@ -108,24 +122,22 @@ VControlPointSpline::~VControlPointSpline() */ void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, ToPixel(WidthMainLine(patternUnit), patternUnit))); if (freeAngle || freeLength) { SetOverrideCursor(cursorArrowOpenHand, 1, 1); } - QGraphicsEllipseItem::hoverEnterEvent(event); + VScenePoint::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); if (freeAngle || freeLength) { //Disable cursor-arrow-openhand RestoreOverrideCursor(cursorArrowOpenHand); } - QGraphicsEllipseItem::hoverLeaveEvent(event); + VScenePoint::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -211,7 +223,7 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang default: break; } - return QGraphicsItem::itemChange(change, value); + return VScenePoint::itemChange(change, value); } //--------------------------------------------------------------------------------------------------------------------- @@ -224,7 +236,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } - QGraphicsEllipseItem::mousePressEvent(event); + VScenePoint::mousePressEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -238,7 +250,7 @@ void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) RestoreOverrideCursor(cursorArrowCloseHand); } } - QGraphicsEllipseItem::mouseReleaseEvent(event); + VScenePoint::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -250,15 +262,17 @@ void VControlPointSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::Init() { - auto rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); + m_baseColor = Qt::red; + SetOnlyPoint(true); this->setBrush(QBrush(Qt::NoBrush)); this->setZValue(100); controlLine = new QGraphicsLineItem(this); - controlLine->setPen(QPen(Qt::red, ToPixel(WidthHairLine(patternUnit), patternUnit))); + + QPen cPen = controlLine->pen(); + cPen.setBrush(QBrush(Qt::red)); + + controlLine->setPen(cPen); controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); } @@ -266,7 +280,8 @@ void VControlPointSpline::Init() void VControlPointSpline::SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint) { QPointF p1, p2; - VGObject::LineIntersectCircle(QPointF(), radius, QLineF( QPointF(), splinePoint-controlPoint), p1, p2); + VGObject::LineIntersectCircle(QPointF(), ScaledRadius(SceneScale(scene())), + QLineF( QPointF(), splinePoint-controlPoint), p1, p2); controlLine->setLine(QLineF(splinePoint-controlPoint, p1)); } @@ -298,18 +313,10 @@ void VControlPointSpline::RefreshCtrlPoint(const qint32 &indexSpline, SplinePoin */ void VControlPointSpline::setEnabledPoint(bool enable) { - if (enable == true) - { - this->setPen(QPen(Qt::black, ToPixel(WidthHairLine(patternUnit), patternUnit))); - this->setFlag(QGraphicsItem::ItemIsSelectable, true); - this->setFlag(QGraphicsItem::ItemIsMovable, true); - this->setAcceptHoverEvents(true); - } - else - { - this->setPen(QPen(Qt::gray, ToPixel(WidthHairLine(patternUnit), patternUnit))); - this->setFlag(QGraphicsItem::ItemIsSelectable, false); - this->setFlag(QGraphicsItem::ItemIsMovable, false); - this->setAcceptHoverEvents(false); - } + setEnabled(enable); + controlLine->setEnabled(enable); + + setFlag(QGraphicsItem::ItemIsSelectable, enable); + setFlag(QGraphicsItem::ItemIsMovable, enable); + setAcceptHoverEvents(enable); } diff --git a/src/libs/vwidgets/vcontrolpointspline.h b/src/libs/vwidgets/vcontrolpointspline.h index 38fb3415f..b10dbc334 100644 --- a/src/libs/vwidgets/vcontrolpointspline.h +++ b/src/libs/vwidgets/vcontrolpointspline.h @@ -30,7 +30,6 @@ #define VCONTROLPOINTSPLINE_H #include -#include #include #include #include @@ -42,23 +41,26 @@ #include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vsplinepath.h" #include "../vmisc/def.h" +#include "vscenepoint.h" /** * @brief The VControlPointSpline class control spline point. */ -class VControlPointSpline : public QObject, public QGraphicsEllipseItem +class VControlPointSpline : public QObject, public VScenePoint { Q_OBJECT public: - VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, Unit patternUnit, - QGraphicsItem * parent = nullptr); + VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem * parent = nullptr); VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, - const QPointF &splinePoint, Unit patternUnit, bool freeAngle, bool freeLength, - QGraphicsItem * parent = nullptr); - virtual ~VControlPointSpline() Q_DECL_OVERRIDE; + const QPointF &splinePoint, bool freeAngle, bool freeLength, QGraphicsItem * parent = nullptr); + virtual ~VControlPointSpline(); 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; signals: /** * @brief ControlPointChangePosition emit when control point change position. @@ -78,9 +80,6 @@ public slots: const QPointF &splinePoint, bool freeAngle = true, bool freeLength = true); void setEnabledPoint(bool enable); protected: - /** @brief radius radius circle. */ - const qreal radius; - /** @brief controlLine pointer to line control point. */ QGraphicsLineItem *controlLine; @@ -98,20 +97,11 @@ private: /** @brief position position point in spline. */ SplinePointPosition position; - Unit patternUnit; - bool freeAngle; bool freeLength; - inline qreal CircleRadius() const; void Init(); void SetCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint); }; -//--------------------------------------------------------------------------------------------------------------------- -qreal VControlPointSpline::CircleRadius() const -{ - return (1.5/*mm*/ / 25.4) * PrintDPI; -} - #endif // VCONTROLPOINTSPLINE_H diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 1062c3257..5d0ecbf0f 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -189,7 +189,6 @@ void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) */ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event) if (flags() & QGraphicsItem::ItemIsMovable) { //Disable cursor-arrow-openhand diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index 52092f3b2..62fef5c91 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -52,7 +52,7 @@ public: explicit VGraphicsSimpleTextItem( const QString & text, QGraphicsItem *parent = nullptr ); virtual ~VGraphicsSimpleTextItem() Q_DECL_OVERRIDE; - qint32 FontSize()const; + qint32 BaseFontSize()const; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::GraphicsSimpleTextItem)}; @@ -91,7 +91,7 @@ private: * @brief FontSize return label font size. * @return font size. */ -inline qint32 VGraphicsSimpleTextItem::FontSize() const +inline qint32 VGraphicsSimpleTextItem::BaseFontSize() const { return fontSize; } diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index e388961c7..e3eae8a6c 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -41,7 +41,7 @@ #include #include -#include "../ifc/ifcdef.h" +#include "global.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -51,7 +51,6 @@ VMainGraphicsScene::VMainGraphicsScene(QObject *parent) : QGraphicsScene(parent), horScrollBar(0), verScrollBar(0), - scaleFactor(1), _transform(QTransform()), scenePos(QPointF()), origins() @@ -64,8 +63,12 @@ VMainGraphicsScene::VMainGraphicsScene(QObject *parent) * @param parent parent object. */ VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) - :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()), - scenePos(QPointF()), origins() + :QGraphicsScene ( sceneRect, parent ), + horScrollBar(0), + verScrollBar(0), + _transform(QTransform()), + scenePos(), + origins() {} //--------------------------------------------------------------------------------------------------------------------- @@ -114,7 +117,7 @@ void VMainGraphicsScene::InitOrigins() { origins.clear(); - QPen originsPen(Qt::green, ToPixel(WidthHairLine(Unit::Mm), Unit::Mm), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + QPen originsPen(Qt::green, widthHairLine, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QBrush axisTextBrush(Qt::green); const qreal arrowAngle = 35.0; const qreal arrowLength = 12.0; @@ -275,17 +278,6 @@ void VMainGraphicsScene::SelectedItem(bool selected, quint32 object, quint32 too emit SelectedObject(selected, object, tool); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetFactor set current scale factor of scene. - * @param factor scene scale factor. scene scale factor. - */ -void VMainGraphicsScene::SetFactor(qreal factor) -{ - scaleFactor=scaleFactor*factor; - emit NewFactor(scaleFactor); -} - //--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsScene::EnableItemMove(bool move) { diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index 7a6b32e04..745dc7cd5 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -66,7 +66,6 @@ public: public slots: void ChoosedItem(quint32 id, const SceneObject &type); void SelectedItem(bool selected, quint32 object, quint32 tool); - void SetFactor(qreal factor); void EnableItemMove(bool move); void EnableDetailsMode(bool mode); void ItemsSelection(const SelectionType &type); @@ -115,11 +114,6 @@ signals: */ void ChoosedObject(quint32 id, SceneObject type); void SelectedObject(bool selected, quint32 object, quint32 tool); - /** - * @brief NewFactor send new scale factor. - * @param factor scene scale factor. - */ - void NewFactor(qreal factor); void DisableItem(bool disable, const QString &namePP); void EnableToolMove(bool move); void CurveDetailsMode(bool mode); @@ -157,9 +151,6 @@ private: /** @brief verScrollBar value vertical scroll bar. */ qint32 verScrollBar; - /** @brief scaleFactor scale factor. */ - qreal scaleFactor; - /** @brief _transform view transform value. */ QTransform _transform; QPointF scenePos; diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 1e0dfbea4..58c1ce3af 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -365,7 +365,6 @@ void VMainGraphicsView::ZoomIn() { scale(1.1, 1.1); VMainGraphicsView::NewSceneRect(this->scene(), this); - emit NewFactor(1.1); } } @@ -378,7 +377,6 @@ void VMainGraphicsView::ZoomOut() { scale(1.0/1.1, 1.0/1.1); VMainGraphicsView::NewSceneRect(this->scene(), this); - emit NewFactor(1.0/1.1); } } @@ -390,7 +388,6 @@ void VMainGraphicsView::ZoomOriginal() trans.m33()); this->setTransform(trans); VMainGraphicsView::NewSceneRect(this->scene(), this); - emit NewFactor(1.0); } //--------------------------------------------------------------------------------------------------------------------- @@ -418,8 +415,6 @@ void VMainGraphicsView::ZoomFitBest() this->setTransform(transform); VMainGraphicsView::NewSceneRect(scene(), this); - - emit NewFactor(factor); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vmaingraphicsview.h b/src/libs/vwidgets/vmaingraphicsview.h index 5e5f24cb4..d0699b748 100644 --- a/src/libs/vwidgets/vmaingraphicsview.h +++ b/src/libs/vwidgets/vmaingraphicsview.h @@ -125,11 +125,6 @@ public: static qreal MaxScale(); signals: - /** - * @brief NewFactor send new scale factor. - * @param factor scene scale factor. - */ - void NewFactor(qreal factor); /** * @brief MouseRelease help catch mouse release event. * diff --git a/src/libs/vwidgets/vscenepoint.cpp b/src/libs/vwidgets/vscenepoint.cpp new file mode 100644 index 000000000..668d42d5f --- /dev/null +++ b/src/libs/vwidgets/vscenepoint.cpp @@ -0,0 +1,196 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 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 "vscenepoint.h" +#include "../vmisc/def.h" +#include "../vgeometry/vpointf.h" +#include "global.h" +#include "vgraphicssimpletextitem.h" + +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VScenePoint::VScenePoint(QGraphicsItem *parent) + : QGraphicsEllipseItem(parent), + m_namePoint(nullptr), + m_lineName(nullptr), + m_onlyPoint(false), + m_isHovered(false), + m_baseColor(Qt::black) +{ + m_namePoint = new VGraphicsSimpleTextItem(this); + m_lineName = new QGraphicsLineItem(this); + this->setBrush(QBrush(Qt::NoBrush)); + this->setAcceptHoverEvents(true); + this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + const qreal scale = SceneScale(scene()); + + if (m_namePoint->BaseFontSize()*scale < 1) + { + m_namePoint->setVisible(false); + m_lineName->setVisible(false); + } + else + { + ScaleMainPenWidth(scale); + ScaleCircleSize(this, scale); + + if (not m_onlyPoint) + { + m_namePoint->setVisible(true); + m_lineName->setVisible(true); + + ScaleLabelFontSize(scale); + ScaleLinePenWidth(m_lineName, scale); + + RefreshLine(); + } + } + + QGraphicsEllipseItem::paint(painter, option, widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::RefreshPointGeometry(const VPointF &point) +{ + setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); + setPos(static_cast(point)); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + m_namePoint->blockSignals(true); + m_namePoint->setText(point.name()); + m_namePoint->setPos(QPointF(point.mx(), point.my())); + m_namePoint->blockSignals(false); + + RefreshLine(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VScenePoint::boundingRect() const +{ + QRectF rect = QGraphicsEllipseItem::boundingRect(); + rect = rect.united(m_namePoint->boundingRect()); + rect = rect.united(m_lineName->boundingRect()); + return rect; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::SetOnlyPoint(bool value) +{ + m_onlyPoint = value; + m_namePoint->setVisible(not m_onlyPoint); + m_lineName->setVisible(not m_onlyPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VScenePoint::IsOnlyPoint() const +{ + return m_onlyPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_isHovered = true; + QGraphicsEllipseItem::hoverEnterEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + m_isHovered = false; + QGraphicsEllipseItem::hoverLeaveEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::RefreshLine() +{ + QRectF nRec = m_namePoint->sceneBoundingRect(); + nRec.translate(- scenePos()); + if (not rect().intersects(nRec)) + { + const QRectF nameRec = m_namePoint->sceneBoundingRect(); + QPointF p1, p2; + VGObject::LineIntersectCircle(QPointF(), ScaledRadius(SceneScale(scene())), + QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); + const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); + m_lineName->setLine(QLineF(p1, pRec - scenePos())); + + if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) + { + m_lineName->setVisible(false); + } + else + { + m_lineName->setVisible(true); + } + } + else + { + m_lineName->setVisible(false); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::ScaleMainPenWidth(qreal scale) +{ + const qreal width = ScaleWidth(m_isHovered ? widthMainLine : widthHairLine, scale); + + setPen(QPen(CorrectColor(this, m_baseColor), width)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VScenePoint::ScaleLabelFontSize(qreal scale) const +{ + qreal fontSize = m_namePoint->BaseFontSize(); + if (scale > 1) + { + fontSize = qMax(0.1, fontSize/scale); + } + + QFont font = m_namePoint->font(); + font.setPointSizeF(fontSize); + m_namePoint->setFont(font); +} + +//--------------------------------------------------------------------------------------------------------------------- +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 new file mode 100644 index 000000000..b22aa06d0 --- /dev/null +++ b/src/libs/vwidgets/vscenepoint.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 14 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 VSCENEPOINT_H +#define VSCENEPOINT_H + +#include +#include + +class VGraphicsSimpleTextItem; +class VPointF; + +class VScenePoint: public QGraphicsEllipseItem +{ +public: + VScenePoint(QGraphicsItem *parent = nullptr); + ~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; + +protected: + /** @brief namePoint point label. */ + VGraphicsSimpleTextItem *m_namePoint; + + /** @brief lineName line what we see if label moved too away from point. */ + QGraphicsLineItem *m_lineName; + + bool m_onlyPoint; + bool m_isHovered; + + /** @brief m_baseColor base color of point. */ + QColor m_baseColor; + + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; + + void RefreshLine(); + void ScaleLinePenWidth(QGraphicsLineItem *line, qreal scale); + + void SetOnlyPoint(bool value); + bool IsOnlyPoint() const; +private: + Q_DISABLE_COPY(VScenePoint) + + void ScaleMainPenWidth(qreal scale); + void ScaleLabelFontSize(qreal scale) const; +}; + +#endif // VSCENEPOINT_H diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp index 350943b53..fbc30486b 100644 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -39,39 +39,62 @@ #include #include -#include "../ifc/ifcdef.h" +#include "global.h" #include "../vgeometry/vabstractcurve.h" +#include "../vmisc/vabstractapplication.h" template class QSharedPointer; //--------------------------------------------------------------------------------------------------------------------- -VSimpleCurve::VSimpleCurve(quint32 id, const QSharedPointer &curve, Unit patternUnit, qreal *factor, - QObject *parent) - : VAbstractSimple(id, patternUnit, factor, parent), +VSimpleCurve::VSimpleCurve(quint32 id, const QSharedPointer &curve, QObject *parent) + : VAbstractSimple(id, parent), VCurvePathItem(), m_curve(curve), m_isHovered(false) { this->setBrush(QBrush(Qt::NoBrush)); - SetPen(this, m_curve->GetColor(), WidthHairLine(patternUnit), LineStyleToPenStyle(m_curve->GetPenStyle())); this->setAcceptHoverEvents(true); 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) { m_curve = curve; - setPen(QPen(CorrectColor(m_curve->GetColor()), pen().width(), LineStyleToPenStyle(m_curve->GetPenStyle()), - Qt::RoundCap)); - ShowPath(); -} -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::SetEnabled(bool enabled) -{ - VAbstractSimple::SetEnabled(enabled); - SetPen(this, m_curve->GetColor(), WidthHairLine(patternUnit), LineStyleToPenStyle(m_curve->GetPenStyle())); + if (not m_curve.isNull()) + { + m_isHovered ? SetDirectionPath(m_curve->GetDirectionPath()) : SetDirectionPath(QPainterPath()); + setPath(m_curve->GetPath()); + } + else + { + qWarning() << tr("VSimpleCurve::RefreshGeometry: pointer to curve is null."); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -128,8 +151,6 @@ void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { m_isHovered = true; - SetPen(this, m_curve->GetColor(), WidthMainLine(patternUnit), LineStyleToPenStyle(m_curve->GetPenStyle())); - ShowPath(); QGraphicsPathItem::hoverEnterEvent(event); } @@ -137,8 +158,6 @@ void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { m_isHovered = false; - SetPen(this, m_curve->GetColor(), WidthHairLine(patternUnit), LineStyleToPenStyle(m_curve->GetPenStyle())); - ShowPath(); QGraphicsPathItem::hoverLeaveEvent(event); } @@ -172,17 +191,3 @@ void VSimpleCurve::keyReleaseEvent(QKeyEvent *event) } QGraphicsPathItem::keyReleaseEvent ( event ); } - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::ShowPath() -{ - if (not m_curve.isNull()) - { - m_isHovered ? SetDirectionPath(m_curve->GetDirectionPath()) : SetDirectionPath(QPainterPath()); - setPath(m_curve->GetPath()); - } - else - { - qWarning() << tr("VSimpleCurve::RefreshGeometry: pointer to curve is null."); - } -} diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h index ac26b7ec3..db9c9aa44 100644 --- a/src/libs/vwidgets/vsimplecurve.h +++ b/src/libs/vwidgets/vsimplecurve.h @@ -50,16 +50,16 @@ class VSimpleCurve : public VAbstractSimple, public VCurvePathItem { Q_OBJECT public: - VSimpleCurve(quint32 id, const QSharedPointer &curve, Unit patternUnit, qreal *factor = nullptr, - QObject *parent = nullptr); + VSimpleCurve(quint32 id, const QSharedPointer &curve, QObject *parent = nullptr); virtual ~VSimpleCurve() Q_DECL_EQ_DEFAULT; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimpleCurve)}; - void RefreshGeometry(const QSharedPointer &curve); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) Q_DECL_OVERRIDE; - virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; + void RefreshGeometry(const QSharedPointer &curve); signals: /** * @brief Choosed send id when clicked. @@ -86,8 +86,6 @@ private: QSharedPointer m_curve; bool m_isHovered; - - void ShowPath(); }; #endif // VSIMPLECURVE_H diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 46dd18bfe..12ab1ab42 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -41,59 +41,32 @@ #include #include -#include "../ifc/ifcdef.h" +#include "global.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" #include "vgraphicssimpletextitem.h" +#include "../vmisc/vabstractapplication.h" //--------------------------------------------------------------------------------------------------------------------- -VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) - : VAbstractSimple(id, patternUnit, factor, parent), - QGraphicsEllipseItem(), - radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), - namePoint(nullptr), - lineName(nullptr), - m_onlyPoint(false), - m_isHighlight(false), +VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, QObject *parent) + : VAbstractSimple(id, parent), + VScenePoint(), m_visualizationMode(false), - currentColor(currentColor) + m_alwaysHovered(false) { - namePoint = new VGraphicsSimpleTextItem(this); - connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); - connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel); - connect(namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed); - connect(namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VSimplePoint::ChangedPosition); - lineName = new QGraphicsLineItem(this); - this->setBrush(QBrush(Qt::NoBrush)); - SetPen(this, currentColor, m_isHighlight ? WidthMainLine(patternUnit) : WidthHairLine(patternUnit)); - this->setAcceptHoverEvents(true); - this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus -} - -//--------------------------------------------------------------------------------------------------------------------- -VSimplePoint::~VSimplePoint() -{} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::SetOnlyPoint(bool value) -{ - m_onlyPoint = value; - namePoint->setVisible(not m_onlyPoint); - lineName->setVisible(not m_onlyPoint); -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VSimplePoint::IsOnlyPoint() const -{ - return m_onlyPoint; + m_baseColor = currentColor; + connect(m_namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); + connect(m_namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VSimplePoint::DeleteFromLabel); + connect(m_namePoint, &VGraphicsSimpleTextItem::PointChoosed, this, &VSimplePoint::PointChoosed); + connect(m_namePoint, &VGraphicsSimpleTextItem::PointSelected, this, &VSimplePoint::PointSelected); + connect(m_namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VSimplePoint::ChangedPosition); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::SetVisualizationMode(bool value) { m_visualizationMode = value; - this->setFlag(QGraphicsItem::ItemIsFocusable, not m_visualizationMode); + setFlag(QGraphicsItem::ItemIsFocusable, not m_visualizationMode); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,91 +78,40 @@ bool VSimplePoint::IsVisualizationMode() const //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::SetPointHighlight(bool value) { - m_isHighlight = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::RefreshLine() -{ - QRectF nRec = namePoint->sceneBoundingRect(); - nRec.translate(- scenePos()); - if (this->rect().intersects(nRec) == false) - { - const QRectF nameRec = namePoint->sceneBoundingRect(); - QPointF p1, p2; - VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center() - scenePos()), p1, p2); - const QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); - lineName->setLine(QLineF(p1, pRec - scenePos())); - SetPen(lineName, Qt::black, WidthHairLine(patternUnit)); - - if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) - { - lineName->setVisible(false); - } - else - { - lineName->setVisible(true); - } - } - else - { - lineName->setVisible(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::RefreshGeometry(const VPointF &point) -{ - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); - SetPen(this, currentColor, m_isHighlight ? WidthMainLine(patternUnit) : WidthHairLine(patternUnit)); - QRectF rec = QRectF(0, 0, radius*2, radius*2); - rec.translate(-rec.center().x(), -rec.center().y()); - this->setRect(rec); - this->setPos(static_cast(point)); - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - namePoint->blockSignals(true); - QFont font = namePoint->font(); - font.setPointSize(static_cast(namePoint->FontSize()/ *factor)); - namePoint->setFont(font); - namePoint->setText(point.name()); - namePoint->setPos(QPointF(point.mx(), point.my())); - namePoint->blockSignals(false); - RefreshLine(); - this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + m_alwaysHovered = value; + m_isHovered = value; } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::SetEnabled(bool enabled) { - VAbstractSimple::SetEnabled(enabled); - SetPen(this, currentColor, m_isHighlight ? WidthMainLine(patternUnit) : WidthHairLine(patternUnit)); - SetPen(lineName, Qt::black, WidthHairLine(patternUnit)); - namePoint->setEnabled(enabled); + setEnabled(enabled); + m_namePoint->setEnabled(enabled); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::EnableToolMove(bool move) { - namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); + m_namePoint->setFlag(QGraphicsItem::ItemIsMovable, move); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::AllowLabelHover(bool enabled) { - namePoint->setAcceptHoverEvents(enabled); + m_namePoint->setAcceptHoverEvents(enabled); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::AllowLabelSelecting(bool enabled) { - namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + m_namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ToolSelectionType(const SelectionType &type) { VAbstractSimple::ToolSelectionType(type); - namePoint->LabelSelectionType(type); + m_namePoint->LabelSelectionType(type); } //--------------------------------------------------------------------------------------------------------------------- @@ -260,21 +182,24 @@ void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) emit Choosed(id); } } - QGraphicsEllipseItem::mouseReleaseEvent(event); + VScenePoint::mouseReleaseEvent(event); } } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - SetPen(this, currentColor, WidthMainLine(patternUnit)); + m_isHovered = true; QGraphicsEllipseItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - SetPen(this, currentColor, WidthHairLine(patternUnit)); + if (not m_alwaysHovered) + { + m_isHovered = false; + } QGraphicsEllipseItem::hoverLeaveEvent(event); } @@ -289,7 +214,7 @@ void VSimplePoint::keyReleaseEvent(QKeyEvent *event) default: break; } - QGraphicsEllipseItem::keyReleaseEvent ( event ); + VScenePoint::keyReleaseEvent ( event ); } //--------------------------------------------------------------------------------------------------------------------- @@ -297,13 +222,13 @@ QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, cons { if (change == QGraphicsItem::ItemSelectedChange) { - namePoint->blockSignals(true); - namePoint->setSelected(value.toBool()); - namePoint->blockSignals(false); + m_namePoint->blockSignals(true); + m_namePoint->setSelected(value.toBool()); + m_namePoint->blockSignals(false); emit Selected(value.toBool(), id); } - return QGraphicsEllipseItem::itemChange(change, value); + return VScenePoint::itemChange(change, value); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index d9d1b83f4..5745139a0 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -42,32 +41,30 @@ #include "../vmisc/def.h" #include "vabstractsimple.h" +#include "../vwidgets/vscenepoint.h" class VGraphicsSimpleTextItem; class VPointF; -class VSimplePoint : public VAbstractSimple, public QGraphicsEllipseItem +class VSimplePoint : public VAbstractSimple, public VScenePoint { Q_OBJECT public: - VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, - QObject *parent = nullptr); - virtual ~VSimplePoint() Q_DECL_OVERRIDE; + VSimplePoint(quint32 id, const QColor ¤tColor, QObject *parent = nullptr); + virtual ~VSimplePoint() = default; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimplePoint)}; - void SetOnlyPoint(bool value); - bool IsOnlyPoint() const; + using VScenePoint::SetOnlyPoint; + using VScenePoint::IsOnlyPoint; void SetVisualizationMode(bool value); bool IsVisualizationMode() const; void SetPointHighlight(bool value); - void RefreshLine(); - void RefreshGeometry(const VPointF &point); - virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; + void SetEnabled(bool enabled); void EnableToolMove(bool move); void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); @@ -90,8 +87,8 @@ public slots: protected: virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE; virtual void keyReleaseEvent ( QKeyEvent * event ) Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; @@ -99,21 +96,8 @@ protected: private: Q_DISABLE_COPY(VSimplePoint) - /** @brief radius radius circle. */ - qreal radius; - - /** @brief namePoint point label. */ - VGraphicsSimpleTextItem *namePoint; - - /** @brief lineName line what we see if label moved too away from point. */ - QGraphicsLineItem *lineName; - - bool m_onlyPoint; - bool m_isHighlight; bool m_visualizationMode; - - /** @brief currentColor current color. */ - QColor currentColor; + bool m_alwaysHovered; }; #endif // VSIMPLEPOINT_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 881774320..6e50c9c7a 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -641,6 +641,7 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) RestoreOverrideCursor(Qt::SizeFDiagCursor); } } + VPieceItem::hoverMoveEvent(pHE); } //--------------------------------------------------------------------------------------------------------------------- @@ -650,8 +651,8 @@ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) */ void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) { - Q_UNUSED(pHE) RestoreOverrideCursor(Qt::SizeFDiagCursor); + VPieceItem::hoverLeaveEvent(pHE); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 3ad0a39e0..059b41e4e 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -18,7 +18,9 @@ SOURCES += \ $$PWD/fancytabbar/fancytab.cpp \ $$PWD/fancytabbar/fancytabbar.cpp \ $$PWD/fancytabbar/stylehelper.cpp \ - $$PWD/vcurvepathitem.cpp + $$PWD/vcurvepathitem.cpp \ + $$PWD/global.cpp \ + $$PWD/vscenepoint.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -40,4 +42,6 @@ HEADERS += \ $$PWD/fancytabbar/fancytab.h \ $$PWD/fancytabbar/fancytabbar.h \ $$PWD/fancytabbar/stylehelper.h \ - $$PWD/vcurvepathitem.h + $$PWD/vcurvepathitem.h \ + $$PWD/global.h \ + $$PWD/vscenepoint.h