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

303 lines
11 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file dialogheight.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-2015 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 "dialogheight.h"
#include "ui_dialogheight.h"
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../tools/vabstracttool.h"
#include "../visualization/vistoolheight.h"
#include "../widgets/vmaingraphicsscene.h"
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogHeight create dialog
* @param data container with data
* @param parent parent widget
*/
DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent)
2015-02-03 09:45:27 +01:00
:DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), line(nullptr)
{
ui->setupUi(this);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
CheckState();
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxPoints(ui->comboBoxP1Line);
FillComboBoxPoints(ui->comboBoxP2Line);
FillComboBoxTypeLine(ui->comboBoxLineType, VAbstractTool::LineStylesPics());
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogHeight::NamePointChanged);
connect(ui->comboBoxBasePoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogHeight::PointNameChanged);
connect(ui->comboBoxP1Line, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogHeight::PointNameChanged);
connect(ui->comboBoxP2Line, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogHeight::PointNameChanged);
line = new VisToolHeight(data);
}
//---------------------------------------------------------------------------------------------------------------------
DialogHeight::~DialogHeight()
{
if (qApp->getCurrentScene()->items().contains(line))
{ // In some cases scene delete object yourself. If not make check program will crash.
delete line;
}
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetPointName set name of point
* @param value name
*/
2015-02-03 11:17:04 +01:00
void DialogHeight::SetPointName(const QString &value)
{
pointName = value;
ui->lineEditNamePoint->setText(pointName);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetTypeLine set type of line
* @param value type
*/
2015-02-03 11:17:04 +01:00
void DialogHeight::SetTypeLine(const QString &value)
{
ChangeCurrentData(ui->comboBoxLineType, value);
2015-02-03 09:45:27 +01:00
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(value));
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetBasePointId set id base point of height
* @param value id
*/
2015-02-03 11:17:04 +01:00
void DialogHeight::SetBasePointId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxBasePoint, value);
line->setPoint1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetP1LineId set id first point of line
* @param value id
*/
2015-02-03 11:17:04 +01:00
void DialogHeight::SetP1LineId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP1Line, value);
line->setLineP1Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief SetP2LineId set id second point of line
* @param value id
*/
2015-02-03 11:17:04 +01:00
void DialogHeight::SetP2LineId(const quint32 &value)
{
setCurrentPointId(ui->comboBoxP2Line, value);
line->setLineP2Id(value);
}
2015-02-03 10:27:33 +01:00
//---------------------------------------------------------------------------------------------------------------------
2015-02-03 11:17:04 +01:00
QString DialogHeight::GetLineColor() const
2015-02-03 10:27:33 +01:00
{
2015-02-03 11:17:04 +01:00
return GetComboBoxCurrentData(ui->comboBoxLineColor);
2015-02-03 10:27:33 +01:00
}
//---------------------------------------------------------------------------------------------------------------------
2015-02-03 11:17:04 +01:00
void DialogHeight::SetLineColor(const QString &value)
2015-02-03 10:27:33 +01:00
{
ChangeCurrentData(ui->comboBoxLineColor, value);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @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 DialogHeight::ChosenObject(quint32 id, const SceneObject &type)
{
2014-08-17 20:49:29 +02:00
if (prepare == false)// After first choose we ignore all objects
{
2014-08-17 20:49:29 +02:00
if (type == SceneObject::Point)
{
2014-08-17 20:49:29 +02:00
switch (number)
{
case (0):
if (SetObject(id, ui->comboBoxBasePoint, tr("Select first point of line")))
{
number++;
line->VisualMode(id);
}
break;
case (1):
if (getCurrentObjectId(ui->comboBoxBasePoint) != id)
2014-08-17 20:49:29 +02:00
{
if (SetObject(id, ui->comboBoxP1Line, tr("Select second point of line")))
{
number++;
line->setLineP1Id(id);
line->RefreshGeometry();
}
2014-08-17 20:49:29 +02:00
}
break;
case (2):
{
QSet<quint32> set;
set.insert(getCurrentObjectId(ui->comboBoxBasePoint));
set.insert(getCurrentObjectId(ui->comboBoxP1Line));
set.insert(id);
if (set.size() == 3)
2014-08-17 20:49:29 +02:00
{
if (SetObject(id, ui->comboBoxP2Line, ""))
{
line->setLineP2Id(id);
line->RefreshGeometry();
prepare = true;
this->setModal(true);
this->show();
}
2014-08-17 20:49:29 +02:00
}
}
2014-08-17 20:49:29 +02:00
break;
default:
break;
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogHeight::SaveData()
{
pointName = ui->lineEditNamePoint->text();
2015-02-03 11:17:04 +01:00
line->setPoint1Id(GetBasePointId());
line->setLineP1Id(GetP1LineId());
line->setLineP2Id(GetP2LineId());
line->setLineStyle(VAbstractTool::LineStyleToPenStyle(GetTypeLine()));
line->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogHeight::PointNameChanged()
{
QSet<quint32> set;
const quint32 basePointId = getCurrentObjectId(ui->comboBoxBasePoint);
const quint32 p1LineId = getCurrentObjectId(ui->comboBoxP1Line);
const quint32 p2LineId = getCurrentObjectId(ui->comboBoxP2Line);
set.insert(basePointId);
set.insert(p1LineId);
set.insert(p2LineId);
const QSharedPointer<VPointF> basePoint = data->GeometricObject<VPointF>(basePointId);
const QSharedPointer<VPointF> p1Line = data->GeometricObject<VPointF>(p1LineId);
const QSharedPointer<VPointF> p2Line = data->GeometricObject<VPointF>(p2LineId);
QColor color = okColor;
if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line->toQPointF(), p2Line->toQPointF()),
basePoint->toQPointF()) == QPointF())
{
flagError = false;
color = errorColor;
}
else
{
flagError = true;
color = okColor;
}
ChangeColor(ui->labelBasePoint, color);
ChangeColor(ui->labelFirstLinePoint, color);
ChangeColor(ui->labelSecondLinePoint, color);
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogHeight::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetTypeLine return type of line
* @return type
*/
2015-02-03 11:17:04 +01:00
QString DialogHeight::GetTypeLine() const
{
2015-02-03 11:17:04 +01:00
return GetComboBoxCurrentData(ui->comboBoxLineType);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetBasePointId return id base point of height
* @return id
*/
2015-02-03 11:17:04 +01:00
quint32 DialogHeight::GetBasePointId() const
{
return getCurrentObjectId(ui->comboBoxBasePoint);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetP1LineId return id first point of line
* @return id id
*/
2015-02-03 11:17:04 +01:00
quint32 DialogHeight::GetP1LineId() const
{
return getCurrentObjectId(ui->comboBoxP1Line);
}
//---------------------------------------------------------------------------------------------------------------------
/**
2015-02-03 11:17:04 +01:00
* @brief GetP2LineId return id second point of line
* @return id
*/
2015-02-03 11:17:04 +01:00
quint32 DialogHeight::GetP2LineId() const
{
return getCurrentObjectId(ui->comboBoxP2Line);
}