valentina/src/app/dialogs/tools/dialogendline.cpp

319 lines
12 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file dialogendline.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date November 15, 2013
**
** @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) 2013 Valentina project
** <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/>.
**
*************************************************************************/
2013-07-25 14:00:51 +02:00
#include "dialogendline.h"
#include "ui_dialogendline.h"
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../visualization/vistoolendline.h"
#include "../../widgets/vmaingraphicsscene.h"
#include "../../tools/vabstracttool.h"
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogEndLine create dialog
* @param data container with data
* @param parent parent widget
*/
DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()),
formulaLength(QString()), formulaAngle(QString()), basePointId(0), formulaBaseHeight(0),
formulaBaseHeightAngle(0), line(nullptr), prepare(false)
{
2013-07-25 14:00:51 +02:00
ui->setupUi(this);
2014-03-06 14:28:46 +01:00
InitVariables(ui);
InitFormulaUI(ui);
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
this->formulaBaseHeightAngle = ui->plainTextEditAngle->height();
2014-03-06 14:28:46 +01:00
InitOkCancelApply(ui);
2013-07-25 14:00:51 +02:00
flagFormula = false;
2013-07-28 00:18:06 +02:00
flagName = false;
CheckState();
FillComboBoxPoints(ui->comboBoxBasePoint);
2013-07-28 00:18:06 +02:00
FillComboBoxTypeLine(ui->comboBoxLineType);
2013-07-25 14:00:51 +02:00
connect(ui->toolButtonPutHereLength, &QPushButton::clicked, this, &DialogEndLine::PutHere);
connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogEndLine::PutAngle);
connect(ui->toolButtonEqualLength, &QPushButton::clicked, this, &DialogEndLine::EvalFormula);
connect(ui->toolButtonEqualAngle, &QPushButton::clicked, this, &DialogEndLine::EvalAngle);
2014-03-04 19:14:11 +01:00
2013-07-28 00:18:06 +02:00
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged);
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogEndLine::AngleTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit);
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogEndLine::DeployAngleTextEdit);
connect(timerFormula, &QTimer::timeout, this, &DialogEndLine::EvalAngle);
line = new VisToolEndLine(data);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PutAngle put variable into formula of angle
*/
void DialogEndLine::PutAngle()
{
PutValHere(ui->plainTextEditAngle, ui->listWidget);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalAngle calculate value of angle
*/
void DialogEndLine::EvalAngle()
{
labelEditFormula = ui->labelEditAngle;
const QString postfix = QStringLiteral("°");
Eval(ui->plainTextEditAngle->toPlainText(), flagError, timerFormula, ui->labelResultCalculationAngle, postfix,
false);
labelEditFormula = ui->labelEditFormula;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::AngleTextChanged()
{
labelEditFormula = ui->labelEditAngle;
ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula);
labelEditFormula = ui->labelEditFormula;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @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
*/
void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type)
{
if (prepare == false)// After first choose we ignore all objects
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
basePointId = id;
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
scene->addItem(line);
line->VisualMode(id, scene->getScenePos());
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
connect(scene, &VMainGraphicsScene::mouseMove, line, &VisToolEndLine::MousePos);
connect(line, &VisToolEndLine::ToolTip, this, &DialogTool::ShowVisToolTip);
emit ToolTip("");
prepare = true;
}
2013-07-25 14:00:51 +02:00
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setPointName set name of point
* @param value name
*/
void DialogEndLine::setPointName(const QString &value)
{
2013-07-25 14:00:51 +02:00
pointName = value;
ui->lineEditNamePoint->setText(pointName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setTypeLine set type of line
* @param value type
*/
void DialogEndLine::setTypeLine(const QString &value)
{
2013-07-25 14:00:51 +02:00
typeLine = value;
2013-07-29 14:55:40 +02:00
SetupTypeLine(ui->comboBoxLineType, value);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setFormula set string of formula
* @param value formula
*/
void DialogEndLine::setFormula(const QString &value)
{
formulaLength = qApp->FormulaToUser(value);
// increase height if needed. TODO : see if I can get the max number of caracters in one line
// of this PlainTextEdit to change 80 to this value
if (formulaLength.length() > 80)
{
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(formulaLength);
line->setLength(formulaLength);
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setAngle set angle of line
* @param value angle in degree
*/
void DialogEndLine::setAngle(const QString &value)
{
formulaAngle = qApp->FormulaToUser(value);
// increase height if needed. TODO : see if I can get the max number of caracters in one line
// of this PlainTextEdit to change 80 to this value
if (formulaAngle.length() > 80)
{
this->DeployAngleTextEdit();
}
ui->plainTextEditAngle->setPlainText(formulaAngle);
line->setAngle(formulaAngle);
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setBasePointId set id base point of line
* @param value id
*/
void DialogEndLine::setBasePointId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxBasePoint, basePointId, value);
line->setPoint1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogEndLine::ShowDialog show dialog after finish working with visual part
* @param click true if need show dialog after click mouse
*/
void DialogEndLine::ShowDialog(bool click)
{
if (prepare)
{
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
SCASSERT(scene != nullptr);
const VPointF *point = data->GeometricObject<const VPointF *>(basePointId);
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
//Radius of point circle, but little bigger. Need handle with hover sizes.
qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
if (line.length() <= radius)
{
return;
}
}
this->setModal(true);
this->setAngle(line->Angle());//Show in dialog angle what user choose
emit ToolTip("");
timerFormula->start();
this->show();
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::ShowVisualization()
{
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
void DialogEndLine::DialogAccepted()
{
this->SaveData();
emit DialogClosed(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::DialogApply()
{
this->SaveData();
emit DialogApplied();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::SaveData()
{
2013-07-25 14:00:51 +02:00
pointName = ui->lineEditNamePoint->text();
2013-07-28 00:18:06 +02:00
typeLine = GetTypeLine(ui->comboBoxLineType);
formulaLength = ui->plainTextEditFormula->toPlainText();
formulaLength.replace("\n", " ");
formulaAngle = ui->plainTextEditAngle->toPlainText();
formulaAngle.replace("\n", " ");
basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
line->setPoint1Id(basePointId);
line->setLength(formulaLength);
line->setAngle(formulaAngle);
line->setLineStyle(VAbstractTool::LineStyle(typeLine));
line->RefreshGeometry();
2013-07-25 14:00:51 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
DialogEndLine::~DialogEndLine()
{
delete line;
2013-07-25 14:00:51 +02:00
delete ui;
}