valentina/dialogs/dialogsplinepath.cpp

241 lines
8.7 KiB
C++
Raw Normal View History

/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox 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-09 08:49:34 +02:00
#include "dialogsplinepath.h"
#include "ui_dialogsplinepath.h"
#include "../geometry/vsplinepoint.h"
2013-08-09 08:49:34 +02:00
DialogSplinePath::DialogSplinePath(const VContainer *data, Draw::Draws mode, QWidget *parent)
:DialogTool(data, mode, parent), ui(new Ui::DialogSplinePath), path(VSplinePath())
{
2013-08-09 08:49:34 +02:00
ui->setupUi(this);
bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
connect(bOk, &QPushButton::clicked, this, &DialogSplinePath::DialogAccepted);
QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel);
connect(bCansel, &QPushButton::clicked, this, &DialogSplinePath::DialogRejected);
FillComboBoxPoints(ui->comboBoxPoint);
path = VSplinePath(data->DataPoints());
connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogSplinePath::PointChenged);
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogSplinePath::currentPointChanged);
connect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle1Changed);
connect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle2Changed);
connect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm1Changed);
connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm2Changed);
}
DialogSplinePath::~DialogSplinePath()
{
2013-08-09 08:49:34 +02:00
delete ui;
}
void DialogSplinePath::SetPath(const VSplinePath &value)
{
2013-08-09 08:49:34 +02:00
this->path = value;
ui->listWidget->clear();
for (qint32 i = 0; i < path.CountPoint(); ++i)
{
2013-08-09 08:49:34 +02:00
NewItem(path[i].P(), path[i].KAsm1(), path[i].Angle2(), path[i].KAsm2());
}
ui->listWidget->setFocus(Qt::OtherFocusReason);
ui->doubleSpinBoxKcurve->setValue(path.getKCurve());
}
void DialogSplinePath::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)
{
2013-08-09 08:49:34 +02:00
NewItem(id, 1, 0, 1);
emit ToolTip(tr("Select point of curve path"));
2013-08-09 08:49:34 +02:00
this->show();
}
}
void DialogSplinePath::DialogAccepted()
{
2013-08-09 08:49:34 +02:00
path.Clear();
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
2013-08-09 08:49:34 +02:00
QListWidgetItem *item = ui->listWidget->item(i);
path.append( qvariant_cast<VSplinePoint>(item->data(Qt::UserRole)));
}
path.setKCurve(ui->doubleSpinBoxKcurve->value());
emit ToolTip("");
2013-08-09 08:49:34 +02:00
emit DialogClosed(QDialog::Accepted);
}
void DialogSplinePath::PointChenged(int row)
{
if (ui->listWidget->count() == 0)
{
2013-08-09 08:49:34 +02:00
return;
}
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
EnableFields();
}
void DialogSplinePath::currentPointChanged(int index)
{
2013-08-09 08:49:34 +02:00
qint64 id = qvariant_cast<qint64>(ui->comboBoxPoint->itemData(index));
qint32 row = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetP(id);
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
EnableFields();
item->setData(Qt::UserRole, QVariant::fromValue(p));
}
void DialogSplinePath::Angle1Changed(int index)
{
2013-08-09 08:49:34 +02:00
SetAngle(index+180);
}
void DialogSplinePath::Angle2Changed(int index)
{
2013-08-09 08:49:34 +02:00
SetAngle(index);
}
void DialogSplinePath::KAsm1Changed(qreal d)
{
2013-08-09 08:49:34 +02:00
qint32 row = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetKAsm1(d);
item->setData(Qt::UserRole, QVariant::fromValue(p));
}
void DialogSplinePath::KAsm2Changed(qreal d)
{
2013-08-09 08:49:34 +02:00
qint32 row = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetKAsm2(d);
item->setData(Qt::UserRole, QVariant::fromValue(p));
}
void DialogSplinePath::NewItem(qint64 id, qreal kAsm1, qreal angle, qreal kAsm2)
{
VPointF point;
if (mode == Draw::Calculation)
{
point = data->GetPoint(id);
}
else
{
point = data->GetModelingPoint(id);
}
2013-08-09 08:49:34 +02:00
QListWidgetItem *item = new QListWidgetItem(point.name());
item->setFont(QFont("Times", 12, QFont::Bold));
VSplinePoint p(id, kAsm1, angle, kAsm2);
DataPoint(id, kAsm1, angle+180, kAsm2, angle);
item->setData(Qt::UserRole, QVariant::fromValue(p));
ui->listWidget->addItem(item);
EnableFields();
}
void DialogSplinePath::DataPoint(qint64 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2)
{
2013-08-09 08:49:34 +02:00
disconnect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogSplinePath::currentPointChanged);
disconnect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle1Changed);
disconnect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle2Changed);
disconnect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm1Changed);
disconnect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm2Changed);
ChangeCurrentData(ui->comboBoxPoint, id);
ui->doubleSpinBoxKasm1->setValue(kAsm1);
ui->doubleSpinBoxKasm2->setValue(kAsm2);
2013-08-20 12:26:02 +02:00
ui->spinBoxAngle2->setValue(static_cast<qint32>(angle2));
ui->spinBoxAngle1->setValue(static_cast<qint32>(angle1));
2013-08-09 08:49:34 +02:00
connect(ui->comboBoxPoint, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogSplinePath::currentPointChanged);
connect(ui->spinBoxAngle1, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle1Changed);
connect(ui->spinBoxAngle2, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &DialogSplinePath::Angle2Changed);
connect(ui->doubleSpinBoxKasm1, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm1Changed);
connect(ui->doubleSpinBoxKasm2, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSplinePath::KAsm2Changed);
}
void DialogSplinePath::EnableFields()
{
2013-08-09 08:49:34 +02:00
ui->doubleSpinBoxKasm1->setEnabled(true);
ui->spinBoxAngle1->setEnabled(true);
ui->doubleSpinBoxKasm2->setEnabled(true);
ui->spinBoxAngle2->setEnabled(true);
qint32 row = ui->listWidget->currentRow();
if (row == 0)
{
2013-08-09 08:49:34 +02:00
ui->doubleSpinBoxKasm1->setEnabled(false);
ui->spinBoxAngle1->setEnabled(false);
return;
}
if (row == ui->listWidget->count()-1)
{
2013-08-09 08:49:34 +02:00
ui->doubleSpinBoxKasm2->setEnabled(false);
ui->spinBoxAngle2->setEnabled(false);
return;
}
}
void DialogSplinePath::SetAngle(qint32 angle)
{
2013-08-09 08:49:34 +02:00
qint32 row = ui->listWidget->currentRow();
QListWidgetItem *item = ui->listWidget->item( row );
VSplinePoint p = qvariant_cast<VSplinePoint>(item->data(Qt::UserRole));
p.SetAngle(angle);
DataPoint(p.P(), p.KAsm1(), p.Angle1(), p.KAsm2(), p.Angle2());
item->setData(Qt::UserRole, QVariant::fromValue(p));
}