diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index fa119d6bf..a33edaeee 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -29,6 +29,7 @@ #include "dialogpiecepath.h" #include "ui_dialogpiecepath.h" #include "../vpatterndb/vpiecenode.h" +#include "visualization/path/vistoolpiecepath.h" #include @@ -36,7 +37,7 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogPiecePath), - m_showMode(true) + m_showMode(false) { ui->setupUi(this); InitOkCancel(ui); @@ -49,15 +50,13 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget if (not m_showMode) { - //vis = new VisToolPiecePath(data); + vis = new VisToolPiecePath(data); } else { ui->comboBoxType->setDisabled(true); ui->comboBoxPiece->setDisabled(true); } - - show();//temporary } //--------------------------------------------------------------------------------------------------------------------- @@ -108,22 +107,22 @@ void DialogPiecePath::ChosenObject(quint32 id, const SceneObject &type) if (not m_showMode) { -// auto visPath = qobject_cast(vis); -// SCASSERT(visPath != nullptr); -// const VPiecePath p = CreatePath(); -// visPath->SetPath(p); + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + const VPiecePath p = CreatePath(); + visPath->SetPath(p); -// if (p.CountNodes() == 1) -// { -// emit ToolTip(tr("Select main path objects, Shift - reverse direction curve, " -// "Enter - finish creation")); + if (p.CountNodes() == 1) + { + emit ToolTip(tr("Select main path objects, Shift - reverse direction curve, " + "Enter - finish creation")); -// visPath->VisualMode(NULL_ID); -// } -// else -// { -// visPath->RefreshGeometry(); -// } + visPath->VisualMode(NULL_ID); + } + else + { + visPath->RefreshGeometry(); + } } } } @@ -138,10 +137,10 @@ void DialogPiecePath::ShowDialog(bool click) if (not m_showMode) { -// auto visPath = qobject_cast(vis); -// SCASSERT(visPath != nullptr); -// visPath->SetMode(Mode::Show); -// visPath->RefreshGeometry(); + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->SetMode(Mode::Show); + visPath->RefreshGeometry(); } setModal(true); show(); @@ -206,10 +205,10 @@ void DialogPiecePath::ListChanged() { if (not m_showMode) { -// auto visPath = qobject_cast(vis); -// SCASSERT(visPath != nullptr); -// visPath->SetPiece(CreatePath()); -// visPath->RefreshGeometry(); + auto visPath = qobject_cast(vis); + SCASSERT(visPath != nullptr); + visPath->SetPath(CreatePath()); + visPath->RefreshGeometry(); } } @@ -230,49 +229,64 @@ void DialogPiecePath::NameChanged() } //--------------------------------------------------------------------------------------------------------------------- -//VPiecePath DialogPiecePath::GetPiecePath() const -//{ - -//} +VPiecePath DialogPiecePath::GetPiecePath() const +{ + return CreatePath(); +} //--------------------------------------------------------------------------------------------------------------------- -//void DialogPiecePath::SetPiecePath(const VPiecePath &path) -//{ +void DialogPiecePath::SetPiecePath(const VPiecePath &path) +{ + ui->listWidget->clear(); + for (int i = 0; i < path.CountNodes(); ++i) + { + NewItem(path.at(i)); + } -//} + ValidObjects(PathIsValid()); + + ListChanged(); +} //--------------------------------------------------------------------------------------------------------------------- -//VPiecePath DialogPiecePath::CreatePath() const -//{ +VPiecePath DialogPiecePath::CreatePath() const +{ + VPiecePath path; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem *item = ui->listWidget->item(i); + path.Append(qvariant_cast(item->data(Qt::UserRole))); + } -//} + return path; +} //--------------------------------------------------------------------------------------------------------------------- bool DialogPiecePath::PathIsValid() const { -// QString url = DialogWarningIcon(); + QString url = DialogWarningIcon(); -// if(CreatePath().Points(data).count() < 2) -// { -// url += tr("You need more points!"); -// ui->helpLabel->setText(url); -// return false; -// } -// else -// { -// if (FirstPointEqualLast(ui->listWidget)) -// { -// url += tr("First point cannot be equal to the last point!"); -// ui->helpLabel->setText(url); -// return false; -// } -// else if (DoublePoints(ui->listWidget)) -// { -// url += tr("You have double points!"); -// ui->helpLabel->setText(url); -// return false; -// } -// } + if(CreatePath().PathPoints(data).count() < 2) + { + url += tr("You need more points!"); + ui->helpLabel->setText(url); + return false; + } + else + { + if (FirstPointEqualLast(ui->listWidget)) + { + url += tr("First point cannot be equal to the last point!"); + ui->helpLabel->setText(url); + return false; + } + else if (DoublePoints(ui->listWidget)) + { + url += tr("You have double points!"); + ui->helpLabel->setText(url); + return false; + } + } ui->helpLabel->setText(tr("Ready!")); return true; } diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.h b/src/libs/vtools/dialogs/tools/dialogpiecepath.h index f1d10f965..78a1056de 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.h +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.h @@ -45,8 +45,8 @@ public: void DisableShowMode(bool disable); -// VPiecePath GetPiecePath() const; -// void SetPiecePath(const VPiecePath &path); + VPiecePath GetPiecePath() const; + void SetPiecePath(const VPiecePath &path); public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; @@ -67,7 +67,7 @@ private: Ui::DialogPiecePath *ui; bool m_showMode; -// VPiecePath CreatePath() const; + VPiecePath CreatePath() const; bool PathIsValid() const; void ValidObjects(bool value); diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.cpp b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp new file mode 100644 index 000000000..a6755dbcc --- /dev/null +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.cpp @@ -0,0 +1,100 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 22 11, 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 "vistoolpiecepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPiecePath::VisToolPiecePath(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), + m_points(), + m_line(nullptr), + m_path() +{ + m_line = InitItem(supportColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolPiecePath::~VisToolPiecePath() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPiecePath::RefreshGeometry() +{ + HideAllItems(); + + if (m_path.CountNodes() > 0) + { + DrawPath(this, m_path.PainterPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap); + + const QVector nodes = m_path.PathNodePoints(Visualization::data); + + for (int i = 0; i < nodes.size(); ++i) + { + QGraphicsEllipseItem *point = GetPoint(static_cast(i), supportColor); + DrawPoint(point, nodes.at(i), supportColor); + } + + if (mode == Mode::Creation) + { + const QVector points = m_path.PathPoints(Visualization::data); + if (points.size() > 0) + { + DrawLine(m_line, QLineF(points.last(), Visualization::scenePos), supportColor, Qt::DashLine); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPiecePath::SetPath(const VPiecePath &path) +{ + m_path = path; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolPiecePath::GetPoint(quint32 i, const QColor &color) +{ + return GetPointItem(Visualization::data, factor, m_points, i, color, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolPiecePath::HideAllItems() +{ + if (m_line) + { + m_line->setVisible(false); + } + + for (int i=0; i < m_points.size(); ++i) + { + if (QGraphicsEllipseItem *item = m_points.at(i)) + { + item->setVisible(false); + } + } +} diff --git a/src/libs/vtools/visualization/path/vistoolpiecepath.h b/src/libs/vtools/visualization/path/vistoolpiecepath.h new file mode 100644 index 000000000..dc5c8d08e --- /dev/null +++ b/src/libs/vtools/visualization/path/vistoolpiecepath.h @@ -0,0 +1,63 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 22 11, 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 VISTOOLPIECEPATH_H +#define VISTOOLPIECEPATH_H + +#include +#include + +#include "vispath.h" +#include "../vpatterndb/vpiecepath.h" + +class VisToolPiecePath : public VisPath +{ + Q_OBJECT +public: + VisToolPiecePath(const VContainer *data, QGraphicsItem *parent = nullptr); + virtual ~VisToolPiecePath(); + + virtual void RefreshGeometry() Q_DECL_OVERRIDE; + void SetPath(const VPiecePath &piece); + virtual int type() const Q_DECL_OVERRIDE {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPiecePath)}; + +private: + Q_DISABLE_COPY(VisToolPiecePath) + QVector m_points; + + QGraphicsLineItem *m_line; + + VPiecePath m_path; + + QGraphicsEllipseItem* GetPoint(quint32 i, const QColor &color); + + void HideAllItems(); +}; + +#endif // VISTOOLPIECEPATH_H diff --git a/src/libs/vtools/visualization/visualization.pri b/src/libs/vtools/visualization/visualization.pri index 7f16b5713..30de372b5 100644 --- a/src/libs/vtools/visualization/visualization.pri +++ b/src/libs/vtools/visualization/visualization.pri @@ -38,7 +38,8 @@ HEADERS += \ $$PWD/line/operation/visoperation.h \ $$PWD/line/operation/vistoolflippingbyaxis.h \ $$PWD/line/operation/vistoolmove.h \ - $$PWD/path/vistoolpiece.h + $$PWD/path/vistoolpiece.h \ + $$PWD/path/vistoolpiecepath.h SOURCES += \ $$PWD/visualization.cpp \ @@ -77,4 +78,5 @@ SOURCES += \ $$PWD/line/operation/visoperation.cpp \ $$PWD/line/operation/vistoolflippingbyaxis.cpp \ $$PWD/line/operation/vistoolmove.cpp \ - $$PWD/path/vistoolpiece.cpp + $$PWD/path/vistoolpiece.cpp \ + $$PWD/path/vistoolpiecepath.cpp