From 1dd86e66fb66bf386046761b54212a6c95e8f59c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 4 Nov 2016 16:16:11 +0200 Subject: [PATCH] New dialog connected to tool button. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 12 +- src/libs/vtools/dialogs/dialogs.pri | 10 +- src/libs/vtools/dialogs/tooldialogs.h | 1 + src/libs/vtools/dialogs/tools/dialogdetail.ui | 30 +- .../dialogs/tools/dialogseamallowance.cpp | 290 ++++++++++++++++++ .../dialogs/tools/dialogseamallowance.h | 75 +++++ .../dialogs/tools/dialogseamallowance.ui | 130 ++++++++ 7 files changed, 520 insertions(+), 28 deletions(-) create mode 100644 src/libs/vtools/dialogs/tools/dialogseamallowance.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogseamallowance.h create mode 100644 src/libs/vtools/dialogs/tools/dialogseamallowance.ui diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 2f678b024..b7053c149 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -935,7 +935,7 @@ void MainWindow::ToolPointOfContact(bool checked) void MainWindow::ToolDetail(bool checked) { ToolSelectAllDrawObjects(); - SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", + SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } @@ -946,12 +946,12 @@ void MainWindow::ToolDetail(bool checked) */ void MainWindow::ClosedDialogDetail(int result) { - if (result == QDialog::Accepted) - { - VToolDetail::Create(dialogTool, sceneDetails, doc, pattern); - } +// if (result == QDialog::Accepted) +// { +// VToolDetail::Create(dialogTool, sceneDetails, doc, pattern); +// } ArrowTool(); - doc->LiteParseTree(Document::LiteParse); +// doc->LiteParseTree(Document::LiteParse); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 343b5a64c..3c1543155 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -41,8 +41,8 @@ HEADERS += \ $$PWD/tools/dialogrotation.h \ $$PWD/tools/dialogflippingbyline.h \ $$PWD/tools/dialogflippingbyaxis.h \ - $$PWD/tools/dialogmove.h - + $$PWD/tools/dialogmove.h \ + $$PWD/tools/dialogseamallowance.h SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -83,7 +83,8 @@ SOURCES += \ $$PWD/tools/dialogrotation.cpp \ $$PWD/tools/dialogflippingbyline.cpp \ $$PWD/tools/dialogflippingbyaxis.cpp \ - $$PWD/tools/dialogmove.cpp + $$PWD/tools/dialogmove.cpp \ + $$PWD/tools/dialogseamallowance.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ @@ -123,4 +124,5 @@ FORMS += \ $$PWD/tools/dialogrotation.ui \ $$PWD/tools/dialogflippingbyline.ui \ $$PWD/tools/dialogflippingbyaxis.ui \ - $$PWD/tools/dialogmove.ui + $$PWD/tools/dialogmove.ui \ + $$PWD/tools/dialogseamallowance.ui diff --git a/src/libs/vtools/dialogs/tooldialogs.h b/src/libs/vtools/dialogs/tooldialogs.h index 23f99447c..d7f859cc1 100644 --- a/src/libs/vtools/dialogs/tooldialogs.h +++ b/src/libs/vtools/dialogs/tooldialogs.h @@ -34,6 +34,7 @@ #include "tools/dialogarcwithlength.h" #include "tools/dialogbisector.h" #include "tools/dialogdetail.h" +#include "tools/dialogseamallowance.h" #include "tools/dialogendline.h" #include "tools/dialogline.h" #include "tools/dialoglineintersect.h" diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 7198fcea0..699792160 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -14,7 +14,7 @@ Seam allowance tool - + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png @@ -24,7 +24,7 @@ - 2 + 0 @@ -45,7 +45,7 @@ - :/icon/32x32/clockwise.png + :/icon/32x32/clockwise.png @@ -318,8 +318,7 @@ - - + .. @@ -333,8 +332,7 @@ - - + .. @@ -636,7 +634,7 @@ ... - + :/icon/24x24/fx.png:/icon/24x24/fx.png @@ -653,7 +651,7 @@ - :/icon/24x24/equal.png + :/icon/24x24/equal.png @@ -744,8 +742,7 @@ - - + .. @@ -842,7 +839,7 @@ ... - + :/icon/24x24/fx.png:/icon/24x24/fx.png @@ -859,7 +856,7 @@ - :/icon/24x24/equal.png + :/icon/24x24/equal.png @@ -950,8 +947,7 @@ - - + .. @@ -1082,9 +1078,7 @@ checkBoxPattern lineEditLetter - - - + buttonBox diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp new file mode 100644 index 000000000..d4f083ec0 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -0,0 +1,290 @@ +/************************************************************************ + ** + ** @file dialogseamallowance.cpp + ** @author Roman Telezhynskyi + ** @date 3 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 "dialogseamallowance.h" +#include "ui_dialogseamallowance.h" +#include "../vpatterndb/vpiecenode.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent) + : DialogTool(data, toolId, parent), + ui(new Ui::DialogSeamAllowance), + m_piece() +{ + ui->setupUi(this); + + InitOkCancelApply(ui); + + flagName = true;//We have default name of piece. + flagError = MainPathIsValid(); + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +DialogSeamAllowance::~DialogSeamAllowance() +{ + delete ui; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPiece DialogSeamAllowance::GetPiece() const +{ + return m_piece; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPiece(const VPiece &piece) +{ + m_piece = piece; + ui->listWidget->clear(); + for (int i = 0; i < m_piece.CountNode(); ++i) + { + NewItem(m_piece.at(i)); + } + + ValidObjects(MainPathIsValid()); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. + * @param id id of objects (points, arcs, splines, spline paths) + * @param type type of object + */ +void DialogSeamAllowance::ChosenObject(quint32 id, const SceneObject &type) +{ + bool reverse = false; + switch (type) + { + case SceneObject::Arc: + NewItem(VPieceNode(id, Tool::NodeArc, reverse)); + break; + case SceneObject::Point: + NewItem(VPieceNode(id, Tool::NodePoint, reverse)); + break; + case SceneObject::Spline: + NewItem(VPieceNode(id, Tool::NodeSpline, reverse)); + break; + case SceneObject::SplinePath: + NewItem(VPieceNode(id, Tool::NodeSplinePath, reverse)); + break; + case (SceneObject::Line): + case (SceneObject::Detail): + case (SceneObject::Unknown): + default: + qDebug() << "Got wrong scene object. Ignore."; + break; + } + + ValidObjects(MainPathIsValid()); + show(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SaveData() +{ + m_piece.Clear(); + m_piece = CreatePiece(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::CheckState() +{ + SCASSERT(bOk != nullptr); + bOk->setEnabled(flagName && flagError); + // In case dialog hasn't apply button + if ( bApply != nullptr) + { + bApply->setEnabled(bOk->isEnabled()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VPiece DialogSeamAllowance::CreatePiece() const +{ + VPiece piece; + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem *item = ui->listWidget->item(i); + piece.Append(qvariant_cast(item->data(Qt::UserRole))); + } + + return piece; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::NewItem(const VPieceNode &node) +{ + SCASSERT(node.GetId() > NULL_ID); + QString name; + switch (node.GetTypeTool()) + { + case (Tool::NodePoint): + case (Tool::NodeArc): + case (Tool::NodeSpline): + case (Tool::NodeSplinePath): + { + const QSharedPointer obj = data->GeometricObject(node.GetId()); + name = obj->name(); + break; + } + default: + qDebug()<<"Got wrong tools. Ignore."; + return; + } + + if (node.GetReverse()) + { + name = QLatin1String("- ") + name; + } + + bool canAddNewPoint = false; + + if(ui->listWidget->count() == 0) + { + canAddNewPoint = true; + } + else + { + if(RowId(ui->listWidget->count()-1) != node.GetId()) + { + canAddNewPoint = true; + } + } + + if(canAddNewPoint) + { + QListWidgetItem *item = new QListWidgetItem(name); + item->setFont(QFont("Times", 12, QFont::Bold)); + item->setData(Qt::UserRole, QVariant::fromValue(node)); + ui->listWidget->addItem(item); + ui->listWidget->setCurrentRow(ui->listWidget->count()-1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 DialogSeamAllowance::RowId(int i) const +{ + const QListWidgetItem *rowItem = ui->listWidget->item(i); + SCASSERT(rowItem != nullptr); + const VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); + return rowNode.GetId(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSeamAllowance::MainPathIsValid() const +{ + const QIcon icon = QIcon::fromTheme("dialog-warning", + QIcon(":/icons/win.icon.theme/16x16/status/dialog-warning.png")); + + const QPixmap pixmap = icon.pixmap(QSize(16, 16)); + QByteArray byteArray; + QBuffer buffer(&byteArray); + pixmap.save(&buffer, "PNG"); + QString url = QString(" "); + + if(CreatePiece().MainPathPoints(data).count() < 3) + { + url += tr("You need more points!"); + ui->helpLabel->setText(url); + return false; + } + else + { + if(not MainPathIsClockwise()) + { + url += tr("You have to choose points in a clockwise direction!"); + ui->helpLabel->setText(url); + return false; + } + if (FirstPointEqualLast()) + { + url += tr("First point cannot be equal to the last point!"); + ui->helpLabel->setText(url); + return false; + } + else + { + for (int i=0, sz = ui->listWidget->count()-1; ihelpLabel->setText(url); + return false; + } + } + } + } + ui->helpLabel->setText(tr("Ready!")); + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ValidObjects(bool value) +{ + flagError = value; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSeamAllowance::FirstPointEqualLast() const +{ + if (ui->listWidget->count() > 1) + { + if (RowId(0) == RowId(ui->listWidget->count()-1)) + { + return true; + } + else + { + return false; + } + } + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSeamAllowance::MainPathIsClockwise() const +{ + const QVector points = CreatePiece().MainPathPoints(data); + + if(points.count() < 3) + { + return false; + } + + const qreal res = VPiece::SumTrapezoids(points); + if (res < 0) + { + return true; + } + return false; +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h new file mode 100644 index 000000000..478d98548 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -0,0 +1,75 @@ +/************************************************************************ + ** + ** @file dialogseamallowance.h + ** @author Roman Telezhynskyi + ** @date 3 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 DIALOGSEAMALLOWANCE_H +#define DIALOGSEAMALLOWANCE_H + +#include "dialogtool.h" +#include "../vpatterndb/vpiece.h" + +namespace Ui +{ + class DialogSeamAllowance; +} + +class DialogSeamAllowance : public DialogTool +{ + Q_OBJECT + +public: + DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr); + virtual ~DialogSeamAllowance(); + + VPiece GetPiece() const; + void SetPiece(const VPiece &m_piece); + +public slots: + virtual void ChosenObject(quint32 id, const SceneObject &type) Q_DECL_OVERRIDE; + +protected: + /** @brief SaveData Put dialog data in local variables */ + virtual void SaveData() Q_DECL_OVERRIDE; + virtual void CheckState() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(DialogSeamAllowance) + + Ui::DialogSeamAllowance *ui; + VPiece m_piece; + + VPiece CreatePiece() const; + + void NewItem(const VPieceNode &node); + quint32 RowId(int i) const; + bool MainPathIsValid() const; + void ValidObjects(bool value); + bool FirstPointEqualLast() const; + bool MainPathIsClockwise() const; +}; + +#endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui new file mode 100644 index 000000000..810e28537 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -0,0 +1,130 @@ + + + DialogSeamAllowance + + + + 0 + 0 + 559 + 423 + + + + Dialog + + + + :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png + + + + + + 0 + + + + Main path + + + + + + + + + 0 + 0 + + + + + + + :/icon/32x32/clockwise.png + + + + + + + All objects in path should follow in clockwise direction. + + + true + + + + + + + + + + + + Ready! + + + Qt::RichText + + + false + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + DialogSeamAllowance + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogSeamAllowance + reject() + + + 316 + 260 + + + 286 + 274 + + + + +