From 9f5fd98865d0b920cd6d0ffb806350172f161583 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 31 Mar 2016 20:10:20 +0300 Subject: [PATCH] Fixed tools Spline and Spline Path. For their work need section by mouse press event, all other better work with mouse release event. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 72 +++++++++++++------ src/app/valentina/mainwindow.h | 3 + src/libs/vmisc/def.h | 1 + .../tooldoublepoint/vtooldoublepoint.cpp | 8 +++ .../tooldoublepoint/vtooldoublepoint.h | 1 + .../toolsinglepoint/vtoolsinglepoint.cpp | 26 ++++++- .../toolsinglepoint/vtoolsinglepoint.h | 1 + src/libs/vtools/tools/drawTools/vdrawtool.h | 1 + src/libs/vtools/tools/vabstracttool.cpp | 9 ++- src/libs/vtools/tools/vabstracttool.h | 2 + src/libs/vwidgets/vgraphicssimpletextitem.cpp | 24 +++++-- src/libs/vwidgets/vgraphicssimpletextitem.h | 4 +- src/libs/vwidgets/vmaingraphicsscene.cpp | 6 ++ src/libs/vwidgets/vmaingraphicsscene.h | 2 + src/libs/vwidgets/vsimplepoint.cpp | 29 ++++++-- src/libs/vwidgets/vsimplepoint.h | 3 + 16 files changed, 158 insertions(+), 34 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 7eac35337..f342e09bd 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -301,6 +301,7 @@ void MainWindow::InitScenes() currentScene = sceneDraw; qApp->setCurrentScene(currentScene); connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove); + connect(this, &MainWindow::ItemsSelection, sceneDraw, &VMainGraphicsScene::ItemsSelection); connect(this, &MainWindow::EnableLabelSelection, sceneDraw, &VMainGraphicsScene::ToggleLabelSelection); connect(this, &MainWindow::EnablePointSelection, sceneDraw, &VMainGraphicsScene::TogglePointSelection); @@ -706,7 +707,7 @@ void MainWindow::ApplyDialog() */ void MainWindow::ToolEndLine(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::EndLine, ":/cursor/endline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -719,7 +720,7 @@ void MainWindow::ToolEndLine(bool checked) */ void MainWindow::ToolLine(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Line, ":/cursor/line_cursor.png", tr("Select first point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -732,7 +733,7 @@ void MainWindow::ToolLine(bool checked) */ void MainWindow::ToolAlongLine(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::AlongLine, ":/cursor/alongline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -745,7 +746,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ToolShoulderPoint(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::ShoulderPoint, ":/cursor/shoulder_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, @@ -759,7 +760,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ToolNormal(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Normal, ":/cursor/normal_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogWithApply, @@ -773,7 +774,7 @@ void MainWindow::ToolNormal(bool checked) */ void MainWindow::ToolBisector(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Bisector, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), &MainWindow::ClosedDialogWithApply, @@ -787,7 +788,7 @@ void MainWindow::ToolBisector(bool checked) */ void MainWindow::ToolLineIntersect(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::LineIntersect, ":/cursor/intersect_cursor.png", tr("Select first point of first line"), &MainWindow::ClosedDialogWithApply, @@ -801,7 +802,7 @@ void MainWindow::ToolLineIntersect(bool checked) */ void MainWindow::ToolSpline(bool checked) { - ToolSelectPoint(); + ToolSelectPointByPress(); SetToolButtonWithApply(checked, Tool::Spline, ":/cursor/spline_cursor.png", tr("Select first point curve"), &MainWindow::ClosedDialogWithApply, @@ -811,7 +812,7 @@ void MainWindow::ToolSpline(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolCubicBezier(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::CubicBezier, ":/cursor/cubic_bezier_cursor.png", tr("Select first curve point"), &MainWindow::ClosedDialogWithApply, @@ -839,7 +840,7 @@ void MainWindow::ToolCutSpline(bool checked) */ void MainWindow::ToolArc(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Arc, ":/cursor/arc_cursor.png", tr("Select point of center of arc"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -852,7 +853,7 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ToolSplinePath(bool checked) { - ToolSelectPoint(); + ToolSelectPointByPress(); SetToolButtonWithApply(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", tr("Select point of curve path"), &MainWindow::ClosedDialogWithApply, @@ -862,7 +863,7 @@ void MainWindow::ToolSplinePath(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolCubicBezierPath(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::CubicBezierPath, ":/cursor/cubic_bezier_path_cursor.png", tr("Select point of cubic bezier path"), @@ -891,7 +892,7 @@ void MainWindow::ToolCutSplinePath(bool checked) */ void MainWindow::ToolPointOfContact(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::PointOfContact, ":/cursor/pointcontact_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogWithApply, @@ -932,7 +933,7 @@ void MainWindow::ClosedDialogDetail(int result) */ void MainWindow::ToolHeight(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Height, ":/cursor/height_cursor.png", tr("Select base point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -945,7 +946,7 @@ void MainWindow::ToolHeight(bool checked) */ void MainWindow::ToolTriangle(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::Triangle, ":/cursor/triangle_cursor.png", tr("Select first point of axis"), &MainWindow::ClosedDialogWithApply, @@ -959,7 +960,7 @@ void MainWindow::ToolTriangle(bool checked) */ void MainWindow::ToolPointOfIntersection(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::PointOfIntersection, ":/cursor/pointofintersect_cursor.png", tr("Select point for X value (vertical)"), @@ -1006,7 +1007,7 @@ void MainWindow::ToolCutArc(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolLineIntersectAxis(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::LineIntersectAxis, ":/cursor/line_intersect_axis_cursor.png", tr("Select first point of line"), @@ -1051,7 +1052,7 @@ void MainWindow::ToolPointOfIntersectionArcs(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolPointOfIntersectionCircles(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::PointOfIntersectionCircles, "://cursor/point_of_intersection_circles.png", tr("Select first circle center "), @@ -1073,7 +1074,7 @@ void MainWindow::ToolPointOfIntersectionCurves(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolPointFromCircleAndTangent(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::PointFromCircleAndTangent, "://cursor/point_from_circle_and_tangent_cursor.png", tr("Select point on tangent "), @@ -1095,7 +1096,7 @@ void MainWindow::ToolPointFromArcAndTangent(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolArcWithLength(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::ArcWithLength, "://cursor/arc_with_length_cursor.png", tr("Select point of the center of the arc"), @@ -1106,7 +1107,7 @@ void MainWindow::ToolArcWithLength(bool checked) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolTrueDarts(bool checked) { - ToolSelectPoint(); + ToolSelectPointByRelease(); SetToolButtonWithApply(checked, Tool::TrueDarts, "://cursor/true_darts_cursor.png", tr("Select the first base line point"), @@ -1889,6 +1890,7 @@ void MainWindow::ArrowTool() ui->actionStopTool->setEnabled(false); currentTool = Tool::Arrow; emit EnableItemMove(true); + emit ItemsSelection(SelectionType::ByMouseRelease); // Only true for rubber band selection emit EnableLabelSelection(true); @@ -4500,6 +4502,20 @@ void MainWindow::ToolSelectPoint() const ui->view->AllowRubberBand(false); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolSelectPointByRelease() const +{ + ToolSelectPoint(); + emit ItemsSelection(SelectionType::ByMouseRelease); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolSelectPointByPress() const +{ + ToolSelectPoint(); + emit ItemsSelection(SelectionType::ByMousePress); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolSelectSpline() const { @@ -4518,6 +4534,8 @@ void MainWindow::ToolSelectSpline() const emit EnableSplineHover(true); emit EnableSplinePathHover(false); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4539,6 +4557,8 @@ void MainWindow::ToolSelectSplinePath() const emit EnableSplineHover(false); emit EnableSplinePathHover(true); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4560,6 +4580,8 @@ void MainWindow::ToolSelectArc() const emit EnableSplineHover(false); emit EnableSplinePathHover(false); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4581,6 +4603,8 @@ void MainWindow::ToolSelectPointArc() const emit EnableSplineHover(false); emit EnableSplinePathHover(false); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4602,6 +4626,8 @@ void MainWindow::ToolSelectCurve() const emit EnableSplineHover(true); emit EnableSplinePathHover(true); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4623,6 +4649,8 @@ void MainWindow::ToolSelectAllObjects() const emit EnableSplineHover(true); emit EnableSplinePathHover(true); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } @@ -4639,5 +4667,7 @@ void MainWindow::ToolSelectDetail() const emit EnableNodePointHover(true); emit EnableDetailHover(true); + emit ItemsSelection(SelectionType::ByMouseRelease); + ui->view->AllowRubberBand(false); } diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index e78d7d3b7..f241b3526 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -157,6 +157,7 @@ public slots: signals: void RefreshHistory(); void EnableItemMove(bool move); + void ItemsSelection(SelectionType type) const; void EnableLabelSelection(bool enable) const; void EnablePointSelection(bool enable) const; @@ -352,6 +353,8 @@ private: bool IgnoreLocking(int error, const QString &path); void ToolSelectPoint() const; + void ToolSelectPointByPress() const; + void ToolSelectPointByRelease() const; void ToolSelectSpline() const; void ToolSelectSplinePath() const; void ToolSelectArc() const; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 8d49efcd5..73421ebce 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -55,6 +55,7 @@ enum class MeasurementsType : char { Standard, Individual , Unknown}; enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE}; enum class Source : char { FromGui, FromFile, FromTool }; enum class NodeUsage : bool {NotInUse = false, InUse = true}; +enum class SelectionType : bool {ByMousePress, ByMouseRelease}; typedef unsigned char ToolVisHolderType; enum class Tool : ToolVisHolderType diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index ee4ec7407..52f436276 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -215,6 +215,14 @@ void VToolDoublePoint::AllowLabelSelecting(bool enabled) secondPoint->AllowLabelSelecting(enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDoublePoint::ToolSelectionType(const SelectionType &type) +{ + VAbstractTool::ToolSelectionType(type); + firstPoint->ToolSelectionType(type); + secondPoint->ToolSelectionType(type); +} + //--------------------------------------------------------------------------------------------------------------------- void VToolDoublePoint::UpdateNamePosition(quint32 id) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h index a825d50e4..9a278a264 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.h @@ -73,6 +73,7 @@ public slots: 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: VSimplePoint *firstPoint; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 59cda043d..9f67fd187 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -136,7 +136,17 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsEllipseItem::mousePressEvent(event); - event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + if (selectionType == SelectionType::ByMouseRelease) + { + event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + } + else + { + if (event->button() == Qt::LeftButton) + { + PointChoosed(); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -188,9 +198,12 @@ void VToolSinglePoint::FullUpdateFromFile() */ void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (selectionType == SelectionType::ByMouseRelease) { - PointChoosed(); + if (event->button() == Qt::LeftButton) + { + PointChoosed(); + } } QGraphicsEllipseItem::mouseReleaseEvent(event); } @@ -365,3 +378,10 @@ void VToolSinglePoint::AllowLabelSelecting(bool enabled) { namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::ToolSelectionType(const SelectionType &type) +{ + VAbstractTool::ToolSelectionType(type); + 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 f6837c9c1..6c9cf979c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -67,6 +67,7 @@ public slots: 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; diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 6c691b050..ddf9eb0ca 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -242,6 +242,7 @@ void VDrawTool::InitDrawToolConnections(VMainGraphicsScene *scene, T *tool) QObject::connect(scene, &VMainGraphicsScene::DisableItem, tool, &T::Disable); QObject::connect(scene, &VMainGraphicsScene::EnableToolMove, tool, &T::EnableToolMove); QObject::connect(scene, &VMainGraphicsScene::CurveDetailsMode, tool, &T::DetailsMode); + QObject::connect(scene, &VMainGraphicsScene::ItemSelection, tool, &T::ToolSelectionType); } #endif // VDRAWTOOL_H diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index a44db4e0c..ad74b4cf4 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -52,7 +52,8 @@ const QString VAbstractTool::AttrInUse = QStringLiteral("inUse"); * @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(nullptr) + :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), vis(nullptr), + selectionType(SelectionType::ByMouseRelease) { SCASSERT(doc != nullptr); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VAbstractPattern::haveLiteChange); @@ -256,6 +257,12 @@ QMap VAbstractTool::PointsList() const return list; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::ToolSelectionType(const SelectionType &type) +{ + selectionType = type; +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractTool::ToolCreation(const Source &typeCreation) { diff --git a/src/libs/vtools/tools/vabstracttool.h b/src/libs/vtools/tools/vabstracttool.h index fac9e89fa..8a86c7e90 100644 --- a/src/libs/vtools/tools/vabstracttool.h +++ b/src/libs/vtools/tools/vabstracttool.h @@ -79,6 +79,7 @@ public slots: virtual void FullUpdateFromFile()=0; virtual void AllowHover(bool enabled)=0; virtual void AllowSelecting(bool enabled)=0; + virtual void ToolSelectionType(const SelectionType &type); signals: /** * @brief toolhaveChange emit if tool create change that need save. @@ -105,6 +106,7 @@ protected: Qt::GlobalColor baseColor; Visualization *vis; + SelectionType selectionType; /** * @brief AddToFile add tag with informations about tool into file. diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index 2067ffc3c..60abcc02a 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -45,7 +45,7 @@ * @param parent parent object. */ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent) - :QGraphicsSimpleTextItem(parent), fontSize(0) + :QGraphicsSimpleTextItem(parent), fontSize(0), selectionType(SelectionType::ByMouseRelease) { this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -64,7 +64,7 @@ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem(QGraphicsItem * parent) * @param parent parent object. */ VGraphicsSimpleTextItem::VGraphicsSimpleTextItem( const QString & text, QGraphicsItem * parent ) - :QGraphicsSimpleTextItem(text, parent), fontSize(0) + :QGraphicsSimpleTextItem(text, parent), fontSize(0), selectionType(SelectionType::ByMouseRelease) { this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -94,6 +94,12 @@ void VGraphicsSimpleTextItem::setEnabled(bool enabled) } } +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::LabelSelectionType(const SelectionType &type) +{ + selectionType = type; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange handle item change. @@ -203,7 +209,14 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } - event->accept(); // This help for not selectable items still receive mouseReleaseEvent events + if (selectionType == SelectionType::ByMouseRelease) + { + event->accept(); // This help for not selectable items still receive mouseReleaseEvent events + } + else + { + emit PointChoosed(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -218,7 +231,10 @@ void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } - emit PointChoosed(); + if (selectionType == SelectionType::ByMouseRelease) + { + emit PointChoosed(); + } QGraphicsSimpleTextItem::mouseReleaseEvent(event); } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.h b/src/libs/vwidgets/vgraphicssimpletextitem.h index b84598e41..dd5db5118 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.h +++ b/src/libs/vwidgets/vgraphicssimpletextitem.h @@ -49,6 +49,7 @@ public: enum { Type = UserType + static_cast(Vis::GraphicsSimpleTextItem)}; void setEnabled(bool enabled); + void LabelSelectionType(const SelectionType &type); signals: /** * @brief NameChangePosition emit when label change position. @@ -72,7 +73,8 @@ protected: virtual void keyReleaseEvent ( QKeyEvent * event ) Q_DECL_OVERRIDE; private: /** @brief fontSize label font size. */ - qint32 fontSize; + qint32 fontSize; + SelectionType selectionType; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index 976a41fc4..6ad0b7ce7 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -281,6 +281,12 @@ void VMainGraphicsScene::EnableDetailsMode(bool mode) emit CurveDetailsMode(mode); } +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::ItemsSelection(const SelectionType &type) +{ + emit ItemSelection(type); +} + //--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsScene::ToggleLabelSelection(bool enabled) { diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index 84fced90b..fc9b99c6e 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -58,6 +58,7 @@ public slots: void SetFactor(qreal factor); void EnableItemMove(bool move); void EnableDetailsMode(bool mode); + void ItemsSelection(const SelectionType &type); void ToggleLabelSelection(bool enabled); void TogglePointSelection(bool enabled); @@ -105,6 +106,7 @@ signals: void DisableItem(bool disable, const QString &namePP); void EnableToolMove(bool move); void CurveDetailsMode(bool mode); + void ItemSelection(const SelectionType &type); void EnableLabelItemSelection(bool enable); void EnablePointItemSelection(bool enable); diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index db420b856..9974bde2b 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -39,7 +39,8 @@ //--------------------------------------------------------------------------------------------------------------------- VSimplePoint::VSimplePoint(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) :VAbstractSimple(id, currentColor, patternUnit, factor, parent), QGraphicsEllipseItem(), - radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr) + radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr), + selectionType(SelectionType::ByMouseRelease) { namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); @@ -158,6 +159,13 @@ void VSimplePoint::AllowLabelSelecting(bool enabled) namePoint->setFlag(QGraphicsItem::ItemIsSelectable, enabled); } +//--------------------------------------------------------------------------------------------------------------------- +void VSimplePoint::ToolSelectionType(const SelectionType &type) +{ + selectionType = type; + namePoint->LabelSelectionType(type); +} + //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::DeleteFromLabel() { @@ -187,15 +195,28 @@ void VSimplePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { // Special for not selectable item first need to call standard mousePressEvent then accept event QGraphicsEllipseItem::mousePressEvent(event); - event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + if (selectionType == SelectionType::ByMouseRelease) + { + event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event + } + else + { + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } + } } //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (selectionType == SelectionType::ByMouseRelease) { - emit Choosed(id); + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } } QGraphicsEllipseItem::mouseReleaseEvent(event); } diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index 53f79df81..9d109ebbc 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -57,6 +57,7 @@ public: void EnableToolMove(bool move); void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); + void ToolSelectionType(const SelectionType &type); QColor GetCurrentColor() const; void SetCurrentColor(const QColor &value); @@ -94,6 +95,8 @@ private: /** @brief lineName line what we see if label moved too away from point. */ QGraphicsLineItem *lineName; + SelectionType selectionType; + }; #endif // VSIMPLEPOINT_H