diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index 885700f4c..7049a309d 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -37,7 +37,8 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogPiecePath), - m_showMode(false) + m_showMode(false), + m_saWidth(0) { ui->setupUi(this); InitOkCancel(ui); @@ -56,6 +57,37 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget flagError = PathIsValid(); CheckState(); + const QString suffix = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit(), true); + ui->doubleSpinBoxSeams->setSuffix(suffix); + ui->doubleSpinBoxSABefore->setSuffix(suffix); + ui->doubleSpinBoxSAAfter->setSuffix(suffix); + + if(qApp->patternUnit() == Unit::Inch) + { + ui->doubleSpinBoxSeams->setDecimals(5); + ui->doubleSpinBoxSABefore->setDecimals(5); + ui->doubleSpinBoxSAAfter->setDecimals(5); + } + + InitNodesList(); + connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPiecePath::NodeChanged); + + connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefBefore); + connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogPiecePath::ReturnDefAfter); + + connect(ui->doubleSpinBoxSeams, static_cast(&QDoubleSpinBox::valueChanged), + [this](){NodeChanged(ui->comboBoxNodes->currentIndex());}); + + connect(ui->doubleSpinBoxSABefore, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogPiecePath::ChangedSABefore); + connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogPiecePath::ChangedSAAfter); + + InitNodeAngles(ui->comboBoxAngle); + connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, + &DialogPiecePath::NodeAngleChanged); + if (not m_showMode) { vis = new VisToolPiecePath(data); @@ -65,6 +97,8 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget ui->comboBoxType->setDisabled(true); ui->comboBoxPiece->setDisabled(true); } + + ui->tabWidget->removeTab(1); } //--------------------------------------------------------------------------------------------------------------------- @@ -221,6 +255,8 @@ void DialogPiecePath::ListChanged() visPath->SetPath(CreatePath()); visPath->RefreshGeometry(); } + + InitNodesList(); } //--------------------------------------------------------------------------------------------------------------------- @@ -239,6 +275,101 @@ void DialogPiecePath::NameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::NodeChanged(int index) +{ + ui->doubleSpinBoxSABefore->setDisabled(true); + ui->doubleSpinBoxSAAfter->setDisabled(true); + ui->pushButtonDefBefore->setDisabled(true); + ui->pushButtonDefAfter->setDisabled(true); + ui->comboBoxAngle->setDisabled(true); + + ui->doubleSpinBoxSABefore->blockSignals(true); + ui->doubleSpinBoxSAAfter->blockSignals(true); + ui->comboBoxAngle->blockSignals(true); + + if (index != -1) + { + #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); + #else + const quint32 id = ui->comboBoxNodes->currentData().toUInt(); + #endif + const VPiecePath path = CreatePath(); + const int nodeIndex = path.indexOfNode(id); + if (nodeIndex != -1) + { + const VPieceNode &node = path.at(nodeIndex); + + ui->doubleSpinBoxSABefore->setEnabled(true); + ui->doubleSpinBoxSAAfter->setEnabled(true); + ui->comboBoxAngle->setEnabled(true); + + qreal w1 = node.GetSABefore(); + if (w1 < 0) + { + w1 = m_saWidth; + } + else + { + ui->pushButtonDefBefore->setEnabled(true); + } + ui->doubleSpinBoxSABefore->setValue(w1); + + qreal w2 = node.GetSAAfter(); + if (w2 < 0) + { + w2 = m_saWidth; + } + else + { + ui->pushButtonDefAfter->setEnabled(true); + } + ui->doubleSpinBoxSAAfter->setValue(w2); + + const int index = ui->comboBoxAngle->findData(static_cast(node.GetAngleType())); + if (index != -1) + { + ui->comboBoxAngle->setCurrentIndex(index); + } + } + } + else + { + ui->doubleSpinBoxSABefore->setValue(0); + ui->doubleSpinBoxSAAfter->setValue(0); + ui->comboBoxAngle->setCurrentIndex(-1); + } + + ui->doubleSpinBoxSABefore->blockSignals(false); + ui->doubleSpinBoxSAAfter->blockSignals(false); + ui->comboBoxAngle->blockSignals(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::ReturnDefBefore() +{ + SetCurrentSABefore(-1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::ReturnDefAfter() +{ + SetCurrentSAAfter(-1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::ChangedSABefore(double d) +{ + SetCurrentSABefore(d); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::ChangedSAAfter(double d) +{ + SetCurrentSAAfter(d); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitPathTypes() { @@ -246,6 +377,74 @@ void DialogPiecePath::InitPathTypes() //ui->comboBoxType->addItem(tr("Internal path"), static_cast(PiecePathType::InternalPath)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::InitNodesList() +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt(); +#else + const quint32 id = ui->comboBoxNodes->currentData().toUInt(); +#endif + + ui->comboBoxNodes->blockSignals(true); + ui->comboBoxNodes->clear(); + + const VPiecePath path = CreatePath(); + + for (int i = 0; i < path.CountNodes(); ++i) + { + const VPieceNode node = path.at(i); + if (node.GetTypeTool() == Tool::NodePoint) + { + const QString name = GetNodeName(node); + + ui->comboBoxNodes->addItem(name, node.GetId()); + } + } + ui->comboBoxNodes->blockSignals(false); + + const int index = ui->comboBoxNodes->findData(id); + if (index != -1) + { + ui->comboBoxNodes->setCurrentIndex(index); + NodeChanged(index);// Need in case combox index was not changed + } + else + { + ui->comboBoxNodes->count() > 0 ? NodeChanged(0) : NodeChanged(-1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::NodeAngleChanged(int index) +{ + const int i = ui->comboBoxNodes->currentIndex(); + if (i != -1 && index != -1) + { + #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 id = ui->comboBoxNodes->itemData(i).toUInt(); + #else + const quint32 id = ui->comboBoxNodes->currentData().toUInt(); + #endif + + QListWidgetItem *rowItem = GetItemById(id); + if (rowItem) + { + #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->itemData(index).toUInt()); + #else + const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->currentData().toUInt()); + #endif + + VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + rowNode.SetAngleType(angle); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + + ListChanged(); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- VPiecePath DialogPiecePath::GetPiecePath() const { @@ -292,6 +491,70 @@ void DialogPiecePath::SetType(PiecePathType type) } } +//--------------------------------------------------------------------------------------------------------------------- +QListWidgetItem *DialogPiecePath::GetItemById(quint32 id) +{ + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem *item = ui->listWidget->item(i); + const VPieceNode node = qvariant_cast(item->data(Qt::UserRole)); + + if (node.GetId() == id) + { + return item; + } + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetCurrentSABefore(qreal value) +{ + const int index = ui->comboBoxNodes->currentIndex(); + if (index != -1) + { + #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); + #else + const quint32 id = ui->comboBoxNodes->currentData().toUInt(); + #endif + + QListWidgetItem *rowItem = GetItemById(id); + if (rowItem) + { + VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + rowNode.SetSABefore(value); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + + ListChanged(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetCurrentSAAfter(qreal value) +{ + const int index = ui->comboBoxNodes->currentIndex(); + if (index != -1) + { + #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + const quint32 id = ui->comboBoxNodes->itemData(index).toUInt(); + #else + const quint32 id = ui->comboBoxNodes->currentData().toUInt(); + #endif + + QListWidgetItem *rowItem = GetItemById(id); + if (rowItem) + { + VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + rowNode.SetSAAfter(value); + rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); + + ListChanged(); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 DialogPiecePath::GetPieceId() const { @@ -327,6 +590,20 @@ void DialogPiecePath::SetPieceId(quint32 id) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPiecePath::SetSAWidth(qreal width) +{ + if (width >=0) + { + m_saWidth = width; + ui->tabWidget->addTab(ui->tabSeamAllowance, QString()); + } + else + { + ui->tabWidget->removeTab(1); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::SetPiecesList(const QVector &list) { diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.h b/src/libs/vtools/dialogs/tools/dialogpiecepath.h index 4e1f79d00..6149853f9 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.h +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.h @@ -51,6 +51,8 @@ public: quint32 GetPieceId() const; void SetPieceId(quint32 id); + void SetSAWidth(qreal width); + virtual void SetPiecesList(const QVector &list) Q_DECL_OVERRIDE; public slots: @@ -66,14 +68,22 @@ private slots: void ShowContextMenu(const QPoint &pos); void ListChanged(); void NameChanged(); + void NodeChanged(int index); + void ReturnDefBefore(); + void ReturnDefAfter(); + void ChangedSABefore(double d); + void ChangedSAAfter(double d); private: Q_DISABLE_COPY(DialogPiecePath) Ui::DialogPiecePath *ui; bool m_showMode; + qreal m_saWidth; void InitPathTypes(); void InitListPieces(); + void InitNodesList(); + void NodeAngleChanged(int index); VPiecePath CreatePath() const; @@ -83,6 +93,11 @@ private: PiecePathType GetType() const; void SetType(PiecePathType type); + + QListWidgetItem *GetItemById(quint32 id); + + void SetCurrentSABefore(qreal value); + void SetCurrentSAAfter(qreal value); }; #endif // DIALOGPIECEPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui index 6ae015961..1041d3cc4 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.ui @@ -6,76 +6,265 @@ 0 0 - 365 - 337 + 480 + 409 Dialog - + - - - QFormLayout::ExpandingFieldsGrow - - - - - Name: - - - - - - - Unnamed path - - - Create name for your path - - - - - - - Type: - - - - - - - - - - Piece: - - - - - - - - - - - - QAbstractItemView::InternalMove - - - - - - - Ready! - - - Qt::RichText - - - false + + + 1 + + + Path + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Name: + + + + + + + Unnamed path + + + Create name for your path + + + + + + + Type: + + + + + + + + + + Piece: + + + + + + + + + + + + QAbstractItemView::InternalMove + + + + + + + Ready! + + + Qt::RichText + + + false + + + + + + + + Seam allowance + + + + + + + + + 0 + 0 + + + + + + + Width: + + + + + + + + 0 + 0 + + + + true + + + 900.990000000000009 + + + 0.100000000000000 + + + 0.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Nodes + + + + QFormLayout::ExpandingFieldsGrow + + + + + Node: + + + + + + + + + + Seam allowance before node + + + Before: + + + + + + + + + 900.990000000000009 + + + 0.100000000000000 + + + + + + + Return to default width + + + Default + + + + + + + + + Seam allowance after node + + + After: + + + + + + + + + 900.990000000000009 + + + 0.100000000000000 + + + + + + + Return to default width + + + Default + + + + + + + + + Angle: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 0b08a1595..5b07f2e24 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -91,7 +91,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & connect(ui->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); - InitNodeAngles(); + InitNodeAngles(ui->comboBoxAngle); connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, &DialogSeamAllowance::NodeAngleChanged); @@ -109,7 +109,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & vis = new VisToolPiece(data); } - ui->tabWidget->setCurrentIndex(1);// Show always first tab active on start. + ui->tabWidget->setCurrentIndex(0);// Show always first tab active on start. } //--------------------------------------------------------------------------------------------------------------------- @@ -770,24 +770,6 @@ void DialogSeamAllowance::InitNodesList() } } -//--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::InitNodeAngles() -{ - ui->comboBoxAngle->clear(); - - ui->comboBoxAngle->addItem(tr("by length"), static_cast(PieceNodeAngle::ByLength)); - ui->comboBoxAngle->addItem(tr("by points intersetions"), - static_cast(PieceNodeAngle::ByPointsIntersection)); - ui->comboBoxAngle->addItem(tr("by first edge symmetry"), - static_cast(PieceNodeAngle::ByFirstEdgeSymmetry)); - ui->comboBoxAngle->addItem(tr("by second edge symmetry"), - static_cast(PieceNodeAngle::BySecondEdgeSymmetry)); - ui->comboBoxAngle->addItem(tr("by first edge right angle"), - static_cast(PieceNodeAngle::ByFirstEdgeRightAngle)); - ui->comboBoxAngle->addItem(tr("by second edge right angle"), - static_cast(PieceNodeAngle::BySecondEdgeRightAngle)); -} - //--------------------------------------------------------------------------------------------------------------------- QListWidgetItem *DialogSeamAllowance::GetItemById(quint32 id) { diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index f90fa75df..4675c0939 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -94,7 +94,6 @@ private: void ValidObjects(bool value); bool MainPathIsClockwise() const; void InitNodesList(); - void InitNodeAngles(); void InitCSAPoint(QComboBox *box); QListWidgetItem *GetItemById(quint32 id); diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index e27204d0f..27f285d92 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -21,7 +21,7 @@ - 1 + 0 diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index a26626ce4..611218f6b 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -502,6 +502,20 @@ void DialogTool::NewNodeItem(QListWidget *listWidget, const VPieceNode &node) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::InitNodeAngles(QComboBox *box) +{ + SCASSERT(box != nullptr); + box->clear(); + + box->addItem(tr("by length"), static_cast(PieceNodeAngle::ByLength)); + box->addItem(tr("by points intersetions"), static_cast(PieceNodeAngle::ByPointsIntersection)); + box->addItem(tr("by first edge symmetry"), static_cast(PieceNodeAngle::ByFirstEdgeSymmetry)); + box->addItem(tr("by second edge symmetry"), static_cast(PieceNodeAngle::BySecondEdgeSymmetry)); + box->addItem(tr("by first edge right angle"), static_cast(PieceNodeAngle::ByFirstEdgeRightAngle)); + box->addItem(tr("by second edge right angle"), static_cast(PieceNodeAngle::BySecondEdgeRightAngle)); +} + //--------------------------------------------------------------------------------------------------------------------- bool DialogTool::IsSplinePath(const QSharedPointer &obj) const { diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 46ed7d9fa..5de089cf6 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -283,6 +283,8 @@ protected: QString GetNodeName(const VPieceNode &node) const; void NewNodeItem(QListWidget *listWidget, const VPieceNode &node); + + void InitNodeAngles(QComboBox *box); private: void FillList(QComboBox *box, const QMap &list)const;