From 297b73a951e138192709c383f09233b9c48e1eb5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 12 Jan 2017 19:09:00 +0200 Subject: [PATCH] VToolSeamAllowance add grainline and labels. Only the dialog. --HG-- branch : feature --- .../dialogs/tools/dialogseamallowance.cpp | 599 ++++++++++++++-- .../dialogs/tools/dialogseamallowance.h | 45 +- .../dialogs/tools/dialogseamallowance.ui | 637 +++++++++++++++++- 3 files changed, 1218 insertions(+), 63 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 8dea602d6..8738ac42d 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -30,86 +30,48 @@ #include "ui_dialogseamallowance.h" #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" +#include "../vpatterndb/calculator.h" #include "visualization/path/vistoolpiece.h" #include "dialogpiecepath.h" #include "../../undocommands/savepiecepathoptions.h" +#include "../support/dialogeditwrongformula.h" #include +#include //--------------------------------------------------------------------------------------------------------------------- DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogSeamAllowance), applyAllowed(false),// By default disabled + m_bAddMode(true), m_mx(0), m_my(0), - m_dialog() + m_dialog(), + m_qslMaterials(), + m_qslPlacements(), + m_conMCP(), + m_oldData(), + m_oldGeom(), + m_oldGrainline(), + m_iRotBaseHeight(0), + m_iLenBaseHeight(0) { ui->setupUi(this); InitOkCancelApply(ui); EnableApply(applyAllowed); + InitMainPathTab(); + InitSeamAllowanceTab(); + InitInternalPathsTab(); + InitPatternPieceDataTab(); + InitGrainlineTab(); + flagName = true;//We have default name of piece. flagError = MainPathIsValid(); CheckState(); - ui->checkBoxForbidFlipping->setChecked(qApp->Settings()->GetForbidWorkpieceFlipping()); - - 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); - } - // Default value for seam allowence is 1 cm. But pattern have different units, so just set 1 in dialog not enough. - ui->doubleSpinBoxSeams->setValue(UnitConvertor(1, Unit::Cm, qApp->patternUnit())); - - InitNodesList(); - connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, - &DialogSeamAllowance::NodeChanged); - - connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefBefore); - connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefAfter); - - connect(ui->doubleSpinBoxSeams, static_cast(&QDoubleSpinBox::valueChanged), - [this](){NodeChanged(ui->comboBoxNodes->currentIndex());}); - - connect(ui->doubleSpinBoxSABefore, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSeamAllowance::ChangedSABefore); - connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSeamAllowance::ChangedSAAfter); - - ui->listWidgetMainPath->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->listWidgetMainPath, &QListWidget::customContextMenuRequested, this, - &DialogSeamAllowance::ShowMainPathContextMenu); - connect(ui->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); - connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); - - InitNodeAngles(ui->comboBoxAngle); - connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, - &DialogSeamAllowance::NodeAngleChanged); - - ui->listWidgetCustomSA->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->listWidgetCustomSA, &QListWidget::customContextMenuRequested, this, - &DialogSeamAllowance::ShowCustomSAContextMenu); - connect(ui->listWidgetCustomSA, &QListWidget::currentRowChanged, this, &DialogSeamAllowance::CustomSAChanged); - connect(ui->comboBoxStartPoint, static_cast(&QComboBox::currentIndexChanged), this, - &DialogSeamAllowance::CSAStartPointChanged); - connect(ui->comboBoxEndPoint, static_cast(&QComboBox::currentIndexChanged), this, - &DialogSeamAllowance::CSAEndPointChanged); - connect(ui->comboBoxIncludeType, static_cast(&QComboBox::currentIndexChanged), this, - &DialogSeamAllowance::CSAIncludeTypeChanged); - - ui->listWidgetInternalPaths->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->listWidgetInternalPaths, &QListWidget::customContextMenuRequested, this, - &DialogSeamAllowance::ShowInternalPathsContextMenu); - if (not applyAllowed) { vis = new VisToolPiece(data); @@ -132,6 +94,8 @@ void DialogSeamAllowance::EnableApply(bool enable) applyAllowed = enable; ui->tabSeamAllowance->setEnabled(applyAllowed); ui->tabInternalPaths->setEnabled(applyAllowed); + ui->tabPatternPieceData->setEnabled(applyAllowed); + ui->tabGrainline->setEnabled(applyAllowed); } //--------------------------------------------------------------------------------------------------------------------- @@ -178,11 +142,34 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ui->checkBoxForbidFlipping->setChecked(piece.IsForbidFlipping()); ui->doubleSpinBoxSeams->setValue(piece.GetSAWidth()); ui->checkBoxSeams->setChecked(piece.IsSeamAllowance()); + ui->lineEditName->setText(piece.GetName()); m_mx = piece.GetMx(); m_my = piece.GetMy(); + ui->lineEditLetter->setText(piece.GetPatternPieceData().GetLetter()); + ui->checkBoxDetail->setChecked(piece.GetPatternPieceData().IsVisible()); + ui->checkBoxPattern->setChecked(piece.GetPatternInfo().IsVisible()); + + m_conMCP.clear(); + for (int i = 0; i < piece.GetPatternPieceData().GetMCPCount(); ++i) + { + m_conMCP << piece.GetPatternPieceData().GetMCP(i); + } + + UpdateList(); + + ui->checkBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); + ui->lineEditRotFormula->setPlainText(piece.GetGrainlineGeometry().GetRotation()); + ui->lineEditLenFormula->setPlainText(piece.GetGrainlineGeometry().GetLength()); + ui->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); + + m_oldData = piece.GetPatternPieceData(); + m_oldGeom = piece.GetPatternInfo(); + m_oldGrainline = piece.GetGrainlineGeometry(); + ValidObjects(MainPathIsValid()); + EnableGrainlineRotation(); ListChanged(); } @@ -303,6 +290,140 @@ void DialogSeamAllowance::CheckState() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateList() +{ + ui->listWidgetMCP->clear(); + for (int i = 0; i < m_conMCP.count(); ++i) + { + MaterialCutPlacement mcp = m_conMCP.at(i); + QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); + if (mcp.m_eMaterial < MaterialType::mtUserDefined) + { + qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); + } + else + { + qsText = qsText.arg(mcp.m_qsMaterialUserDef); + } + if (mcp.m_ePlacement == PlacementType::ptCutOnFold) + { + qsText = qsText.arg(QLatin1String(" ") + tr("on Fold")); + } + else + { + qsText = qsText.arg(""); + } + + ui->listWidgetMCP->addItem(qsText); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::AddUpdate() +{ + MaterialCutPlacement mcp; + QStringList qslUserMaterials = qApp->Settings()->GetUserDefinedMaterials(); + +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + int i = ui->comboBoxMaterial->itemData(ui->comboBoxMaterial->currentIndex()).toInt(); +#else + int i = ui->comboBoxMaterial->currentData().toInt(); +#endif + QString qsMat = ui->comboBoxMaterial->currentText(); + if (i < m_qslMaterials.count() && qsMat == m_qslMaterials[i]) + { + mcp.m_eMaterial = MaterialType(i); + mcp.m_qsMaterialUserDef.clear(); + } + else + { + mcp.m_eMaterial = MaterialType::mtUserDefined; + mcp.m_qsMaterialUserDef = qsMat; + // check if we have new user defined material + bool bFound = false; + for (int i = 0; i < qslUserMaterials.count() && bFound == false; ++i) + { + if (mcp.m_qsMaterialUserDef == qslUserMaterials[i]) + { + bFound = true; + } + } + if (bFound == false) + { + qApp->Settings()->AddUserDefinedMaterial(mcp.m_qsMaterialUserDef); + qApp->Settings()->sync(); + ui->comboBoxMaterial->addItem(mcp.m_qsMaterialUserDef, int(MaterialType::mtUserDefined)); + } + } + + mcp.m_iCutNumber = ui->spinBoxCutNumber->value(); + mcp.m_ePlacement = PlacementType(ui->comboBoxPlacement->currentIndex()); + + if (m_bAddMode == true) + { + m_conMCP << mcp; + } + else + { + int iR = ui->listWidgetMCP->currentRow(); + SCASSERT(iR >= 0) + m_conMCP[iR] = mcp; + SetAddMode(); + } + UpdateList(); + ClearFields(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::Cancel() +{ + ClearFields(); + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::Remove() +{ + int iR = ui->listWidgetMCP->currentRow(); + SCASSERT(iR >= 0) + m_conMCP.removeAt(iR); + UpdateList(); + ClearFields(); + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::NameDetailChanged() +{ + SCASSERT(labelEditNamePoint != nullptr) + QLineEdit* edit = qobject_cast(sender()); + if (edit) + { + if (edit->text().isEmpty()) + { + flagName = false; + ChangeColor(labelEditNamePoint, Qt::red); + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(1, icon); + } + else + { + flagName = true; + ChangeColor(labelEditNamePoint, okColor); + QIcon icon; + ui->tabWidget->setTabIcon(1, icon); + } + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::MaterialChanged() +{ + ui->pushButtonAdd->setEnabled(ui->comboBoxMaterial->currentText().isEmpty() == false); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::ShowMainPathContextMenu(const QPoint &pos) { @@ -738,6 +859,208 @@ void DialogSeamAllowance::PathDialogClosed(int result) delete m_dialog; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateValues() +{ + QPlainTextEdit* apleSender[2]; + apleSender[0] = ui->lineEditRotFormula; + apleSender[1] = ui->lineEditLenFormula; + bool bFormulasOK = true; + + for (int i = 0; i < 2; ++i) + { + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) + { + plbVal = ui->labelRot; + plbText = ui->labelEditRot; + QChar ch(0x00b0); + qsUnit = ch; + } + else + { + plbVal = ui->labelLen; + plbText = ui->labelEditLen; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + + plbVal->setToolTip(tr("Value")); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + Calculator cal; + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + qreal dVal; + dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if (i == 1 && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (qmu::QmuParserError &e) + { + qsVal.clear(); + ChangeColor(plbText, Qt::red); + bFormulasOK = false; + plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); + } + + bOk->setEnabled(bFormulasOK); + if (bFormulasOK == false) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); + } + else + { + ResetWarning(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetAddMode() +{ + ui->pushButtonAdd->setText(tr("Add")); + ui->pushButtonCancel->hide(); + ui->pushButtonRemove->hide(); + ui->listWidgetMCP->setCurrentRow(-1); + m_bAddMode = true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetEditMode() +{ + int iR = ui->listWidgetMCP->currentRow(); + // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! + if (iR < 0 || iR >= m_conMCP.count()) + { + return; + } + + ui->pushButtonAdd->setText(tr("Update")); + ui->pushButtonCancel->show(); + ui->pushButtonRemove->show(); + + MaterialCutPlacement mcp = m_conMCP.at(iR); + if (mcp.m_eMaterial == MaterialType::mtUserDefined) + { + int iRow = qApp->Settings()->GetUserDefinedMaterials().indexOf(mcp.m_qsMaterialUserDef); + if (iRow >= 0) + { + ui->comboBoxMaterial->setCurrentIndex(iRow + m_qslMaterials.count()); + } + else + { + ui->comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); + } + } + else + { + ui->comboBoxMaterial->setCurrentIndex(int(mcp.m_eMaterial)); + } + ui->spinBoxCutNumber->setValue(mcp.m_iCutNumber); + ui->comboBoxPlacement->setCurrentIndex(int(mcp.m_ePlacement)); + + m_bAddMode = false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnableGrainlineRotation() +{ + ui->lineEditRotFormula->setEnabled(ui->checkBoxGrainline->isChecked()); + ui->lineEditLenFormula->setEnabled(ui->checkBoxGrainline->isChecked()); + ui->pushButtonRot->setEnabled(ui->checkBoxGrainline->isChecked()); + ui->pushButtonLen->setEnabled(ui->checkBoxGrainline->isChecked()); + ui->pushButtonShowLen->setEnabled(ui->checkBoxGrainline->isChecked()); + ui->pushButtonShowRot->setEnabled(ui->checkBoxGrainline->isChecked()); + + if (ui->checkBoxGrainline->isChecked() == true) + { + UpdateValues(); + } + else + { + ChangeColor(ui->labelEditLen, okColor); + ChangeColor(ui->labelEditRot, okColor); + bOk->setEnabled(true); + ResetWarning(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditFormula() +{ + QPlainTextEdit* pleFormula; + bool bCheckZero; + + if (sender() == ui->pushButtonLen) + { + pleFormula = ui->lineEditLenFormula; + bCheckZero = true; + } + else if (sender() == ui->pushButtonRot) + { + pleFormula = ui->lineEditRotFormula; + bCheckZero = false; + } + else + { + // should not get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.SetFormula(pleFormula->toPlainText()); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == QDialog::Accepted) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + pleFormula->setPlainText(qsFormula); + UpdateValues(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployRotation() +{ + DeployFormula(ui->lineEditRotFormula, ui->pushButtonShowRot, m_iRotBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployLength() +{ + DeployFormula(ui->lineEditLenFormula, ui->pushButtonShowLen, m_iLenBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ResetWarning() +{ + QIcon icon; + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); +} + //--------------------------------------------------------------------------------------------------------------------- VPiece DialogSeamAllowance::CreatePiece() const { @@ -767,9 +1090,33 @@ VPiece DialogSeamAllowance::CreatePiece() const piece.SetForbidFlipping(ui->checkBoxForbidFlipping->isChecked()); piece.SetSeamAllowance(ui->checkBoxSeams->isChecked()); piece.SetSAWidth(ui->doubleSpinBoxSeams->value()); + piece.SetName(ui->lineEditName->text()); piece.SetMx(m_mx); piece.SetMy(m_my); + piece.GetPatternPieceData().SetLetter(ui->lineEditLetter->text()); + + for (int i = 0; i < m_conMCP.count(); ++i) + { + piece.GetPatternPieceData().Append(m_conMCP[i]); + } + + piece.GetPatternPieceData().SetPos(m_oldData.GetPos()); + piece.GetPatternPieceData().SetLabelWidth(m_oldData.GetLabelWidth()); + piece.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); + piece.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); + piece.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); + piece.GetPatternPieceData().SetVisible(ui->checkBoxDetail->isChecked()); + + piece.GetPatternInfo() = m_oldGeom; + piece.GetPatternInfo().SetVisible(ui->checkBoxPattern->isChecked()); + + piece.GetGrainlineGeometry() = m_oldGrainline; + piece.GetGrainlineGeometry().SetVisible(ui->checkBoxGrainline->isChecked()); + piece.GetGrainlineGeometry().SetRotation(ui->lineEditRotFormula->toPlainText()); + piece.GetGrainlineGeometry().SetLength(ui->lineEditLenFormula->toPlainText()); + piece.GetGrainlineGeometry().SetArrowType(VGrainlineGeometry::ArrowType(ui->comboBoxArrow->currentIndex())); + return piece; } @@ -1006,6 +1353,67 @@ void DialogSeamAllowance::SetCurrentSAAfter(qreal value) } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitMainPathTab() +{ + ui->checkBoxForbidFlipping->setChecked(qApp->Settings()->GetForbidWorkpieceFlipping()); + + ui->listWidgetMainPath->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetMainPath, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowMainPathContextMenu); + connect(ui->listWidgetMainPath->model(), &QAbstractItemModel::rowsMoved, this, &DialogSeamAllowance::ListChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitSeamAllowanceTab() +{ + connect(ui->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance); + + 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); + } + // Default value for seam allowence is 1 cm. But pattern have different units, so just set 1 in dialog not enough. + ui->doubleSpinBoxSeams->setValue(UnitConvertor(1, Unit::Cm, qApp->patternUnit())); + + InitNodesList(); + connect(ui->comboBoxNodes, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::NodeChanged); + + connect(ui->pushButtonDefBefore, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefBefore); + connect(ui->pushButtonDefAfter, &QPushButton::clicked, this, &DialogSeamAllowance::ReturnDefAfter); + + connect(ui->doubleSpinBoxSeams, static_cast(&QDoubleSpinBox::valueChanged), + [this](){NodeChanged(ui->comboBoxNodes->currentIndex());}); + + connect(ui->doubleSpinBoxSABefore, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSeamAllowance::ChangedSABefore); + connect(ui->doubleSpinBoxSAAfter, static_cast(&QDoubleSpinBox::valueChanged), + this, &DialogSeamAllowance::ChangedSAAfter); + + InitNodeAngles(ui->comboBoxAngle); + connect(ui->comboBoxAngle, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::NodeAngleChanged); + + ui->listWidgetCustomSA->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetCustomSA, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowCustomSAContextMenu); + connect(ui->listWidgetCustomSA, &QListWidget::currentRowChanged, this, &DialogSeamAllowance::CustomSAChanged); + connect(ui->comboBoxStartPoint, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::CSAStartPointChanged); + connect(ui->comboBoxEndPoint, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::CSAEndPointChanged); + connect(ui->comboBoxIncludeType, static_cast(&QComboBox::currentIndexChanged), this, + &DialogSeamAllowance::CSAIncludeTypeChanged); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitCSAPoint(QComboBox *box) { @@ -1036,6 +1444,75 @@ void DialogSeamAllowance::InitSAIncludeType() static_cast(PiecePathIncludeType::AsCustomSA)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitInternalPathsTab() +{ + ui->listWidgetInternalPaths->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listWidgetInternalPaths, &QListWidget::customContextMenuRequested, this, + &DialogSeamAllowance::ShowInternalPathsContextMenu); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitPatternPieceDataTab() +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + ui->lineEditName->setClearButtonEnabled(true); + ui->lineEditLetter->setClearButtonEnabled(true); +#endif + + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSeamAllowance::NameDetailChanged); + + m_qslMaterials << QApplication::translate("Detail", "Fabric", 0) + << QApplication::translate("Detail", "Lining", 0) + << QApplication::translate("Detail", "Interfacing", 0) + << QApplication::translate("Detail", "Interlining", 0); + + for (int i = 0; i < m_qslMaterials.count(); ++i) + { + ui->comboBoxMaterial->addItem(m_qslMaterials[i], i); + } + + const QStringList qsl = qApp->Settings()->GetUserDefinedMaterials(); + for (int i = 0; i < qsl.count(); ++i) + { + ui->comboBoxMaterial->addItem(qsl.at(i), int(MaterialType::mtUserDefined)); + } + + m_qslPlacements << tr("None") << tr("Cut on fold"); + ui->comboBoxPlacement->addItems(m_qslPlacements); + ui->pushButtonRot->setIcon(QIcon("://icon/16x16/fx.png")); + ui->pushButtonLen->setIcon(QIcon("://icon/16x16/fx.png")); + + connect(ui->pushButtonAdd, &QPushButton::clicked, this, &DialogSeamAllowance::AddUpdate); + connect(ui->pushButtonCancel, &QPushButton::clicked, this, &DialogSeamAllowance::Cancel); + connect(ui->pushButtonRemove, &QPushButton::clicked, this, &DialogSeamAllowance::Remove); + connect(ui->listWidgetMCP, &QListWidget::itemClicked, this, &DialogSeamAllowance::SetEditMode); + connect(ui->comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogSeamAllowance::MaterialChanged); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitGrainlineTab() +{ + connect(ui->checkBoxGrainline, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableGrainlineRotation); + connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); + connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); + connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); + connect(ui->lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); + + connect(ui->pushButtonShowRot, &QPushButton::clicked, this, &DialogSeamAllowance::DeployRotation); + connect(ui->pushButtonShowLen, &QPushButton::clicked, this, &DialogSeamAllowance::DeployLength); + + SetAddMode(); + EnableGrainlineRotation(); + + ui->comboBoxArrow->addItem(tr("Both")); + ui->comboBoxArrow->addItem(tr("Just front")); + ui->comboBoxArrow->addItem(tr("Just rear")); + + m_iRotBaseHeight = ui->lineEditRotFormula->height(); + m_iLenBaseHeight = ui->lineEditLenFormula->height(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::UpdateCurrentCustomSARecord() { @@ -1065,3 +1542,11 @@ void DialogSeamAllowance::UpdateCurrentInternalPathRecord() const quint32 path = qvariant_cast(item->data(Qt::UserRole)); item->setText(GetPathName(path)); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ClearFields() +{ + ui->comboBoxMaterial->setCurrentIndex(0); + ui->spinBoxCutNumber->setValue(0); + ui->comboBoxPlacement->setCurrentIndex(0); +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 2890ea3f4..4e7f659a8 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -31,6 +31,9 @@ #include "dialogtool.h" #include "../vpatterndb/vpiece.h" +#include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vgrainlinegeometry.h" namespace Ui { @@ -59,7 +62,15 @@ protected: virtual void SaveData() Q_DECL_OVERRIDE; virtual void CheckState() Q_DECL_OVERRIDE; +protected slots: + void UpdateList(); + void AddUpdate(); + void Cancel(); + void Remove(); + private slots: + void NameDetailChanged(); + void MaterialChanged(); void ShowMainPathContextMenu(const QPoint &pos); void ShowCustomSAContextMenu(const QPoint &pos); void ShowInternalPathsContextMenu(const QPoint &pos); @@ -78,16 +89,37 @@ private slots: void CustomSAChanged(int row); void PathDialogClosed(int result); + void UpdateValues(); + void SetAddMode(); + void SetEditMode(); + void EnableGrainlineRotation(); + void EditFormula(); + void DeployRotation(); + void DeployLength(); + void ResetWarning(); + private: Q_DISABLE_COPY(DialogSeamAllowance) Ui::DialogSeamAllowance *ui; bool applyAllowed; + bool m_bAddMode; qreal m_mx; qreal m_my; QPointer m_dialog; + QStringList m_qslMaterials; + QStringList m_qslPlacements; + // temporary container for Material/Cut/Placement 3-tuples + MCPContainer m_conMCP; + + VPatternPieceData m_oldData; + VPatternInfoGeometry m_oldGeom; + VGrainlineGeometry m_oldGrainline; + int m_iRotBaseHeight; + int m_iLenBaseHeight; + VPiece CreatePiece() const; void NewMainPathItem(const VPieceNode &node); @@ -97,11 +129,9 @@ private: bool MainPathIsValid() const; void ValidObjects(bool value); bool MainPathIsClockwise() const; - void InitNodesList(); - void InitCSAPoint(QComboBox *box); - void InitSAIncludeType(); void UpdateCurrentCustomSARecord(); void UpdateCurrentInternalPathRecord(); + void ClearFields(); QListWidgetItem *GetItemById(quint32 id); @@ -109,6 +139,15 @@ private: void SetCurrentSABefore(qreal value); void SetCurrentSAAfter(qreal value); + + void InitMainPathTab(); + void InitSeamAllowanceTab(); + void InitNodesList(); + void InitCSAPoint(QComboBox *box); + void InitSAIncludeType(); + void InitInternalPathsTab(); + void InitPatternPieceDataTab(); + void InitGrainlineTab(); }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index 75ff3623e..ff18f4b2d 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -6,8 +6,8 @@ 0 0 - 476 - 504 + 521 + 493 @@ -21,7 +21,7 @@ - 0 + 4 @@ -399,6 +399,637 @@ + + + Pattern piece data + + + + + + Qt::Horizontal + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Letter: + + + + + + + 3 + + + Letter of pattern piece + + + + + + + Name of detail: + + + + + + + Detail + + + 30 + + + Name can't be empty + + + + + + + + + Material/Cut number/Placement + + + + + + Cut number: + + + + + + + Material type: + + + + + + + You can choose one of the predefined materials or enter a new one + + + true + + + + + + + 1 + + + 1000 + + + + + + + Placement: + + + + + + + + + + Add + + + + + + + Cancel + + + + + + + Remove + + + + + + + + + + + + Detail label visible + + + + + + + Pattern label visible + + + + + + + + + + + 180 + 0 + + + + Qt::ClickFocus + + + + + + + + + Grainline + + + + + + + + Grainline visible + + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Rotation: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + 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 + + + + + + + + Length: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Arrows: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + +