2016-05-12 21:11:21 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file dialogrotation.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 10 4, 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
|
|
|
|
** <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 "dialogrotation.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QColor>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QRegularExpressionMatch>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QStringList>
|
2016-05-12 21:11:21 +02:00
|
|
|
#include <QTimer>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QToolButton>
|
|
|
|
#include <Qt>
|
|
|
|
#include <new>
|
2016-05-12 21:11:21 +02:00
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../../visualization/visualization.h"
|
2016-09-13 10:27:44 +02:00
|
|
|
#include "../../visualization/line/operation/vistoolrotation.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
|
|
|
#include "../ifc/xml/vdomdocument.h"
|
|
|
|
#include "../qmuparser/qmudef.h"
|
|
|
|
#include "../support/dialogeditwrongformula.h"
|
2016-05-12 21:11:21 +02:00
|
|
|
#include "../vgeometry/vpointf.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vmisc/vcommonsettings.h"
|
2016-05-12 21:11:21 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
2016-07-26 12:45:17 +02:00
|
|
|
#include "../vwidgets/vabstractmainwindow.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vwidgets/vmaingraphicsscene.h"
|
|
|
|
#include "ui_dialogrotation.h"
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent)
|
|
|
|
: DialogTool(data, toolId, parent),
|
|
|
|
ui(new Ui::DialogRotation),
|
|
|
|
flagAngle(false),
|
|
|
|
timerAngle(nullptr),
|
|
|
|
formulaAngle(),
|
|
|
|
formulaBaseHeightAngle(0),
|
|
|
|
objects(),
|
2016-05-24 12:29:13 +02:00
|
|
|
stage1(true),
|
2017-03-29 12:09:49 +02:00
|
|
|
m_suffix(),
|
|
|
|
m_firstRelease(false)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
this->formulaBaseHeightAngle = ui->plainTextEditFormula->height();
|
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
|
|
|
|
2016-05-18 14:35:07 +02:00
|
|
|
ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix());
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
timerAngle = new QTimer(this);
|
|
|
|
connect(timerAngle, &QTimer::timeout, this, &DialogRotation::EvalAngle);
|
|
|
|
|
|
|
|
InitOkCancelApply(ui);
|
|
|
|
|
|
|
|
FillComboBoxPoints(ui->comboBoxOriginPoint);
|
|
|
|
|
2016-05-18 15:57:17 +02:00
|
|
|
flagName = true;
|
2016-05-12 21:11:21 +02:00
|
|
|
CheckState();
|
|
|
|
|
|
|
|
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogRotation::SuffixChanged);
|
|
|
|
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogRotation::FXAngle);
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogRotation::AngleChanged);
|
|
|
|
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogRotation::DeployAngleTextEdit);
|
2016-05-18 15:57:17 +02:00
|
|
|
connect(ui->comboBoxOriginPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
this, &DialogRotation::PointChanged);
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
vis = new VisToolRotation(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DialogRotation::~DialogRotation()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint32 DialogRotation::GetOrigPointId() const
|
|
|
|
{
|
|
|
|
return getCurrentObjectId(ui->comboBoxOriginPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SetOrigPointId(const quint32 &value)
|
|
|
|
{
|
|
|
|
ChangeCurrentData(ui->comboBoxOriginPoint, value);
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
operation->SetOriginPointId(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogRotation::GetAngle() const
|
|
|
|
{
|
|
|
|
return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SetAngle(const QString &value)
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formulaAngle = qApp->TrVars()->FormulaToUser(value, qApp->Settings()->GetOsSeparator());
|
2016-05-12 21:11:21 +02:00
|
|
|
// increase height if needed.
|
|
|
|
if (formulaAngle.length() > 80)
|
|
|
|
{
|
|
|
|
this->DeployAngleTextEdit();
|
|
|
|
}
|
|
|
|
ui->plainTextEditFormula->setPlainText(formulaAngle);
|
|
|
|
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
operation->SetAngle(formulaAngle);
|
|
|
|
|
|
|
|
MoveCursorToEnd(ui->plainTextEditFormula);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogRotation::GetSuffix() const
|
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
return m_suffix;
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SetSuffix(const QString &value)
|
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
m_suffix = value;
|
2016-05-12 21:11:21 +02:00
|
|
|
ui->lineEditSuffix->setText(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<quint32> DialogRotation::GetObjects() const
|
|
|
|
{
|
|
|
|
return objects.toVector();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::ShowDialog(bool click)
|
|
|
|
{
|
|
|
|
if (stage1 && not click)
|
|
|
|
{
|
|
|
|
if (objects.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage1 = false;
|
|
|
|
|
2016-05-18 18:07:43 +02:00
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
scene->clearSelection();
|
|
|
|
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
operation->SetObjects(objects.toVector());
|
|
|
|
operation->VisualMode();
|
|
|
|
|
2016-05-18 18:07:43 +02:00
|
|
|
scene->ToggleArcSelection(false);
|
2016-12-20 16:08:28 +01:00
|
|
|
scene->ToggleElArcSelection(false);
|
2016-05-18 18:07:43 +02:00
|
|
|
scene->ToggleSplineSelection(false);
|
|
|
|
scene->ToggleSplinePathSelection(false);
|
|
|
|
|
|
|
|
scene->ToggleArcHover(false);
|
2016-12-20 16:08:28 +01:00
|
|
|
scene->ToggleElArcHover(false);
|
2016-05-18 18:07:43 +02:00
|
|
|
scene->ToggleSplineHover(false);
|
|
|
|
scene->ToggleSplinePathHover(false);
|
|
|
|
|
2016-09-17 18:18:27 +02:00
|
|
|
emit ToolTip(tr("Select origin point"));
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
else if (not stage1 && prepare && click)
|
|
|
|
{
|
2017-03-29 12:09:49 +02:00
|
|
|
// The check need to ignore first release of mouse button.
|
|
|
|
// User can select point by clicking on a label.
|
|
|
|
if (not m_firstRelease)
|
|
|
|
{
|
|
|
|
m_firstRelease = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
/*We will ignore click if pointer is in point circle*/
|
|
|
|
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(scene != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetOrigPointId());
|
2017-03-31 16:04:11 +02:00
|
|
|
const QLineF line = QLineF(static_cast<QPointF>(*point), scene->getScenePos());
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
//Radius of point circle, but little bigger. Need handle with hover sizes.
|
2017-06-16 13:53:08 +02:00
|
|
|
if (line.length() <= defPointRadiusPixel*1.5)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
SetAngle(operation->Angle());//Show in dialog angle that a user choose
|
|
|
|
setModal(true);
|
|
|
|
emit ToolTip("");
|
|
|
|
timerAngle->start();
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::ChosenObject(quint32 id, const SceneObject &type)
|
|
|
|
{
|
|
|
|
if (not stage1 && not prepare)// After first choose we ignore all objects
|
|
|
|
{
|
|
|
|
if (type == SceneObject::Point)
|
|
|
|
{
|
2016-05-18 15:57:17 +02:00
|
|
|
if (objects.contains(id))
|
|
|
|
{
|
2016-09-17 18:18:27 +02:00
|
|
|
emit ToolTip(tr("Select origin point that is not part of the list of objects"));
|
2016-05-18 15:57:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
if (SetObject(id, ui->comboBoxOriginPoint, ""))
|
|
|
|
{
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-07-26 12:45:17 +02:00
|
|
|
VAbstractMainWindow *window = qobject_cast<VAbstractMainWindow *>(qApp->getMainWindow());
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(window != nullptr)
|
2016-07-26 12:45:17 +02:00
|
|
|
connect(operation, &Visualization::ToolTip, window, &VAbstractMainWindow::ShowToolTip);
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
operation->SetOriginPointId(id);
|
|
|
|
operation->RefreshGeometry();
|
|
|
|
|
|
|
|
prepare = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SelectedObject(bool selected, quint32 object, quint32 tool)
|
|
|
|
{
|
2016-05-25 15:28:35 +02:00
|
|
|
Q_UNUSED(tool)
|
2016-05-12 21:11:21 +02:00
|
|
|
if (stage1)
|
|
|
|
{
|
|
|
|
if (selected)
|
|
|
|
{
|
|
|
|
if (not objects.contains(object))
|
|
|
|
{
|
|
|
|
objects.append(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objects.removeOne(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::DeployAngleTextEdit()
|
|
|
|
{
|
|
|
|
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeightAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::AngleChanged()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditAngle;
|
|
|
|
labelResultCalculation = ui->labelResultAngle;
|
|
|
|
ValFormulaChanged(flagAngle, ui->plainTextEditFormula, timerAngle, degreeSymbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::FXAngle()
|
|
|
|
{
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit angle"));
|
|
|
|
dialog->SetFormula(GetAngle());
|
2016-08-26 18:20:03 +02:00
|
|
|
dialog->setPostfix(degreeSymbol);
|
2016-05-12 21:11:21 +02:00
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
SetAngle(dialog->GetFormula());
|
|
|
|
}
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SuffixChanged()
|
|
|
|
{
|
|
|
|
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
|
|
|
|
if (edit)
|
|
|
|
{
|
2016-05-18 15:38:04 +02:00
|
|
|
const QString suffix = edit->text();
|
|
|
|
if (suffix.isEmpty())
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
flagName = false;
|
|
|
|
ChangeColor(ui->labelSuffix, Qt::red);
|
2016-05-18 15:38:04 +02:00
|
|
|
CheckState();
|
|
|
|
return;
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
if (m_suffix != suffix)
|
2016-05-18 15:38:04 +02:00
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
QRegularExpression rx(NameRegExp());
|
2017-03-23 09:25:46 +01:00
|
|
|
const QStringList uniqueNames = VContainer::AllUniqueNames();
|
2016-05-24 12:29:13 +02:00
|
|
|
for (int i=0; i < uniqueNames.size(); ++i)
|
2016-05-18 15:38:04 +02:00
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
const QString name = uniqueNames.at(i) + suffix;
|
|
|
|
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
|
|
|
|
{
|
|
|
|
flagName = false;
|
|
|
|
ChangeColor(ui->labelSuffix, Qt::red);
|
|
|
|
CheckState();
|
|
|
|
return;
|
|
|
|
}
|
2016-05-18 15:38:04 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
2016-05-18 15:38:04 +02:00
|
|
|
|
|
|
|
flagName = true;
|
|
|
|
ChangeColor(ui->labelSuffix, okColor);
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::CheckState()
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bOk != nullptr)
|
2016-10-04 16:50:48 +02:00
|
|
|
bOk->setEnabled(flagAngle && flagName && flagError);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(bApply != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
bApply->setEnabled(bOk->isEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::ShowVisualization()
|
|
|
|
{
|
|
|
|
AddVisualization<VisToolRotation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::SaveData()
|
|
|
|
{
|
2016-05-24 12:29:13 +02:00
|
|
|
m_suffix = ui->lineEditSuffix->text();
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
formulaAngle = ui->plainTextEditFormula->toPlainText();
|
|
|
|
formulaAngle.replace("\n", " ");
|
|
|
|
|
|
|
|
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(operation != nullptr)
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
operation->SetObjects(objects.toVector());
|
|
|
|
operation->SetOriginPointId(GetOrigPointId());
|
|
|
|
operation->SetAngle(formulaAngle);
|
|
|
|
operation->RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
DialogTool::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2016-05-18 15:57:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::PointChanged()
|
|
|
|
{
|
|
|
|
QColor color = okColor;
|
|
|
|
if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint)))
|
|
|
|
{
|
|
|
|
flagError = false;
|
|
|
|
color = errorColor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagError = true;
|
|
|
|
color = okColor;
|
|
|
|
}
|
|
|
|
ChangeColor(ui->labelOriginPoint, color);
|
|
|
|
CheckState();
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogRotation::EvalAngle()
|
|
|
|
{
|
|
|
|
labelEditFormula = ui->labelEditAngle;
|
|
|
|
Eval(ui->plainTextEditFormula->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false);
|
|
|
|
}
|