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

372 lines
13 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file dialogarc.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-08-06 09:56:09 +02:00
#include "dialogarc.h"
#include "ui_dialogarc.h"
#include <QPushButton>
#include <QTimer>
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogArc create dialog
* @param data container with data
* @param parent parent widget
*/
DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
2014-06-10 11:49:14 +02:00
timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(0), radius(QString()), f1(QString()),
f2(QString()), formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0)
{
2013-08-06 09:56:09 +02:00
ui->setupUi(this);
InitVariables(ui);
plainTextEditFormula = ui->plainTextEditFormula;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
this->formulaBaseHeightF1 = ui->plainTextEditF1->height();
this->formulaBaseHeightF2 = ui->plainTextEditF2->height();
2013-08-06 09:56:09 +02:00
timerRadius = new QTimer(this);
connect(timerRadius, &QTimer::timeout, this, &DialogArc::EvalRadius);
timerF1 = new QTimer(this);
connect(timerF1, &QTimer::timeout, this, &DialogArc::EvalF1);
timerF2 = new QTimer(this);
connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF2);
InitOkCancelApply(ui);
2013-08-06 09:56:09 +02:00
FillComboBoxPoints(ui->comboBoxBasePoint);
CheckState();
connect(ui->toolButtonPutHereRadius, &QPushButton::clicked, this, &DialogArc::PutRadius);
connect(ui->toolButtonPutHereF1, &QPushButton::clicked, this, &DialogArc::PutF1);
2013-08-21 10:03:53 +02:00
connect(ui->toolButtonPutHereF2, &QPushButton::clicked, this, &DialogArc::PutF2);
2013-08-06 09:56:09 +02:00
connect(ui->toolButtonEqualRadius, &QPushButton::clicked, this, &DialogArc::EvalRadius);
connect(ui->toolButtonEqualF1, &QPushButton::clicked, this, &DialogArc::EvalF1);
connect(ui->toolButtonEqualF2, &QPushButton::clicked, this, &DialogArc::EvalF2);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogArc::RadiusChanged);
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogArc::F1Changed);
connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, &DialogArc::F2Changed);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogArc::DeployFormulaTextEdit);
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArc::DeployF1TextEdit);
connect(ui->pushButtonGrowLengthF2, &QPushButton::clicked, this, &DialogArc::DeployF2TextEdit);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployF1TextEdit()
{
DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployF2TextEdit()
{
DeployFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
DialogArc::~DialogArc()
{
2013-10-26 19:55:06 +02:00
delete ui;
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetCenter set id of center point
* @param value id
*/
void DialogArc::SetCenter(const quint32 &value)
{
2013-08-06 09:56:09 +02:00
center = value;
ChangeCurrentData(ui->comboBoxBasePoint, center);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetF2 set formula second angle of arc
* @param value formula
*/
void DialogArc::SetF2(const QString &value)
{
f2 = qApp->FormulaToUser(value);
// increase height if needed.
if (f2.length() > 80)
{
this->DeployF2TextEdit();
}
ui->plainTextEditF2->setPlainText(f2);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetF1 set formula first angle of arc
* @param value formula
*/
void DialogArc::SetF1(const QString &value)
{
f1 = qApp->FormulaToUser(value);
// increase height if needed.
if (f1.length() > 80)
{
this->DeployF1TextEdit();
}
ui->plainTextEditF1->setPlainText(f1);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetRadius set formula of radius
* @param value formula
*/
void DialogArc::SetRadius(const QString &value)
{
2013-08-06 09:56:09 +02:00
radius = value;
// increase height if needed.
if (radius.length() > 80)
{
this->DeployFormulaTextEdit();
}
ui->plainTextEditFormula->setPlainText(radius);
2013-08-06 09:56:09 +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
*/
void DialogArc::ChosenObject(quint32 id, const SceneObject &type)
{
if (type == SceneObject::Point)
{
const VPointF *point = data->GeometricObject<const VPointF *>(id);
ChangeCurrentText(ui->comboBoxBasePoint, point->name());
emit ToolTip("");
this->setModal(true);
2013-08-06 09:56:09 +02:00
this->show();
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
*/
void DialogArc::DialogAccepted()
{
this->SaveData();
emit DialogClosed(QDialog::Accepted);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DialogApply()
{
this->SaveData();
emit DialogApplied();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::SaveData()
{
radius = ui->plainTextEditFormula->toPlainText();
2014-06-16 19:18:36 +02:00
radius.replace("\n", " ");
f1 = ui->plainTextEditF1->toPlainText();
f1.replace("\n", " ");
f2 = ui->plainTextEditF2->toPlainText();
f2.replace("\n", " ");
center = getCurrentObjectId(ui->comboBoxBasePoint);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ValChenged show description angles of lines
* @param row number of row
*/
void DialogArc::ValChenged(int row)
{
if (ui->listWidget->count() == 0)
{
2013-08-06 09:56:09 +02:00
return;
}
QListWidgetItem *item = ui->listWidget->item( row );
if (ui->radioButtonLineAngles->isChecked())
{
qreal angle = *data->GetVariable<VLineAngle*>(item->text())->GetValue();
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(angle).arg(tr("Value of angle of line."));
2013-08-06 09:56:09 +02:00
ui->labelDescription->setText(desc);
return;
}
DialogTool::ValChenged(row);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PutRadius put variable into formula of radius
*/
void DialogArc::PutRadius()
{
PutValHere(ui->plainTextEditFormula, ui->listWidget);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PutF1 put variable into formula of first angle
*/
void DialogArc::PutF1()
{
PutValHere(ui->plainTextEditF1, ui->listWidget);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief PutF2 put variable into formula of second angle
*/
void DialogArc::PutF2()
{
PutValHere(ui->plainTextEditF2, ui->listWidget);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief LineAngles show variable angles of lines
*/
2014-05-11 20:15:32 +02:00
// cppcheck-suppress unusedFunction
void DialogArc::LineAngles()
{
ShowLineAngles();
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RadiusChanged after change formula of radius calculate value and show result
*/
void DialogArc::RadiusChanged()
{
labelEditFormula = ui->labelEditRadius;
ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F1Changed after change formula of first angle calculate value and show result
*/
void DialogArc::F1Changed()
{
labelEditFormula = ui->labelEditF1;
ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F2Changed after change formula of second angle calculate value and show result
*/
void DialogArc::F2Changed()
{
labelEditFormula = ui->labelEditF2;
ValFormulaChanged(flagF2, ui->plainTextEditF2, timerF2);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CheckState if all is right enable button ok
*/
void DialogArc::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(flagRadius && flagF1 && flagF2);
SCASSERT(bApply != nullptr);
bApply->setEnabled(flagRadius && flagF1 && flagF2);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalRadius calculate value of radius
*/
void DialogArc::EvalRadius()
{
labelEditFormula = ui->labelEditRadius;
Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, timerRadius, ui->labelResultRadius);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalF1 calculate value of first angle
*/
void DialogArc::EvalF1()
{
labelEditFormula = ui->labelEditF1;
Eval(ui->plainTextEditF1->toPlainText(), flagF1, timerF1, ui->labelResultF1);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalF2 calculate value of second angle
*/
void DialogArc::EvalF2()
{
labelEditFormula = ui->labelEditF2;
Eval(ui->plainTextEditF2->toPlainText(), flagF2, timerF2, ui->labelResultF2);
2013-08-06 09:56:09 +02:00
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowLineAngles show varibles angles of lines
*/
void DialogArc::ShowLineAngles()
{
2013-08-06 09:56:09 +02:00
disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged);
ui->listWidget->clear();
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged);
const QMap<QString, VLineAngle *> lineAnglesTable = data->DataLineAngles();
QMapIterator<QString, VLineAngle *> i(lineAnglesTable);
while (i.hasNext())
{
2013-08-06 09:56:09 +02:00
i.next();
QListWidgetItem *item = new QListWidgetItem(i.key());
item->setFont(QFont("Times", 12, QFont::Bold));
ui->listWidget->addItem(item);
}
ui->listWidget->setCurrentRow (0);
}