2014-01-08 15:05:32 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogcutarc.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-01-08 15:05:32 +01:00
|
|
|
** @date 7 1, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-01-08 15:05:32 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "dialogcutarc.h"
|
|
|
|
#include "ui_dialogcutarc.h"
|
|
|
|
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../../libs/vgeometry/varc.h"
|
2015-06-12 10:55:44 +02:00
|
|
|
#include "../../libs/vpatterndb/vcontainer.h"
|
2014-08-15 16:37:22 +02:00
|
|
|
#include "../../visualization/vistoolcutarc.h"
|
|
|
|
#include "../../widgets/vmaingraphicsscene.h"
|
2014-09-05 10:01:46 +02:00
|
|
|
#include "../../xml/vpattern.h"
|
2015-04-29 19:50:15 +02:00
|
|
|
#include "dialogeditwrongformula.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogCutArc create dialog.
|
|
|
|
* @param data container with data
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2014-07-29 14:19:11 +02:00
|
|
|
DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
2015-05-21 21:24:31 +02:00
|
|
|
: DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()), formulaBaseHeight(0)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-06-19 13:43:02 +02:00
|
|
|
InitFormulaUI(ui);
|
2014-09-05 10:01:46 +02:00
|
|
|
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
|
2014-01-08 15:05:32 +01:00
|
|
|
labelEditNamePoint = ui->labelEditNamePoint;
|
2014-06-19 14:01:38 +02:00
|
|
|
this->formulaBaseHeight = ui->plainTextEditFormula->height();
|
2014-10-29 19:00:38 +01:00
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
2014-03-06 14:28:46 +01:00
|
|
|
|
2014-05-30 21:03:17 +02:00
|
|
|
InitOkCancelApply(ui);
|
2014-01-08 15:05:32 +01:00
|
|
|
flagFormula = false;
|
|
|
|
CheckState();
|
|
|
|
|
|
|
|
FillComboBoxArcs(ui->comboBoxArc);
|
2015-02-08 11:23:26 +01:00
|
|
|
FillComboBoxLineColors(ui->comboBoxColor);
|
2014-01-08 15:05:32 +01:00
|
|
|
|
2015-04-29 19:50:15 +02:00
|
|
|
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutArc::FXLength);
|
2014-01-08 15:05:32 +01:00
|
|
|
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged);
|
2014-06-09 18:37:11 +02:00
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutArc::FormulaTextChanged);
|
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit);
|
2014-08-15 16:37:22 +02:00
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
vis = new VisToolCutArc(data);
|
2014-06-09 18:37:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::FormulaTextChanged()
|
|
|
|
{
|
|
|
|
this->FormulaChangedPlainText();
|
|
|
|
}
|
|
|
|
|
2015-04-29 19:50:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::FXLength()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit length"));
|
|
|
|
dialog->SetFormula(GetFormula());
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetFormula(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:37:22 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::ShowVisualization()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
AddVisualization<VisToolCutArc>();
|
2014-08-15 16:37:22 +02:00
|
|
|
}
|
|
|
|
|
2014-06-09 18:37:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::DeployFormulaTextEdit()
|
|
|
|
{
|
2014-06-19 11:29:56 +02:00
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-08 15:05:32 +01:00
|
|
|
DialogCutArc::~DialogCutArc()
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
DeleteVisualization<VisToolCutArc>();
|
2014-01-08 15:05:32 +01:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
|
|
|
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
|
|
|
|
* @param id id of point or detail
|
|
|
|
* @param type type of object
|
|
|
|
*/
|
2014-07-15 16:42:41 +02:00
|
|
|
void DialogCutArc::ChosenObject(quint32 id, const SceneObject &type)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (prepare == false)// After first choose we ignore all objects
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2014-08-17 20:49:29 +02:00
|
|
|
if (type == SceneObject::Arc)
|
|
|
|
{
|
|
|
|
if (SetObject(id, ui->comboBoxArc, ""))
|
|
|
|
{
|
2015-05-21 21:24:31 +02:00
|
|
|
vis->VisualMode(id);
|
2014-08-17 20:49:29 +02:00
|
|
|
prepare = true;
|
|
|
|
this->setModal(true);
|
|
|
|
this->show();
|
|
|
|
}
|
|
|
|
}
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-09 18:37:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::SaveData()
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
pointName = ui->lineEditNamePoint->text();
|
2014-06-09 18:37:11 +02:00
|
|
|
formula = ui->plainTextEditFormula->toPlainText();
|
2014-06-16 19:18:36 +02:00
|
|
|
formula.replace("\n", " ");
|
2014-08-15 16:37:22 +02:00
|
|
|
|
2015-05-21 21:24:31 +02:00
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
|
|
|
SCASSERT(path != nullptr);
|
|
|
|
|
2015-02-03 09:17:59 +01:00
|
|
|
path->setPoint1Id(getArcId());
|
2014-08-15 16:37:22 +02:00
|
|
|
path->setLength(formula);
|
|
|
|
path->RefreshGeometry();
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-11-22 19:37:59 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
|
|
|
* @brief setArcId set id of arc
|
|
|
|
* @param value id
|
|
|
|
*/
|
2014-07-29 15:08:38 +02:00
|
|
|
void DialogCutArc::setArcId(const quint32 &value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
setCurrentArcId(ui->comboBoxArc, value, ComboBoxCutArc::CutArc);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
|
|
|
SCASSERT(path != nullptr);
|
2015-02-03 09:17:59 +01:00
|
|
|
path->setPoint1Id(value);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2015-02-08 11:23:26 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogCutArc::GetColor() const
|
|
|
|
{
|
|
|
|
return GetComboBoxCurrentData(ui->comboBoxColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogCutArc::SetColor(const QString &value)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxColor, value);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetFormula set string with formula length
|
2014-05-30 10:32:40 +02:00
|
|
|
* @param value string with formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutArc::SetFormula(const QString &value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
2015-06-11 12:15:57 +02:00
|
|
|
formula = qApp->TrVars()->FormulaToUser(value);
|
2014-06-09 18:37:11 +02:00
|
|
|
// increase height if needed.
|
|
|
|
if (formula.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployFormulaTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
|
|
|
VisToolCutArc *path = qobject_cast<VisToolCutArc *>(vis);
|
|
|
|
SCASSERT(path != nullptr);
|
2014-08-15 16:37:22 +02:00
|
|
|
path->setLength(formula);
|
2015-05-21 21:24:31 +02:00
|
|
|
|
2014-10-29 14:40:56 +01:00
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
2014-01-08 15:05:32 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-05-30 10:32:40 +02:00
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief SetPointName set name point on arc
|
2014-05-30 10:32:40 +02:00
|
|
|
* @param value name
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
void DialogCutArc::SetPointName(const QString &value)
|
2014-01-08 15:05:32 +01:00
|
|
|
{
|
|
|
|
pointName = value;
|
|
|
|
ui->lineEditNamePoint->setText(pointName);
|
|
|
|
}
|
2014-05-30 10:32:40 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2015-02-03 11:17:04 +01:00
|
|
|
* @brief GetFormula return string with formula length
|
2014-05-30 10:32:40 +02:00
|
|
|
* @return formula
|
|
|
|
*/
|
2015-02-03 11:17:04 +01:00
|
|
|
QString DialogCutArc::GetFormula() const
|
2014-05-30 10:32:40 +02:00
|
|
|
{
|
2015-06-12 10:55:44 +02:00
|
|
|
return qApp->TrVars()->FormulaFromUser(formula, qApp->getSettings()->GetOsSeparator());
|
2014-05-30 10:32:40 +02:00
|
|
|
}
|
2015-02-02 16:11:48 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief getArcId return id of arc
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
quint32 DialogCutArc::getArcId() const
|
|
|
|
{
|
2015-02-03 09:17:59 +01:00
|
|
|
return getCurrentObjectId(ui->comboBoxArc);
|
2015-02-02 16:11:48 +01:00
|
|
|
}
|