diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 117787659..43c25233c 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -74,7 +74,7 @@ void VToolOptionsPropertyBrowser::ClearPropertyBrowser() void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (item->type()) { @@ -177,6 +177,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolTrueDarts::Type: ShowOptionsToolTrueDarts(item); break; + case VToolRotation::Type: + ShowOptionsToolRotation(item); + break; default: break; } @@ -191,7 +194,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -288,6 +291,9 @@ void VToolOptionsPropertyBrowser::UpdateOptions() case VToolTrueDarts::Type: UpdateOptionsToolTrueDarts(); break; + case VToolRotation::Type: + UpdateOptionsToolRotation(); + break; default: break; } @@ -323,7 +329,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in switch."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in switch."); switch (currentItem->type()) { @@ -414,6 +420,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolTrueDarts::Type: ChangeDataToolTrueDarts(prop); break; + case VToolRotation::Type: + ChangeDataToolRotation(prop); + break; default: break; } @@ -1525,6 +1534,12 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCurveIntersectAxis(VProperty *pr } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolRotation(VProperty *property) +{ + SCASSERT(property != nullptr) +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item) { @@ -1907,6 +1922,12 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCurveIntersectAxis(QGraphicsIte AddPropertyFormula(tr("Angle"), i->GetFormulaAngle(), AttrAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolRotation(QGraphicsItem *item) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { @@ -2365,6 +2386,12 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCurveIntersectAxis() idToProperty[AttrAngle]->setValue(valueAngle); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolRotation() +{ + +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 6ffd7a12b..a0e44fef0 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -144,6 +144,7 @@ private: void ChangeDataToolTriangle(VPE::VProperty *property); void ChangeDataToolLineIntersectAxis(VPE::VProperty *property); void ChangeDataToolCurveIntersectAxis(VPE::VProperty *property); + void ChangeDataToolRotation(VPE::VProperty *property); void ShowOptionsToolSinglePoint(QGraphicsItem *item); void ShowOptionsToolEndLine(QGraphicsItem *item); @@ -174,6 +175,7 @@ private: void ShowOptionsToolTriangle(QGraphicsItem *item); void ShowOptionsToolLineIntersectAxis(QGraphicsItem *item); void ShowOptionsToolCurveIntersectAxis(QGraphicsItem *item); + void ShowOptionsToolRotation(QGraphicsItem *item); void UpdateOptionsToolSinglePoint(); void UpdateOptionsToolEndLine(); @@ -204,6 +206,7 @@ private: void UpdateOptionsToolTriangle(); void UpdateOptionsToolLineIntersectAxis(); void UpdateOptionsToolCurveIntersectAxis(); + void UpdateOptionsToolRotation(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index bddd259f3..c6e4fbfeb 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -208,7 +208,7 @@ void DialogHistory::FillTable() QString DialogHistory::Record(const VToolRecord &tool) { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used in history."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used in history."); const QDomElement domElem = doc->elementById(tool.getId()); if (domElem.isElement() == false) @@ -384,6 +384,7 @@ QString DialogHistory::Record(const VToolRecord &tool) case Tool::NodeSpline: case Tool::NodeSplinePath: case Tool::Group: + case Tool::Rotation: return QString(); } } diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 4125aed5d..b6ddbf233 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -613,6 +613,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur SCASSERT(scene != nullptr); connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); + connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool, &DialogTool::SelectedObject); connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); @@ -1004,12 +1005,22 @@ void MainWindow::ClosedDialogUnionDetails(int result) void MainWindow::ToolGroup(bool checked) { ToolSelectGroupObjects(); - currentScene->clearSelection(); SetToolButton(checked, Tool::Group, ":/cursor/group_plus_cursor.png", tr("Select one or more objects, Enter - finish creation"), &MainWindow::ClosedDialogGroup); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolRotation(bool checked) +{ + ToolSelectGroupObjects(); + SetToolButtonWithApply(checked, Tool::Rotation, + ":/cursor/rotation_cursor.png", + tr("Select one or more objects, Enter - confirm selection"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ClosedDialogGroup(int result) { @@ -1740,6 +1751,7 @@ void MainWindow::InitToolButtons() connect(ui->toolButtonArcWithLength, &QToolButton::clicked, this, &MainWindow::ToolArcWithLength); connect(ui->toolButtonTrueDarts, &QToolButton::clicked, this, &MainWindow::ToolTrueDarts); connect(ui->toolButtonGroup, &QToolButton::clicked, this, &MainWindow::ToolGroup); + connect(ui->toolButtonRotation, &QToolButton::clicked, this, &MainWindow::ToolRotation); } //--------------------------------------------------------------------------------------------------------------------- @@ -1780,12 +1792,16 @@ void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::CancelTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); qCDebug(vMainWindow, "Canceling tool."); delete dialogTool; dialogTool = nullptr; qCDebug(vMainWindow, "Dialog closed."); + + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + switch ( currentTool ) { case Tool::Arrow: @@ -1907,9 +1923,10 @@ void MainWindow::CancelTool() case Tool::Group: ui->toolButtonGroup->setChecked(false); break; + case Tool::Rotation: + ui->toolButtonRotation->setChecked(false); + break; } - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); // Crash: using CRTL+Z while using line tool. // related bug report: @@ -3110,6 +3127,7 @@ void MainWindow::SetEnableTool(bool enable) ui->toolButtonArcWithLength->setEnabled(drawTools); ui->toolButtonTrueDarts->setEnabled(drawTools); ui->toolButtonGroup->setEnabled(drawTools); + ui->toolButtonRotation->setEnabled(drawTools); ui->actionLast_tool->setEnabled(drawTools); @@ -3380,7 +3398,7 @@ void MainWindow::CreateMenus() void MainWindow::LastUsedTool() { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was handled."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was handled."); if (currentTool == lastUsedTool) { @@ -3531,6 +3549,10 @@ void MainWindow::LastUsedTool() ui->toolButtonGroup->setChecked(true); ToolGroup(true); break; + case Tool::Rotation: + ui->toolButtonRotation->setChecked(true); + ToolRotation(true); + break; } } @@ -4715,12 +4737,12 @@ void MainWindow::ToolSelectAllDrawObjects() const } //--------------------------------------------------------------------------------------------------------------------- -void MainWindow::ToolSelectGroupObjects() const +void MainWindow::ToolSelectOperationObjects() const { // Only true for rubber band selection emit EnableLabelSelection(true); emit EnablePointSelection(true); - emit EnableLineSelection(true); + emit EnableLineSelection(false); emit EnableArcSelection(true); emit EnableSplineSelection(true); emit EnableSplinePathSelection(true); @@ -4728,7 +4750,7 @@ void MainWindow::ToolSelectGroupObjects() const // Hovering emit EnableLabelHover(true); emit EnablePointHover(true); - emit EnableLineHover(true); + emit EnableLineHover(false); emit EnableArcHover(true); emit EnableSplineHover(true); emit EnableSplinePathHover(true); @@ -4738,6 +4760,17 @@ void MainWindow::ToolSelectGroupObjects() const ui->view->AllowRubberBand(true); } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::ToolSelectGroupObjects() const +{ + ToolSelectOperationObjects(); + // Only true for rubber band selection + emit EnableLineSelection(true); + + // Hovering + emit EnableLineHover(true); +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ToolSelectDetail() const { diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 98b383942..6708c07dd 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -122,6 +122,7 @@ public slots: void ToolPointOfIntersection(bool checked); void ToolUnionDetails(bool checked); void ToolGroup(bool checked); + void ToolRotation(bool checked); void ToolCutArc(bool checked); void ToolLineIntersectAxis(bool checked); void ToolCurveIntersectAxis(bool checked); @@ -372,6 +373,7 @@ private: void ToolSelectPointArc() const; void ToolSelectCurve() const; void ToolSelectAllDrawObjects() const; + void ToolSelectOperationObjects() const; void ToolSelectGroupObjects() const; void ToolSelectDetail() const; }; diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index 51eb11f32..92a31bb71 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -983,6 +983,32 @@ + + + + false + + + Rotate objects + + + ... + + + + :/toolicon/32x32/rotation.png:/toolicon/32x32/rotation.png + + + + 32 + 32 + + + + true + + + diff --git a/src/app/valentina/share/resources/cursor.qrc b/src/app/valentina/share/resources/cursor.qrc index 1063918f4..cfd41aa80 100644 --- a/src/app/valentina/share/resources/cursor.qrc +++ b/src/app/valentina/share/resources/cursor.qrc @@ -66,5 +66,7 @@ cursor/cubic_bezier_path_cursor@2x.png cursor/group_plus_cursor.png cursor/group_plus_cursor@2x.png + cursor/rotation_cursor.png + cursor/rotation_cursor@2x.png diff --git a/src/app/valentina/share/resources/cursor/rotation_cursor.png b/src/app/valentina/share/resources/cursor/rotation_cursor.png new file mode 100644 index 000000000..3a769ac46 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/rotation_cursor.png differ diff --git a/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png b/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png new file mode 100644 index 000000000..55d2765c2 Binary files /dev/null and b/src/app/valentina/share/resources/cursor/rotation_cursor@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon.qrc b/src/app/valentina/share/resources/toolicon.qrc index 8b5d0bec5..89e67fe78 100644 --- a/src/app/valentina/share/resources/toolicon.qrc +++ b/src/app/valentina/share/resources/toolicon.qrc @@ -64,5 +64,7 @@ toolicon/32x32/cubic_bezier_path@2x.png toolicon/32x32/group_plus.png toolicon/32x32/group_plus@2x.png + toolicon/32x32/rotation.png + toolicon/32x32/rotation@2x.png diff --git a/src/app/valentina/share/resources/toolicon/32x32/rotation.png b/src/app/valentina/share/resources/toolicon/32x32/rotation.png new file mode 100644 index 000000000..f1fa60133 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/rotation.png differ diff --git a/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png b/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png new file mode 100644 index 000000000..3a7337253 Binary files /dev/null and b/src/app/valentina/share/resources/toolicon/32x32/rotation@2x.png differ diff --git a/src/app/valentina/share/resources/toolicon/svg/rotation.svg b/src/app/valentina/share/resources/toolicon/svg/rotation.svg new file mode 100644 index 000000000..5da456343 --- /dev/null +++ b/src/app/valentina/share/resources/toolicon/svg/rotation.svg @@ -0,0 +1,82 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 31c89cbf0..73bba92ac 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -840,7 +840,7 @@ void VPattern::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &do void VPattern::SplinesCommonAttributes(const QDomElement &domElement, quint32 &id, quint32 &idObject, quint32 &idTool) { ToolsCommonAttributes(domElement, id); - idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); } @@ -1279,7 +1279,7 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par qreal my = 0; PointsCommonAttributes(domElement, id, mx, my); - const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); QSharedPointer point; try @@ -2330,7 +2330,7 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse quint32 id = 0; ToolsCommonAttributes(domElement, id); - const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); + const quint32 idObject = GetParametrUInt(domElement, AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); VArc *arc = nullptr; try @@ -3130,7 +3130,7 @@ void VPattern::ToolsCommonAttributes(const QDomElement &domElement, quint32 &id) QRectF VPattern::ActiveDrawBoundingRect() const { // This check helps to find missed tools in the switch - Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 42, "Not all tools was used."); + Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 43, "Not all tools was used."); QRectF rec; @@ -3237,6 +3237,9 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::TrueDarts: rec = ToolBoundingRect(rec, tool.getId()); break; + case Tool::Rotation: + rec = ToolBoundingRect(rec, tool.getId()); + break; //These tools are not accesseble in Draw mode, but still 'history' contains them. case Tool::Detail: case Tool::UnionDetails: diff --git a/src/libs/ifc/exception/vexception.cpp b/src/libs/ifc/exception/vexception.cpp index 46413173b..f449591b2 100644 --- a/src/libs/ifc/exception/vexception.cpp +++ b/src/libs/ifc/exception/vexception.cpp @@ -170,7 +170,7 @@ VExceptionToolWasDeleted &VExceptionToolWasDeleted::operator=(const VExceptionTo * @brief raise method raise for exception */ // cppcheck-suppress unusedFunction -Q_NORETURN void VExceptionToolWasDeleted::VExceptionToolWasDeleted::raise() const +Q_NORETURN void VExceptionToolWasDeleted::raise() const { throw *this; } diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index dcbd260be..65d74d3ff 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -128,6 +128,8 @@ const QString AttrCCenter = QStringLiteral("cCenter"); const QString AttrTangent = QStringLiteral("tangent"); const QString AttrCRadius = QStringLiteral("cRadius"); const QString AttrArc = QStringLiteral("arc"); +const QString AttrSuffix = QStringLiteral("suffix"); +const QString AttrIdObject = QStringLiteral("idObject"); const QString TypeLineNone = QStringLiteral("none"); const QString TypeLineLine = QStringLiteral("hair"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index a88c39d3f..39d65b2f9 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -130,6 +130,8 @@ extern const QString AttrCCenter; extern const QString AttrTangent; extern const QString AttrCRadius; extern const QString AttrArc; +extern const QString AttrSuffix; +extern const QString AttrIdObject; extern const QString TypeLineNone; extern const QString TypeLineLine; diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 8524b4f9f..e50e98cd5 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -210,7 +210,7 @@ public: signals: /** - * @brief ChangedActivDraw change active pattern peace. + * @brief ChangedActivPP change active pattern peace. * @param newName new pattern peace name. */ void ChangedActivPP(const QString &newName); diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index f083d1353..ae9d200a5 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -29,8 +29,6 @@ #ifndef VGEOMETRYDEF_H #define VGEOMETRYDEF_H -#include - enum class Draw : char { Calculation, Modeling, Layout }; enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, CubicBezier, CubicBezierPath, Unknown }; enum class SplinePointPosition : char { FirstPoint, LastPoint }; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 9aa894976..5b6ba2ca9 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -102,6 +102,7 @@ enum class Tool : ToolVisHolderType TrueDarts, UnionDetails, Group, + Rotation, LAST_ONE_DO_NOT_USE //add new stuffs above this, this constant must be last and never used }; @@ -110,6 +111,7 @@ enum class Vis : ToolVisHolderType ControlPointSpline = static_cast(Tool::LAST_ONE_DO_NOT_USE), GraphicsSimpleTextItem, SimplePoint, + SimpleCurve, Line, Path, ToolAlongLine, @@ -139,7 +141,8 @@ enum class Vis : ToolVisHolderType ToolCutSplinePath, ToolLineIntersectAxis, ToolCurveIntersectAxis, - ToolTrueDarts + ToolTrueDarts, + ToolRotation }; enum class VarType : char { Measurement, Increment, LineLength, CurveLength, LineAngle, CurveAngle, ArcRadius, diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 26bcfaad6..1a358d539 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -37,7 +37,8 @@ HEADERS += \ $$PWD/tools/dialogpointofintersectioncurves.h \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ - $$PWD/tools/dialoggroup.h + $$PWD/tools/dialoggroup.h \ + $$PWD/tools/dialogrotation.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -74,7 +75,8 @@ SOURCES += \ $$PWD/tools/dialogpointofintersectioncurves.cpp \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ - $$PWD/tools/dialoggroup.cpp + $$PWD/tools/dialoggroup.cpp \ + $$PWD/tools/dialogrotation.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -110,4 +112,5 @@ FORMS += \ $$PWD/tools/dialogpointofintersectioncurves.ui \ $$PWD/tools/dialogcubicbezier.ui \ $$PWD/tools/dialogcubicbezierpath.ui \ - $$PWD/tools/dialoggroup.ui + $$PWD/tools/dialoggroup.ui \ + $$PWD/tools/dialogrotation.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index b9ac6d496..8383ebd91 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -61,6 +61,7 @@ #include "dialogs/tools/dialogpointfromarcandtangent.h" #include "dialogs/tools/dialogtruedarts.h" #include "dialogs/tools/dialoggroup.h" +#include "dialogs/tools/dialogrotation.h" #include "dialogs/support/dialogeditwrongformula.h" #include "dialogs/support/dialogundo.h" diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp new file mode 100644 index 000000000..b8d25e219 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -0,0 +1,323 @@ +/************************************************************************ + ** + ** @file dialogrotation.cpp + ** @author Roman Telezhynskyi + ** @date 10 4, 2016 + ** + ** @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) 2016 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 "dialogrotation.h" +#include "ui_dialogrotation.h" + +#include + +#include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/vtranslatevars.h" +#include "../ifc/xml/vdomdocument.h" +#include "../../visualization/line/vistoolrotation.h" +#include "../support/dialogeditwrongformula.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogRotation), + flagAngle(false), + timerAngle(nullptr), + formulaAngle(), + formulaBaseHeightAngle(0), + objects(), + stage1(true) +{ + ui->setupUi(this); + + this->formulaBaseHeightAngle = ui->plainTextEditFormula->height(); + ui->plainTextEditFormula->installEventFilter(this); + +// ui->lineEditSuffix->setText(/*qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)*/); + + timerAngle = new QTimer(this); + connect(timerAngle, &QTimer::timeout, this, &DialogRotation::EvalAngle); + + InitOkCancelApply(ui); + + FillComboBoxPoints(ui->comboBoxOriginPoint); + +// flagName = true; + CheckState(); + + connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogRotation::SuffixChanged); + connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogRotation::FXAngle); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogRotation::AngleChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogRotation::DeployAngleTextEdit); + + vis = new VisToolRotation(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogRotation::~DialogRotation() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogRotation::GetOrigPointId() const +{ + return getCurrentObjectId(ui->comboBoxOriginPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetOrigPointId(const quint32 &value) +{ + ChangeCurrentData(ui->comboBoxOriginPoint, value); + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetOriginPointId(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogRotation::GetAngle() const +{ + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetAngle(const QString &value) +{ + formulaAngle = qApp->TrVars()->FormulaToUser(value); + // increase height if needed. + if (formulaAngle.length() > 80) + { + this->DeployAngleTextEdit(); + } + ui->plainTextEditFormula->setPlainText(formulaAngle); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetAngle(formulaAngle); + + MoveCursorToEnd(ui->plainTextEditFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogRotation::GetSuffix() const +{ + return ui->lineEditSuffix->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetSuffix(const QString &value) +{ + ui->lineEditSuffix->setText(value); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogRotation::GetObjects() const +{ + return objects.toVector(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ShowDialog(bool click) +{ + if (stage1 && not click) + { + if (objects.isEmpty()) + { + return; + } + + stage1 = false; + + auto scene = qApp->getCurrentScene(); + SCASSERT(scene != nullptr); + scene->clearSelection(); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + operation->SetObjects(objects.toVector()); + operation->VisualMode(); + + emit ToolTip("Select origin point"); + } + else if (not stage1 && prepare && click) + { + /*We will ignore click if pointer is in point circle*/ + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + const QSharedPointer point = data->GeometricObject(GetOrigPointId()); + const QLineF line = QLineF(point->toQPointF(), 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) + { + return; + } + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + SetAngle(operation->Angle());//Show in dialog angle that a user choose + setModal(true); + emit ToolTip(""); + timerAngle->start(); + show(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ChosenObject(quint32 id, const SceneObject &type) +{ + if (not stage1 && not prepare)// After first choose we ignore all objects + { + if (type == SceneObject::Point) + { + if (SetObject(id, ui->comboBoxOriginPoint, "")) + { + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + connect(operation, &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip); + + operation->SetOriginPointId(id); + operation->RefreshGeometry(); + + prepare = true; + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SelectedObject(bool selected, quint32 object, quint32 tool) +{ + if (stage1) + { + if (selected) + { + if (not objects.contains(object)) + { + objects.append(object); + } + } + else + { + objects.removeOne(object); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::DeployAngleTextEdit() +{ + DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeightAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::AngleChanged() +{ + labelEditFormula = ui->labelEditAngle; + labelResultCalculation = ui->labelResultAngle; + ValFormulaChanged(flagAngle, ui->plainTextEditFormula, timerAngle, degreeSymbol); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::FXAngle() +{ + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this); + dialog->setWindowTitle(tr("Edit angle")); + dialog->SetFormula(GetAngle()); + dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + if (dialog->exec() == QDialog::Accepted) + { + SetAngle(dialog->GetFormula()); + } + delete dialog; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SuffixChanged() +{ + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + const QString name = edit->text(); +// QRegularExpression rx(NameRegExp()); + if (name.isEmpty()/* || (pointName != name && not data->IsUnique(name)) || not rx.match(name).hasMatch()*/) + { + flagName = false; + ChangeColor(ui->labelSuffix, Qt::red); + } + else + { + flagName = true; + ChangeColor(ui->labelSuffix, okColor); + } + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagAngle && flagName); + SCASSERT(bApply != nullptr); + bApply->setEnabled(bOk->isEnabled()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ShowVisualization() +{ + AddVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SaveData() +{ + formulaAngle = ui->plainTextEditFormula->toPlainText(); + formulaAngle.replace("\n", " "); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr); + + operation->SetObjects(objects.toVector()); + operation->SetOriginPointId(GetOrigPointId()); + operation->SetAngle(formulaAngle); + operation->RefreshGeometry(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::closeEvent(QCloseEvent *event) +{ + ui->plainTextEditFormula->blockSignals(true); + DialogTool::closeEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::EvalAngle() +{ + labelEditFormula = ui->labelEditAngle; + Eval(ui->plainTextEditFormula->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false); +} diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.h b/src/libs/vtools/dialogs/tools/dialogrotation.h new file mode 100644 index 000000000..2f30ccfc4 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.h @@ -0,0 +1,101 @@ +/************************************************************************ + ** + ** @file dialogrotation.h + ** @author Roman Telezhynskyi + ** @date 10 4, 2016 + ** + ** @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) 2016 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 DIALOGROTATION_H +#define DIALOGROTATION_H + +#include "dialogtool.h" + +namespace Ui +{ + class DialogRotation; +} + +class DialogRotation : public DialogTool +{ + Q_OBJECT +public: + explicit DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogRotation(); + + quint32 GetOrigPointId() const; + void SetOrigPointId(const quint32 &value); + + QString GetAngle() const; + void SetAngle(const QString &value); + + QString GetSuffix() const; + void SetSuffix(const QString &value); + + QVector GetObjects() const; + + virtual void ShowDialog(bool click) Q_DECL_OVERRIDE; + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE; + +private slots: + /** @brief DeployAngleTextEdit grow or shrink formula input */ + void DeployAngleTextEdit(); + void AngleChanged(); + void FXAngle(); + void SuffixChanged(); + +protected: + virtual void CheckState() Q_DECL_OVERRIDE; + virtual void ShowVisualization() Q_DECL_OVERRIDE; + + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(DialogRotation) + Ui::DialogRotation *ui; + + /** @brief flagAngle true if value of angle is correct */ + bool flagAngle; + + /** @brief timerAngle timer of check formula of angle */ + QTimer *timerAngle; + + /** @brief angle formula of angle */ + QString formulaAngle; + + /** @brief formulaBaseHeightAngle base height defined by dialogui */ + int formulaBaseHeightAngle; + + QList objects; + + bool stage1; + + void EvalAngle(); +}; + +#endif // DIALOGROTATION_H diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.ui b/src/libs/vtools/dialogs/tools/dialogrotation.ui new file mode 100644 index 000000000..a8bc2fbb0 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogrotation.ui @@ -0,0 +1,275 @@ + + + DialogRotation + + + + 0 + 0 + 309 + 189 + + + + Rotation + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calulation + + + true + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value + + + _ + + + + + + + + + + + Origin Point: + + + + + + + + + + Suffix: + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogRotation + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogRotation + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libs/vtools/tools/drawTools/drawtools.h b/src/libs/vtools/tools/drawTools/drawtools.h index 5b0bee7ff..f52094158 100644 --- a/src/libs/vtools/tools/drawTools/drawtools.h +++ b/src/libs/vtools/tools/drawTools/drawtools.h @@ -58,5 +58,6 @@ #include "toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.h" #include "toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.h" #include "toolpoint/tooldoublepoint/vtooltruedarts.h" +#include "operation/vtoolrotation.h" #endif // DRAWTOOLS_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp new file mode 100644 index 000000000..8372e1b0b --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -0,0 +1,934 @@ +/************************************************************************ + ** + ** @file vtoolrotation.cpp + ** @author Roman Telezhynskyi + ** @date 12 4, 2016 + ** + ** @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) 2016 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 "vtoolrotation.h" +#include "../../../dialogs/tools/dialogrotation.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../../../visualization/line/vistoolrotation.h" +#include "../vwidgets/vsimplepoint.h" +#include "../vwidgets/vsimplecurve.h" + +const QString VToolRotation::TagName = QStringLiteral("operation"); +const QString VToolRotation::TagItem = QStringLiteral("item"); +const QString VToolRotation::TagSource = QStringLiteral("source"); +const QString VToolRotation::TagDestination = QStringLiteral("destination"); + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation::VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, + const QString &angle, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent) + : VDrawTool(doc, data, id), + QGraphicsItem(parent), + origPointId(origPointId), + angle(angle), + suffix(suffix), + source(source), + destination(destination), + rObjects() +{ + for (int i = 0; i < destination.size(); ++i) + { + const DestinationItem object = destination.at(i); + const QSharedPointer obj = data->GetGObject(object.id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + VSimplePoint *point = new VSimplePoint(object.id, QColor(baseColor), *data->GetPatternUnit(), &factor); + point->setParentItem(this); + point->SetType(GOType::Point); + connect(point, &VSimplePoint::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Point); + }); + connect(point, &VSimplePoint::Selected, this, &VToolRotation::ObjectSelected); + connect(point, &VSimplePoint::ShowContextMenu, this, &VToolRotation::contextMenuEvent); + connect(point, &VSimplePoint::Delete, this, &VToolRotation::DeleteFromLabel); + connect(point, &VSimplePoint::NameChangedPosition, this, &VToolRotation::LabelChangePosition); + point->RefreshGeometry(*VAbstractTool::data.GeometricObject(object.id)); + rObjects.insert(object.id, point); + break; + } + case GOType::Arc: + case GOType::EllipticalArc: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::Arc); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Arc); + }); + break; + } + case GOType::Spline: + case GOType::CubicBezier: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::Spline); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::Spline); + }); + break; + } + case GOType::SplinePath: + case GOType::CubicBezierPath: + { + VSimpleCurve *curve = InitCurve(object.id, data, GOType::SplinePath); + connect(curve, &VSimpleCurve::Choosed, [this](quint32 id) + { + emit ChoosedTool(id, SceneObject::SplinePath); + }); + break; + } + case GOType::Unknown: + break; + } + } + + ToolCreation(typeCreation); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation::~VToolRotation() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::setDialog() +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + dialogTool->SetOrigPointId(origPointId); + dialogTool->SetAngle(angle); + dialogTool->SetSuffix(suffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation *VToolRotation::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data) +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + const quint32 originPointId = dialogTool->GetOrigPointId(); + QString angle = dialogTool->GetAngle(); + const QString suffix = dialogTool->GetSuffix(); + const QVector source = dialogTool->GetObjects(); + VToolRotation* operation = Create(0, originPointId, angle, suffix, source, QVector(), + scene, doc, data, Document::FullParse, Source::FromGui); + if (operation != nullptr) + { + operation->dialog = dialogTool; + } + return operation; +} + +//--------------------------------------------------------------------------------------------------------------------- +VToolRotation *VToolRotation::Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, + const QVector &source, + const QVector &destination, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) +{ + qreal calcAngle = 0; + + calcAngle = CheckFormula(_id, angle, data); + + const auto originPoint = *data->GeometricObject(origin); + const QPointF oPoint = originPoint.toQPointF(); + + QVector dest = destination; + + quint32 id = _id; + if (typeCreation == Source::FromGui) + { + dest.clear();// Try to avoid mistake, value must be empty + + id = data->getNextId();//Just reserve id for tool + + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + dest.append(CreatePoint(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::Arc: + dest.append(CreateArc(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::EllipticalArc: + //dest.append(CreateItem(id, idObject, oPoint, angle, suffix)); + break; + case GOType::Spline: + dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::SplinePath: + dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::CubicBezier: + dest.append(CreateCurve(id, idObject, oPoint, calcAngle, suffix, data)); + break; + case GOType::CubicBezierPath: + dest.append(CreateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, + data)); + break; + case GOType::Unknown: + break; + } + } + } + else + { + for (int i = 0; i < source.size(); ++i) + { + const quint32 idObject = source.at(i); + const QSharedPointer obj = data->GetGObject(idObject); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects were handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + UpdatePoint(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id, dest.at(i).mx, + dest.at(i).my); + break; + case GOType::Arc: + UpdateArc(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::EllipticalArc: + //dest.append(UpdateItem(id, idObject, oPoint, angle, suffix, data)); + break; + case GOType::Spline: + UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::SplinePath: + UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezier: + UpdateCurve(id, idObject, oPoint, calcAngle, suffix, data, dest.at(i).id); + break; + case GOType::CubicBezierPath: + UpdateCurveWithSegments(id, idObject, oPoint, calcAngle, suffix, data, + dest.at(i).id); + break; + case GOType::Unknown: + break; + } + } + if (parse != Document::FullParse) + { + doc->UpdateToolData(id, data); + } + } + + VDrawTool::AddRecord(id, Tool::Rotation, doc); + if (parse == Document::FullParse) + { + VToolRotation *tool = new VToolRotation(doc, data, id, origin, angle, suffix, source, dest, typeCreation); + scene->addItem(tool); + InitRotationToolConnections(scene, tool); + doc->AddTool(id, tool); + doc->IncrementReferens(originPoint.getIdTool()); + for (int i = 0; i < source.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(source.at(i))->getIdTool()); + } + + for (int i = 0; i < dest.size(); ++i) + { + doc->IncrementReferens(data->GetGObject(dest.at(i).id)->getIdTool()); + } + return tool; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolRotation::getTagName() const +{ + return VToolRotation::TagName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::setEnabled(bool enabled) +{ + this->setEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolRotation::Suffix() const +{ + return suffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::GroupVisibility(quint32 object, bool visible) +{ + if (rObjects.contains(object)) + { + VAbstractSimple *obj = rObjects.value(object); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + item->setVisible(visible); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ShowVisualization(bool show) +{ + ShowToolVisualization(show); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::FullUpdateFromFile() +{ + ReadAttributes(); + QMapIterator i(rObjects); + 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())); + } + } + SetVisualization(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + else + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setAcceptHoverEvents(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointLabelHover(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelHover(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowPointLabelSelecting(bool enabled) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + item->AllowLabelSelecting(enabled); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplineHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplineSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Spline); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplinePathHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowSplinePathSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::SplinePath); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowArcHover(bool enabled) +{ + AllowCurveHover(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowArcSelecting(bool enabled) +{ + AllowCurveSelecting(enabled, GOType::Arc); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetFakeGObject(id); + SaveOptions(domElement, obj); + } + else + { + qCDebug(vTool, "Can't find tool with id = %u", id); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SetVisualization() +{ + if (vis != nullptr) + { + VisToolRotation *visual = qobject_cast(vis); + SCASSERT(visual != nullptr); + + visual->SetObjects(source); + visual->SetOriginPointId(origPointId); + visual->SetAngle(angle); + visual->RefreshGeometry(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VToolRotation::boundingRect() const +{ + QRectF recTool; + const QList items = childItems(); + foreach (QGraphicsItem *item, items) + { + recTool = recTool.united(item->boundingRect()); + recTool = recTool.united(item->childrenBoundingRect()); + } + + return recTool; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(widget); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::Disable(bool disable, const QString &namePP) +{ + enabled = !CorrectDisable(disable, namePP); + setEnabled(enabled); + + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + i.value()->SetEnabled(enabled); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ObjectSelected(bool selected, quint32 objId) +{ + emit ChangedToolSelection(selected, objId, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::DeleteFromLabel() +{ + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::LabelChangePosition(const QPointF &pos, quint32 labelId) +{ + if (rObjects.contains(labelId)) + { + VAbstractSimple *obj = rObjects.value(labelId); + if (obj->GetType() == GOType::Point) + { + VSimplePoint *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + else + { + VSimpleCurve *item = qobject_cast(obj); + SCASSERT(item != nullptr); + ChangePosition(item, labelId, pos); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SaveDialog(QDomElement &domElement) +{ + SCASSERT(dialog != nullptr); + DialogRotation *dialogTool = qobject_cast(dialog); + SCASSERT(dialogTool != nullptr); + + doc->SetAttribute(domElement, AttrCenter, QString().setNum(dialogTool->GetOrigPointId())); + doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle()); + doc->SetAttribute(domElement, AttrSuffix, dialogTool->GetSuffix()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ReadToolAttributes(const QDomElement &domElement) +{ + origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); + angle = doc->GetParametrString(domElement, AttrAngle, "0"); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); + doc->SetAttribute(tag, AttrAngle, angle); + doc->SetAttribute(tag, AttrSuffix, suffix); + + QDomElement tagObjects = doc->createElement(TagSource); + for (int i = 0; i < source.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, source.at(i)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); + + tagObjects = doc->createElement(TagDestination); + for (int i = 0; i < destination.size(); ++i) + { + QDomElement item = doc->createElement(TagItem); + doc->SetAttribute(item, AttrIdObject, destination.at(i).id); + doc->SetAttribute(item, AttrMx, qApp->fromPixel(destination.at(i).mx)); + doc->SetAttribute(item, AttrMy, qApp->fromPixel(destination.at(i).my)); + tagObjects.appendChild(item); + } + tag.appendChild(tagObjects); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::DoChangePosition(quint32 id, qreal mx, qreal my) +{ + if (rObjects.contains(id)) + { + VPointF *point = new VPointF(*VAbstractTool::data.GeometricObject(id)); + point->setMx(mx); + point->setMy(my); + VAbstractTool::data.UpdateGObject(id, point); + + VSimplePoint *item = qobject_cast(rObjects.value(id)); + SCASSERT(item != nullptr); + + item->blockSignals(true); + item->setPos(QPointF(mx, my)); + item->blockSignals(false); + item->RefreshLine(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdateNamePosition(quint32 id) +{ + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); +// auto moveLabel = new MoveLabel(doc, point->mx(), point->my(), id, scene()); +// connect(moveLabel, &MoveLabel::ChangePosition, this, &VToolSinglePoint::DoChangePosition); +// qApp->getUndoStack()->push(moveLabel); +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = rotated.mx(); + item.my = rotated.my(); + item.id = data->AddGObject(new VPointF(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + + DestinationItem item; + item.mx = INT_MAX; + item.my = INT_MAX; + item.id = data->AddGObject(new Item(rotated)); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +DestinationItem VToolRotation::CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddArc(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddCurve(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + qreal angle, const QString &suffix, VContainer *data) +{ + const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); + return item; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my) +{ + const QSharedPointer point = data->GeometricObject(idItem); + VPointF rotated = point->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + rotated.setMx(mx); + rotated.setMy(my); + data->UpdateGObject(id, new VPointF(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + const QSharedPointer i = data->GeometricObject(idItem); + Item rotated = i->Rotate(origin, angle, suffix); + rotated.setIdObject(idTool); + data->UpdateGObject(id, new Item(rotated)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddArc(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddCurve(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id) +{ + UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + data->AddCurveWithSegments(data->GeometricObject(id), id); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::ShowToolVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + AddVisualization(); + SetVisualization(); + } + else + { + if (T *visual = qobject_cast(vis)) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos) +{ + const QPointF p = pos - item->pos(); + DoChangePosition(id, p.x(), p.y()); + UpdateNamePosition(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve *VToolRotation::InitCurve(quint32 id, VContainer *data, GOType curveType) +{ + VSimpleCurve *curve = new VSimpleCurve(id, QColor(baseColor), *data->GetPatternUnit(), &factor); + curve->setParentItem(this); + curve->SetType(curveType); + connect(curve, &VSimpleCurve::Selected, this, &VToolRotation::ObjectSelected); + connect(curve, &VSimpleCurve::ShowContextMenu, this, &VToolRotation::contextMenuEvent); + curve->RefreshGeometry(VAbstractTool::data.GeometricObject(id)); + rObjects.insert(id, curve); + return curve; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowCurveHover(bool enabled, GOType type) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setAcceptHoverEvents(enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AllowCurveSelecting(bool enabled, GOType type) +{ + QMapIterator i(rObjects); + while (i.hasNext()) + { + i.next(); + if (i.value()->GetType() != GOType::Point) + { + VSimpleCurve *item = qobject_cast(i.value()); + SCASSERT(item != nullptr); + if (item->GetType() == type) + { + item->setFlag(QGraphicsItem::ItemIsSelectable, enabled); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolRotation::AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId) +{ + QDomElement obj = doc->createElement(TagItem); + doc->SetAttribute(obj, AttrIdObject, objId); + domElement.appendChild(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolRotation::InitRotationToolConnections(VMainGraphicsScene *scene, T *tool) +{ + SCASSERT(scene != nullptr); + SCASSERT(tool != nullptr); + + InitDrawToolConnections(scene, tool); + + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemHover, tool, &T::AllowPointHover); + QObject::connect(scene, &VMainGraphicsScene::EnablePointItemSelection, tool, &T::AllowPointSelecting); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemHover, tool, &T::AllowPointLabelHover); + QObject::connect(scene, &VMainGraphicsScene::EnableLabelItemSelection, tool, &T::AllowPointLabelSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemHover, tool, &T::AllowSplineHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplineItemSelection, tool, &T::AllowSplineSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemHover, tool, &T::AllowSplinePathHover); + QObject::connect(scene, &VMainGraphicsScene::EnableSplinePathItemSelection, tool, &T::AllowSplinePathSelecting); + + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemHover, tool, &T::AllowArcHover); + QObject::connect(scene, &VMainGraphicsScene::EnableArcItemSelection, tool, &T::AllowArcSelecting); +} diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h new file mode 100644 index 000000000..34c78b9c9 --- /dev/null +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -0,0 +1,175 @@ +/************************************************************************ + ** + ** @file vtoolrotation.h + ** @author Roman Telezhynskyi + ** @date 12 4, 2016 + ** + ** @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) 2016 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 VTOOLROTATION_H +#define VTOOLROTATION_H + +#include "../vdrawtool.h" + +struct DestinationItem +{ + quint32 id; + qreal mx; + qreal my; +}; + +class VAbstractSimple; +class VSimpleCurve; + +class VToolRotation : public VDrawTool, public QGraphicsItem +{ + Q_OBJECT +public: + VToolRotation(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 origPointId, + const QString &angle, const QString &suffix, const QVector &source, + const QVector &destination, const Source &typeCreation, + QGraphicsItem *parent = nullptr); + virtual ~VToolRotation(); + virtual void setDialog() Q_DECL_OVERRIDE; + static VToolRotation* Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + VContainer *data); + static VToolRotation* Create(const quint32 _id, const quint32 &origin, QString &angle, const QString &suffix, + const QVector &source, const QVector &destination, + VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); + // cppcheck-suppress duplInheritedMember + static const QString TagName; + static const QString TagItem; + static const QString TagSource; + static const QString TagDestination; + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Tool::Rotation)}; + virtual QString getTagName() const Q_DECL_OVERRIDE; + + void setEnabled(bool enabled); + + QString Suffix() const; + + virtual void GroupVisibility(quint32 object, bool visible) Q_DECL_OVERRIDE; + virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + + virtual QRectF boundingRect() const Q_DECL_OVERRIDE; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE; + +public slots: + virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; + + virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; + virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + + void AllowPointHover(bool enabled); + void AllowPointSelecting(bool enabled); + + void AllowPointLabelHover(bool enabled); + void AllowPointLabelSelecting(bool enabled); + + void AllowSplineHover(bool enabled); + void AllowSplineSelecting(bool enabled); + + void AllowSplinePathHover(bool enabled); + void AllowSplinePathSelecting(bool enabled); + + void AllowArcHover(bool enabled); + void AllowArcSelecting(bool enabled); + + virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; + void ObjectSelected(bool selected, quint32 objId); + void DeleteFromLabel(); + void LabelChangePosition(const QPointF &pos, quint32 labelId); + +protected: + virtual void AddToFile() Q_DECL_OVERRIDE; + virtual void RefreshDataInFile() Q_DECL_OVERRIDE; + virtual void SetVisualization() Q_DECL_OVERRIDE; + virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; + +private slots: + void DoChangePosition(quint32 id, qreal mx, qreal my); + +private: + Q_DISABLE_COPY(VToolRotation) + quint32 origPointId; + QString angle; + QString suffix; + + QVector source; + QVector destination; + + QMap rObjects; + + void UpdateNamePosition(quint32 id); + + static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data); + + template + static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data); + template + static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data); + + static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id, qreal mx, qreal my); + template + static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id); + template + static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + const QString &suffix, VContainer *data, quint32 id); + + template + void ShowToolVisualization(bool show); + + void ChangePosition(QGraphicsItem *item, quint32 id, const QPointF &pos); + + VSimpleCurve *InitCurve(quint32 id, VContainer *data, GOType curveType); + + template + static void InitRotationToolConnections(VMainGraphicsScene *scene, T *tool); + + void AllowCurveHover(bool enabled, GOType type); + void AllowCurveSelecting(bool enabled, GOType type); + + static void AddSourceObject(VAbstractPattern *doc, QDomElement &domElement, quint32 objId); +}; + +#endif // VTOOLROTATION_H diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index fc7662e9b..88199a6ec 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -31,7 +31,6 @@ #include -const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool"); //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 9ebc987ce..270faad67 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -45,7 +45,6 @@ public: VAbstractNode(VAbstractPattern *doc, VContainer *data, const quint32 &id, const quint32 &idNode, const quint32 &idTool, QObject *parent = nullptr); virtual ~VAbstractNode() Q_DECL_OVERRIDE {} - static const QString AttrIdObject; static const QString AttrIdTool; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; virtual void incrementReferens() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index a8ed05c2e..36b6f986c 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -49,7 +49,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ - $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ + $$PWD/drawTools/operation/vtoolrotation.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -96,4 +97,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ - $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp + $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ + $$PWD/drawTools/operation/vtoolrotation.cpp diff --git a/src/libs/vtools/visualization/line/vistoolrotation.cpp b/src/libs/vtools/visualization/line/vistoolrotation.cpp new file mode 100644 index 000000000..fd0aed0f3 --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolrotation.cpp @@ -0,0 +1,258 @@ +/************************************************************************ + ** + ** @file vistoolrotation.cpp + ** @author Roman Telezhynskyi + ** @date 11 4, 2016 + ** + ** @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) 2016 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 "vistoolrotation.h" +#include "../vgeometry/vpointf.h" +#include "../vgeometry/varc.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vgeometry/vspline.h" +#include "../vgeometry/vsplinepath.h" +#include "../vgeometry/vcubicbezier.h" +#include "../vgeometry/vcubicbezierpath.h" +#include "../vpatterndb/vcontainer.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +VisToolRotation::VisToolRotation(const VContainer *data, QGraphicsItem *parent) + : VisLine(data, parent), + angle(INT_MIN), + objects(), + point(nullptr), + xAxis(nullptr), + supportColor2(Qt::darkGreen), + points(), + curves() +{ + point = InitPoint(supportColor2, this); + xAxis = InitItem(supportColor2, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolRotation::~VisToolRotation() +{ + qDeleteAll(points); + qDeleteAll(curves); +} + +//--------------------------------------------------------------------------------------------------------------------- +#if defined(Q_CC_GNU) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch-default" +#endif + +void VisToolRotation::RefreshGeometry() +{ + if (objects.isEmpty()) + { + return; + } + + if (object1Id != NULL_ID) + { + const QPointF origin = Visualization::data->GeometricObject(object1Id)->toQPointF(); + DrawPoint(point, origin, supportColor2); + + QLineF rLine; + if (VFuzzyComparePossibleNulls(angle, INT_MIN)) + { + rLine = QLineF(origin, Visualization::scenePos); + + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) + { + rLine.setAngle(CorrectAngle(rLine.angle())); + } + + rLine.setP2(Ray(origin, rLine.angle())); + } + else + { + rLine = QLineF(origin, Ray(origin, angle)); + } + + if (mode == Mode::Creation) + { + DrawLine(this, rLine, supportColor2, Qt::DashLine); + DrawLine(xAxis, QLineF(origin, Ray(origin, 0)), supportColor2, Qt::DashLine); + } + + Visualization::toolTip = tr("Rotating angle = %1°, Shift - sticking angle, " + "Mouse click - finish creation").arg(rLine.angle()); + + int iPoint = -1; + int iCurve = -1; + for (int i = 0; i < objects.size(); ++i) + { + const quint32 id = objects.at(i); + const QSharedPointer obj = Visualization::data->GetGObject(id); + + // This check helps to find missed objects in the switch + Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 7, "Not all objects was handled."); + + switch(static_cast(obj->getType())) + { + case GOType::Point: + { + const QSharedPointer p = Visualization::data->GeometricObject(id); + + ++iPoint; + QGraphicsEllipseItem *point = GetPoint(iPoint); + DrawPoint(point, p->toQPointF(), supportColor); + + ++iPoint; + point = GetPoint(iPoint); + DrawPoint(point, p->Rotate(origin, angle).toQPointF(), supportColor); + break; + } + case GOType::Arc: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::EllipticalArc: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::Spline: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::SplinePath: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::CubicBezier: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::CubicBezierPath: + { + iCurve = AddCurve(origin, id, iCurve); + break; + } + case GOType::Unknown: + break; + } + } + } +} + +#if defined(Q_CC_GNU) + #pragma GCC diagnostic pop +#endif + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetObjects(QVector objects) +{ + this->objects = objects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetOriginPointId(quint32 value) +{ + object1Id = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VisToolRotation::Angle() const +{ + return QString::number(line().angle()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::SetAngle(const QString &expression) +{ + angle = FindVal(expression, Visualization::data->PlainVariables()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolRotation::VisualMode(const quint32 &pointId) +{ + Q_UNUSED(pointId); + VMainGraphicsScene *scene = qobject_cast(qApp->getCurrentScene()); + SCASSERT(scene != nullptr); + + Visualization::scenePos = scene->getScenePos(); + RefreshGeometry(); + + AddOnScene(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolRotation::GetPoint(quint32 i) +{ + if (not points.isEmpty() && static_cast(points.size() - 1) >= i) + { + return points.at(static_cast(i)); + } + else + { + auto point = InitPoint(supportColor, this); + points.append(point); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsPathItem *VisToolRotation::GetCurve(quint32 i) +{ + if (not curves.isEmpty() && static_cast(curves.size() - 1) >= i) + { + return curves.at(static_cast(i)); + } + else + { + auto curve = InitItem(supportColor, this); + curves.append(curve); + return curve; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +int VisToolRotation::AddCurve(const QPointF &origin, quint32 id, int i) +{ + const QSharedPointer curve = Visualization::data->GeometricObject(id); + + ++i; + QGraphicsPathItem *path = GetCurve(i); + DrawPath(path, curve->GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + + ++i; + path = GetCurve(i); + const Item rotated = curve->Rotate(origin, angle); + DrawPath(path, rotated.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); + + return i; +} diff --git a/src/libs/vtools/visualization/line/vistoolrotation.h b/src/libs/vtools/visualization/line/vistoolrotation.h new file mode 100644 index 000000000..00f36202a --- /dev/null +++ b/src/libs/vtools/visualization/line/vistoolrotation.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file vistoolrotation.h + ** @author Roman Telezhynskyi + ** @date 11 4, 2016 + ** + ** @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) 2016 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 VISTOOLROTATION_H +#define VISTOOLROTATION_H + +#include "visline.h" + +class VisToolRotation : public VisLine +{ + Q_OBJECT +public: + explicit VisToolRotation(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolRotation(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + + void SetObjects(QVector objects); + void SetOriginPointId(quint32 value); + + QString Angle() const; + void SetAngle(const QString &expression); + + virtual void VisualMode(const quint32 &pointId = NULL_ID) Q_DECL_OVERRIDE; + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolRotation)}; +private: + Q_DISABLE_COPY(VisToolRotation) + qreal angle; + QVector objects; + QGraphicsEllipseItem *point; + QGraphicsLineItem *xAxis; + QColor supportColor2; + + QVector points; + QVector curves; + + QGraphicsEllipseItem * GetPoint(quint32 i); + QGraphicsPathItem * GetCurve(quint32 i); + + template + int AddCurve(const QPointF &origin, quint32 id, int i); +}; + +#endif // VISTOOLROTATION_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 1f47f42be..fce6c442e 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -32,7 +32,8 @@ HEADERS += \ $$PWD/path/vistoolarcwithlength.h \ $$PWD/path/vistoolpointofintersectioncurves.h \ $$PWD/path/vistoolcubicbezier.h \ - $$PWD/path/vistoolcubicbezierpath.h + $$PWD/path/vistoolcubicbezierpath.h \ + visualization/line/vistoolrotation.h SOURCES += \ $$PWD/visualization.cpp \ @@ -65,4 +66,5 @@ SOURCES += \ $$PWD/path/vistoolarcwithlength.cpp \ $$PWD/path/vistoolpointofintersectioncurves.cpp \ $$PWD/path/vistoolcubicbezier.cpp \ - $$PWD/path/vistoolcubicbezierpath.cpp + $$PWD/path/vistoolcubicbezierpath.cpp \ + visualization/line/vistoolrotation.cpp diff --git a/src/libs/vwidgets/vabstractsimple.cpp b/src/libs/vwidgets/vabstractsimple.cpp index 1649df7f6..44b890f79 100644 --- a/src/libs/vwidgets/vabstractsimple.cpp +++ b/src/libs/vwidgets/vabstractsimple.cpp @@ -28,16 +28,32 @@ #include "vabstractsimple.h" +#include +#include + //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) - :QObject(parent), id (id), factor(factor), currentColor(currentColor), enabled(true), patternUnit(patternUnit) + : QObject(parent), + id (id), + factor(factor), + currentColor(currentColor), + enabled(true), + patternUnit(patternUnit), + selectionType(SelectionType::ByMouseRelease), + type(GOType::Unknown) {} //--------------------------------------------------------------------------------------------------------------------- VAbstractSimple::~VAbstractSimple() {} +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::ToolSelectionType(const SelectionType &type) +{ + selectionType = type; +} + //--------------------------------------------------------------------------------------------------------------------- QColor VAbstractSimple::CorrectColor(const QColor &color) const { @@ -50,3 +66,28 @@ QColor VAbstractSimple::CorrectColor(const QColor &color) const return Qt::gray; } } + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +QColor VAbstractSimple::GetCurrentColor() const +{ + return currentColor; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::ContextMenu(QGraphicsSceneContextMenuEvent *event) +{ + emit ShowContextMenu(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +GOType VAbstractSimple::GetType() const +{ + return type; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSimple::SetType(const GOType &value) +{ + type = value; +} diff --git a/src/libs/vwidgets/vabstractsimple.h b/src/libs/vwidgets/vabstractsimple.h index bcebd73d1..7bcbac68c 100644 --- a/src/libs/vwidgets/vabstractsimple.h +++ b/src/libs/vwidgets/vabstractsimple.h @@ -33,6 +33,11 @@ #include #include #include "../vmisc/def.h" +#include "../vgeometry/vgeometrydef.h" +#include "../ifc/ifcdef.h" + +class QGraphicsSceneContextMenuEvent; +class QGraphicsItem; class VAbstractSimple : public QObject { @@ -40,9 +45,22 @@ class VAbstractSimple : public QObject public: VAbstractSimple(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, QObject *parent = 0); - virtual ~VAbstractSimple() Q_DECL_OVERRIDE; + virtual ~VAbstractSimple(); - virtual void ChangedActivDraw(const bool &flag)=0; + virtual void ToolSelectionType(const SelectionType &type); + + QColor GetCurrentColor() const; + + virtual void SetEnabled(bool enabled) { Q_UNUSED(enabled); } + + GOType GetType() const; + void SetType(const GOType &value); + +signals: + void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); + +public slots: + void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: /** @brief id spline id. */ @@ -58,10 +76,20 @@ protected: Unit patternUnit; + SelectionType selectionType; + + GOType type; + QColor CorrectColor(const QColor &color) const; template - void SetPen(T *item, const QColor &color, qreal width); + void SetPen(T *item, const QColor &color, qreal width); + + template + void SimpleChangedActivDraw(T *item, const bool &flag); + + template + void SetSimpleCurrentColor(T *item, const QColor &value); private: Q_DISABLE_COPY(VAbstractSimple) @@ -81,4 +109,21 @@ void VAbstractSimple::SetPen(T *item, const QColor &color, qreal width) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractSimple::SimpleChangedActivDraw(T *item, const bool &flag) +{ + enabled = flag; + item->setEnabled(enabled); + SetPen(item, currentColor, WidthHairLine(patternUnit)); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VAbstractSimple::SetSimpleCurrentColor(T *item, const QColor &value) +{ + currentColor = value; + SetPen(item, CorrectColor(currentColor), item->pen().widthF()); +} + #endif // VABSTRACTSIMPLE_H diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp new file mode 100644 index 000000000..6e93d62a1 --- /dev/null +++ b/src/libs/vwidgets/vsimplecurve.cpp @@ -0,0 +1,133 @@ +/************************************************************************ + ** + ** @file vsimplecurve.cpp + ** @author Roman Telezhynskyi + ** @date 7 5, 2016 + ** + ** @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) 2016 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 "vsimplecurve.h" +#include "../ifc/ifcdef.h" +#include "../vgeometry/vabstractcurve.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve::VSimpleCurve(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent) + : VAbstractSimple(id, currentColor, patternUnit, factor, parent), + QGraphicsPathItem(), + m_curve() +{ + this->setBrush(QBrush(Qt::NoBrush)); + SetPen(this, currentColor, WidthHairLine(patternUnit)); + this->setAcceptHoverEvents(true); +} + +//--------------------------------------------------------------------------------------------------------------------- +VSimpleCurve::~VSimpleCurve() +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::SetCurrentColor(const QColor &value) +{ + SetSimpleCurrentColor(this, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::ChangedActivDraw(bool flag) +{ + SimpleChangedActivDraw(this, flag); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::RefreshGeometry(const QSharedPointer &curve) +{ + m_curve = curve; + if (not curve.isNull()) + { + setPath(curve->GetPath(PathDirection::Hide)); + } + else + { + qWarning() << tr("VSimpleCurve::RefreshGeometry: pointer to curve is null."); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::CurveChoosed() +{ + emit Choosed(id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::CurveSelected(bool selected) +{ + emit Selected(selected, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + // Special for not selectable item first need to call standard mousePressEvent then accept event + QGraphicsPathItem::mousePressEvent(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 VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (selectionType == SelectionType::ByMouseRelease) + { + if (event->button() == Qt::LeftButton) + { + emit Choosed(id); + } + } + QGraphicsPathItem::mouseReleaseEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + SetPen(this, currentColor, WidthMainLine(patternUnit)); + QGraphicsPathItem::hoverEnterEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + SetPen(this, currentColor, WidthHairLine(patternUnit)); + QGraphicsPathItem::hoverLeaveEvent(event); +} diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h new file mode 100644 index 000000000..8fb35fe8c --- /dev/null +++ b/src/libs/vwidgets/vsimplecurve.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file vsimplecurve.h + ** @author Roman Telezhynskyi + ** @date 7 5, 2016 + ** + ** @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) 2016 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 VSIMPLECURVE_H +#define VSIMPLECURVE_H + +#include "vabstractsimple.h" + +#include + +class VAbstractCurve; + +class VSimpleCurve : public VAbstractSimple, public QGraphicsPathItem +{ + Q_OBJECT +public: + VSimpleCurve(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor = nullptr, + QObject *parent = nullptr); + virtual ~VSimpleCurve(); + + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::SimpleCurve)}; + + void SetCurrentColor(const QColor &value); + + void ChangedActivDraw(bool flag); + void RefreshGeometry(const QSharedPointer &curve); +signals: + /** + * @brief Choosed send id when clicked. + * @param id point id. + */ + void Choosed(quint32 id); + void Selected(bool selected, quint32 id); + void Delete(); + +public slots: + void CurveChoosed(); + void CurveSelected(bool selected); + +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; + +private: + Q_DISABLE_COPY(VSimpleCurve) + + QSharedPointer m_curve; +}; + +#endif // VSIMPLECURVE_H diff --git a/src/libs/vwidgets/vsimplepoint.cpp b/src/libs/vwidgets/vsimplepoint.cpp index 0fafd4051..5819efc1b 100644 --- a/src/libs/vwidgets/vsimplepoint.cpp +++ b/src/libs/vwidgets/vsimplepoint.cpp @@ -39,8 +39,7 @@ //--------------------------------------------------------------------------------------------------------------------- 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), - selectionType(SelectionType::ByMouseRelease) + radius(ToPixel(DefPointRadius/*mm*/, Unit::Mm)), namePoint(nullptr), lineName(nullptr) { namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VSimplePoint::ContextMenu); @@ -59,11 +58,15 @@ VSimplePoint::~VSimplePoint() {} //--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::ChangedActivDraw(const bool &flag) +void VSimplePoint::SetCurrentColor(const QColor &value) { - enabled = flag; - setEnabled(enabled); - SetPen(this, currentColor, WidthHairLine(patternUnit)); + SetSimpleCurrentColor(this, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSimplePoint::ChangedActivDraw(bool flag) +{ + SimpleChangedActivDraw(this, flag); } //--------------------------------------------------------------------------------------------------------------------- @@ -150,7 +153,7 @@ void VSimplePoint::AllowLabelSelecting(bool enabled) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ToolSelectionType(const SelectionType &type) { - selectionType = type; + VAbstractSimple::ToolSelectionType(type); namePoint->LabelSelectionType(type); } @@ -175,13 +178,7 @@ void VSimplePoint::PointSelected(bool selected) //--------------------------------------------------------------------------------------------------------------------- void VSimplePoint::ChangedPosition(const QPointF &pos) { - emit NameChangedPosition(pos); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::ContextMenu(QGraphicsSceneContextMenuEvent *event) -{ - emit ShowContextMenu(event); + emit NameChangedPosition(pos, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -242,17 +239,3 @@ QVariant VSimplePoint::itemChange(QGraphicsItem::GraphicsItemChange change, cons return QGraphicsEllipseItem::itemChange(change, value); } - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -QColor VSimplePoint::GetCurrentColor() const -{ - return currentColor; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimplePoint::SetCurrentColor(const QColor &value) -{ - currentColor = value; - SetPen(this, CorrectColor(currentColor), pen().widthF()); -} diff --git a/src/libs/vwidgets/vsimplepoint.h b/src/libs/vwidgets/vsimplepoint.h index c412ee594..642757805 100644 --- a/src/libs/vwidgets/vsimplepoint.h +++ b/src/libs/vwidgets/vsimplepoint.h @@ -44,21 +44,19 @@ public: QObject *parent = nullptr); virtual ~VSimplePoint() Q_DECL_OVERRIDE; - virtual void ChangedActivDraw(const bool &flag) Q_DECL_OVERRIDE; - virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Vis::SimplePoint)}; + void ChangedActivDraw(bool flag); void RefreshLine(); void RefreshGeometry(const VPointF &point); - void SetEnabled(bool enabled); + virtual void SetEnabled(bool enabled) Q_DECL_OVERRIDE; void EnableToolMove(bool move); void AllowLabelHover(bool enabled); void AllowLabelSelecting(bool enabled); - void ToolSelectionType(const SelectionType &type); + virtual void ToolSelectionType(const SelectionType &type) Q_DECL_OVERRIDE; - QColor GetCurrentColor() const; - void SetCurrentColor(const QColor &value); + void SetCurrentColor(const QColor &value); signals: /** * @brief Choosed send id when clicked. @@ -66,16 +64,14 @@ signals: */ void Choosed(quint32 id); void Selected(bool selected, quint32 id); - void ShowContextMenu(QGraphicsSceneContextMenuEvent * event); void Delete(); - void NameChangedPosition(const QPointF &pos); + void NameChangedPosition(const QPointF &pos, quint32 id); public slots: void DeleteFromLabel(); void PointChoosed(); void PointSelected(bool selected); void ChangedPosition(const QPointF &pos); - void ContextMenu(QGraphicsSceneContextMenuEvent * event); protected: virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; @@ -95,9 +91,6 @@ private: /** @brief lineName line what we see if label moved too away from point. */ QGraphicsLineItem *lineName; - - SelectionType selectionType; - }; #endif // VSIMPLEPOINT_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 619eb87e5..d80356e60 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -9,7 +9,8 @@ SOURCES += \ $$PWD/vgraphicssimpletextitem.cpp \ $$PWD/vsimplepoint.cpp \ $$PWD/vabstractsimple.cpp \ - $$PWD/vnobrushscalepathitem.cpp + $$PWD/vnobrushscalepathitem.cpp \ + $$PWD/vsimplecurve.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -22,4 +23,5 @@ HEADERS += \ $$PWD/vgraphicssimpletextitem.h \ $$PWD/vsimplepoint.h \ $$PWD/vabstractsimple.h \ - $$PWD/vnobrushscalepathitem.h + $$PWD/vnobrushscalepathitem.h \ + $$PWD/vsimplecurve.h