valentina/src/dialogs/dialogarc.cpp

260 lines
7.9 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file dialogarc.cpp
** @author Roman Telezhinsky <dismine@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 <QtWidgets>
DialogArc::DialogArc(const VContainer *data, Draw::Draws mode, QWidget *parent)
:DialogTool(data, mode, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
timerRadius(0), timerF1(0), timerF2(0), center(0), radius(QString()), f1(QString()), f2(QString())
{
2013-08-06 09:56:09 +02:00
ui->setupUi(this);
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);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogArc::DialogAccepted);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogArc::DialogRejected);
FillComboBoxPoints(ui->comboBoxBasePoint);
CheckState();
listWidget = ui->listWidget;
labelDescription = ui->labelDescription;
radioButtonSizeGrowth = ui->radioButtonSizeGrowth;
radioButtonStandartTable = ui->radioButtonStandartTable;
radioButtonIncrements = ui->radioButtonIncrements;
radioButtonLengthLine = ui->radioButtonLengthLine;
radioButtonLengthArc = ui->radioButtonLengthArc;
radioButtonLengthCurve = ui->radioButtonLengthSpline;
2013-08-06 09:56:09 +02:00
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->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged);
ShowVariable(data->DataBase());
connect(ui->radioButtonSizeGrowth, &QRadioButton::clicked, this, &DialogArc::SizeGrowth);
connect(ui->radioButtonStandartTable, &QRadioButton::clicked, this, &DialogArc::StandartTable);
connect(ui->radioButtonIncrements, &QRadioButton::clicked, this, &DialogArc::Increments);
connect(ui->radioButtonLengthLine, &QRadioButton::clicked, this, &DialogArc::LengthLines);
connect(ui->radioButtonLineAngles, &QRadioButton::clicked, this, &DialogArc::LineAngles);
connect(ui->radioButtonLengthArc, &QRadioButton::clicked, this, &DialogArc::LengthArcs);
connect(ui->radioButtonLengthSpline, &QRadioButton::clicked, this, &DialogArc::LengthCurves);
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->lineEditRadius, &QLineEdit::textChanged, this, &DialogArc::RadiusChanged);
connect(ui->lineEditF1, &QLineEdit::textChanged, this, &DialogArc::F1Changed);
connect(ui->lineEditF2, &QLineEdit::textChanged, this, &DialogArc::F2Changed);
}
DialogArc::~DialogArc()
{
2013-10-26 19:55:06 +02:00
delete ui;
2013-08-06 09:56:09 +02:00
}
void DialogArc::SetCenter(const qint64 &value)
{
2013-08-06 09:56:09 +02:00
center = value;
ChangeCurrentData(ui->comboBoxBasePoint, center);
}
void DialogArc::SetF2(const QString &value)
{
2013-08-06 09:56:09 +02:00
f2 = value;
ui->lineEditF2->setText(f2);
}
void DialogArc::SetF1(const QString &value)
{
2013-08-06 09:56:09 +02:00
f1 = value;
ui->lineEditF1->setText(f1);
}
void DialogArc::SetRadius(const QString &value)
{
2013-08-06 09:56:09 +02:00
radius = value;
ui->lineEditRadius->setText(radius);
}
void DialogArc::ChoosedObject(qint64 id, const Scene::Scenes &type)
{
if (idDetail == 0 && mode == Draw::Modeling)
{
if (type == Scene::Detail)
{
idDetail = id;
return;
}
}
if (mode == Draw::Modeling)
{
if (CheckObject(id)==false)
{
return;
}
}
if (type == Scene::Point)
{
VPointF point;
if (mode == Draw::Calculation)
{
point = data->GetPoint(id);
}
else
{
point = data->GetPointModeling(id);
}
2013-08-06 09:56:09 +02:00
ChangeCurrentText(ui->comboBoxBasePoint, point.name());
emit ToolTip("");
2013-08-06 09:56:09 +02:00
this->show();
}
}
void DialogArc::DialogAccepted()
{
2013-08-06 09:56:09 +02:00
radius = ui->lineEditRadius->text();
f1 = ui->lineEditF1->text();
f2 = ui->lineEditF2->text();
center = getCurrentObjectId(ui->comboBoxBasePoint);
2013-08-06 09:56:09 +02:00
emit DialogClosed(QDialog::Accepted);
}
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())
{
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetLineAngle(item->text()))
.arg(tr("Value angle of line."));
2013-08-06 09:56:09 +02:00
ui->labelDescription->setText(desc);
return;
}
DialogTool::ValChenged(row);
}
void DialogArc::PutRadius()
{
2013-08-06 09:56:09 +02:00
PutValHere(ui->lineEditRadius, ui->listWidget);
}
void DialogArc::PutF1()
{
2013-08-06 09:56:09 +02:00
PutValHere(ui->lineEditF1, ui->listWidget);
}
void DialogArc::PutF2()
{
2013-08-06 09:56:09 +02:00
PutValHere(ui->lineEditF2, ui->listWidget);
}
void DialogArc::LineAngles()
{
ShowLineAngles();
2013-08-06 09:56:09 +02:00
}
void DialogArc::RadiusChanged()
{
labelEditFormula = ui->labelEditRadius;
2013-08-06 09:56:09 +02:00
ValFormulaChanged(flagRadius, ui->lineEditRadius, timerRadius);
}
void DialogArc::F1Changed()
{
labelEditFormula = ui->labelEditF1;
2013-08-06 09:56:09 +02:00
ValFormulaChanged(flagF1, ui->lineEditF1, timerF1);
}
void DialogArc::F2Changed()
{
labelEditFormula = ui->labelEditF2;
2013-08-06 09:56:09 +02:00
ValFormulaChanged(flagF2, ui->lineEditF2, timerF2);
}
void DialogArc::CheckState()
{
Q_ASSERT(bOk != 0);
bOk->setEnabled(flagRadius && flagF1 && flagF2);
2013-08-06 09:56:09 +02:00
}
void DialogArc::EvalRadius()
{
labelEditFormula = ui->labelEditRadius;
2013-08-06 09:56:09 +02:00
Eval(ui->lineEditRadius, flagRadius, timerRadius, ui->labelResultRadius);
}
void DialogArc::EvalF1()
{
labelEditFormula = ui->labelEditF1;
2013-08-06 09:56:09 +02:00
Eval(ui->lineEditF1, flagF1, timerF1, ui->labelResultF1);
}
void DialogArc::EvalF2()
{
labelEditFormula = ui->labelEditF2;
2013-08-06 09:56:09 +02:00
Eval(ui->lineEditF2, flagF2, timerF2, ui->labelResultF2);
}
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 QHash<QString, qreal> *lineAnglesTable = data->DataLineAngles();
Q_ASSERT(lineAnglesTable != 0);
QHashIterator<QString, qreal> 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);
}