2014-03-04 17:50:54 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vabstractspline.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-03-04 17:50:54 +01:00
|
|
|
** @date 4 3, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2014-03-04 17:50:54 +01:00
|
|
|
** <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 "vabstractspline.h"
|
2016-02-12 19:10:01 +01:00
|
|
|
#include "../vwidgets/vcontrolpointspline.h"
|
2016-03-04 17:08:29 +01:00
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
2016-02-12 19:10:01 +01:00
|
|
|
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QKeyEvent>
|
2014-03-04 17:50:54 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractSpline::VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent)
|
2014-08-17 17:50:33 +02:00
|
|
|
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector<VControlPointSpline *>()),
|
2015-04-23 17:06:17 +02:00
|
|
|
sceneType(SceneObject::Unknown), isHovered(false), detailsMode(false)
|
2016-03-31 16:01:41 +02:00
|
|
|
{
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
}
|
2014-03-04 17:50:54 +01:00
|
|
|
|
2014-10-04 08:37:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VAbstractSpline::~VAbstractSpline()
|
|
|
|
{}
|
|
|
|
|
2014-08-30 21:58:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractSpline::getTagName() const
|
|
|
|
{
|
2016-05-16 19:59:04 +02:00
|
|
|
return VAbstractPattern::TagSpline;
|
2014-07-24 12:20:26 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update tool data form file.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::FullUpdateFromFile()
|
|
|
|
{
|
2015-02-06 18:43:31 +01:00
|
|
|
ReadAttributes();
|
2014-03-04 17:50:54 +01:00
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-06-24 10:23:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-25 08:24:16 +02:00
|
|
|
void VAbstractSpline::Disable(bool disable, const QString &namePP)
|
2014-06-24 10:23:39 +02:00
|
|
|
{
|
2015-05-25 08:24:16 +02:00
|
|
|
enabled = !CorrectDisable(disable, namePP);
|
2015-02-06 13:31:40 +01:00
|
|
|
this->setEnabled(enabled);
|
2016-05-19 12:11:50 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
this->setPen(QPen(CorrectColor(curve->GetColor()),
|
2015-06-15 11:32:27 +02:00
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine,
|
2015-02-06 13:31:40 +01:00
|
|
|
Qt::RoundCap));
|
|
|
|
emit setEnabledPoint(enabled);
|
2014-06-24 10:23:39 +02:00
|
|
|
}
|
|
|
|
|
2015-04-23 17:06:17 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::DetailsMode(bool mode)
|
|
|
|
{
|
|
|
|
detailsMode = mode;
|
|
|
|
RefreshGeometry();
|
|
|
|
ShowHandles(detailsMode);
|
|
|
|
}
|
|
|
|
|
2016-03-31 16:01:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::AllowHover(bool enabled)
|
|
|
|
{
|
|
|
|
setAcceptHoverEvents(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::AllowSelecting(bool enabled)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemIsSelectable, enabled);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ShowTool highlight tool.
|
|
|
|
* @param id object id in container
|
|
|
|
* @param enable enable or disable highlight.
|
|
|
|
*/
|
2015-02-07 16:18:18 +01:00
|
|
|
void VAbstractSpline::ShowTool(quint32 id, bool enable)
|
2014-03-04 17:50:54 +01:00
|
|
|
{
|
2015-02-07 16:18:18 +01:00
|
|
|
ShowItem(this, id, enable);
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief SetFactor set current scale factor of scene.
|
|
|
|
* @param factor scene scale factor.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::SetFactor(qreal factor)
|
|
|
|
{
|
|
|
|
VDrawTool::SetFactor(factor);
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
2014-08-19 13:16:00 +02:00
|
|
|
* @brief hoverEnterEvent handle hover enter events.
|
|
|
|
* @param event hover enter event.
|
2014-06-13 19:02:41 +02:00
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-08-19 13:16:00 +02:00
|
|
|
void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
2014-03-04 17:50:54 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2016-05-19 12:11:50 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
this->setPen(QPen(CorrectColor(curve->GetColor()),
|
2015-06-15 11:32:27 +02:00
|
|
|
qApp->toPixel(WidthMainLine(*VAbstractTool::data.GetPatternUnit()))/factor, Qt::SolidLine,
|
2015-02-06 12:41:30 +01:00
|
|
|
Qt::RoundCap));
|
2014-08-17 16:22:30 +02:00
|
|
|
this->setPath(ToolPath(PathDirection::Show));
|
2014-08-19 13:16:00 +02:00
|
|
|
isHovered = true;
|
|
|
|
QGraphicsPathItem::hoverEnterEvent(event);
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief hoverLeaveEvent handle hover leave events.
|
|
|
|
* @param event hover leave event.
|
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2016-05-19 12:11:50 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
this->setPen(QPen(CorrectColor(curve->GetColor()),
|
2015-06-15 11:32:27 +02:00
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2015-04-23 17:06:17 +02:00
|
|
|
if (detailsMode)
|
|
|
|
{
|
|
|
|
this->setPath(ToolPath(PathDirection::Show));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->setPath(ToolPath());
|
|
|
|
}
|
2014-08-19 13:16:00 +02:00
|
|
|
isHovered = false;
|
|
|
|
QGraphicsPathItem::hoverLeaveEvent(event);
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief itemChange hadle item change.
|
|
|
|
* @param change change.
|
|
|
|
* @param value value.
|
|
|
|
* @return value.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
QVariant VAbstractSpline::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
2016-04-05 19:14:12 +02:00
|
|
|
emit ChangedToolSelection(value.toBool(), id, id);
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
|
|
|
|
2016-05-08 17:04:18 +02:00
|
|
|
return QGraphicsPathItem::itemChange(change, value);
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief keyReleaseEvent handle key release events.
|
|
|
|
* @param event key release event.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
2015-11-02 17:25:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
DeleteTool();
|
|
|
|
}
|
|
|
|
catch(const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return;//Leave this method immediately!!!
|
|
|
|
}
|
|
|
|
break;
|
2014-03-04 17:50:54 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-08 17:04:18 +02:00
|
|
|
QGraphicsPathItem::keyReleaseEvent ( event );
|
2014-03-04 17:50:54 +01:00
|
|
|
}
|
2014-08-17 16:22:30 +02:00
|
|
|
|
2016-03-31 16:01:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
QGraphicsPathItem::mousePressEvent(event);
|
|
|
|
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
}
|
|
|
|
|
2014-08-17 17:50:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
2016-03-31 16:01:41 +02:00
|
|
|
* @brief mouseReleaseEvent handle mouse release events.
|
2014-08-17 17:50:33 +02:00
|
|
|
* @param event mouse release event.
|
|
|
|
*/
|
2016-03-31 16:01:41 +02:00
|
|
|
void VAbstractSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2014-08-17 17:50:33 +02:00
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit ChoosedTool(id, sceneType);
|
|
|
|
}
|
2016-03-31 16:01:41 +02:00
|
|
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
2014-08-17 17:50:33 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 16:22:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const
|
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
2014-08-17 16:22:30 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.addPath(curve->GetPath(direction));
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
return path;
|
|
|
|
}
|
2014-09-06 10:51:46 +02:00
|
|
|
|
2015-02-06 18:43:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::ReadToolAttributes(const QDomElement &domElement)
|
|
|
|
{
|
2016-05-19 12:11:50 +02:00
|
|
|
Q_UNUSED(domElement)
|
2015-02-06 18:43:31 +01:00
|
|
|
}
|
|
|
|
|
2015-05-28 14:13:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
|
|
|
|
{
|
|
|
|
VDrawTool::SaveOptions(tag, obj);
|
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = qSharedPointerCast<VAbstractCurve>(obj);
|
|
|
|
doc->SetAttribute(tag, AttrColor, curve->GetColor());
|
2015-05-28 14:13:37 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 17:08:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSpline VAbstractSpline::CorrectedSpline(const VSpline &spline, const SplinePointPosition &position,
|
|
|
|
const QPointF &pos) const
|
|
|
|
{
|
|
|
|
VSpline spl;
|
|
|
|
if (position == SplinePointPosition::FirstPoint)
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
QLineF line(spline.GetP1(), pos);
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
qreal newAngle1 = line.angle();
|
|
|
|
QString newAngle1F = QString().setNum(newAngle1);
|
|
|
|
|
|
|
|
qreal newLength1 = line.length();
|
|
|
|
QString newLength1F = QString().setNum(qApp->fromPixel(newLength1));
|
|
|
|
|
|
|
|
if (not qmu::QmuTokenParser::IsSingle(spline.GetStartAngleFormula()))
|
|
|
|
{
|
|
|
|
newAngle1 = spline.GetStartAngle();
|
|
|
|
newAngle1F = spline.GetStartAngleFormula();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not qmu::QmuTokenParser::IsSingle(spline.GetC1LengthFormula()))
|
|
|
|
{
|
|
|
|
newLength1 = spline.GetC1Length();
|
|
|
|
newLength1F = spline.GetC1LengthFormula();
|
|
|
|
}
|
|
|
|
|
|
|
|
spl = VSpline(spline.GetP1(), spline.GetP4(), newAngle1, newAngle1F, spline.GetEndAngle(),
|
|
|
|
spline.GetEndAngleFormula(), newLength1, newLength1F, spline.GetC2Length(),
|
|
|
|
spline.GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-14 21:28:09 +02:00
|
|
|
QLineF line(spline.GetP4(), pos);
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
qreal newAngle2 = line.angle();
|
|
|
|
QString newAngle2F = QString().setNum(newAngle2);
|
|
|
|
|
|
|
|
qreal newLength2 = line.length();
|
|
|
|
QString newLength2F = QString().setNum(qApp->fromPixel(newLength2));
|
|
|
|
|
|
|
|
if (not qmu::QmuTokenParser::IsSingle(spline.GetEndAngleFormula()))
|
|
|
|
{
|
|
|
|
newAngle2 = spline.GetEndAngle();
|
|
|
|
newAngle2F = spline.GetEndAngleFormula();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not qmu::QmuTokenParser::IsSingle(spline.GetC2LengthFormula()))
|
|
|
|
{
|
|
|
|
newLength2 = spline.GetC2Length();
|
|
|
|
newLength2F = spline.GetC2LengthFormula();
|
|
|
|
}
|
|
|
|
spl = VSpline(spline.GetP1(), spline.GetP4(), spline.GetStartAngle(), spline.GetStartAngleFormula(),
|
|
|
|
newAngle2, newAngle2F, spline.GetC1Length(), spline.GetC1LengthFormula(),
|
|
|
|
newLength2, newLength2F);
|
|
|
|
}
|
|
|
|
|
|
|
|
return spl;
|
|
|
|
}
|
|
|
|
|
2014-09-06 10:51:46 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-22 16:30:48 +02:00
|
|
|
void VAbstractSpline::ShowHandles(bool show)
|
2014-09-06 10:51:46 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < controlPoints.size(); ++i)
|
|
|
|
{
|
|
|
|
controlPoints.at(i)->setVisible(show);
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 13:17:49 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::setEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
QGraphicsPathItem::setEnabled(enabled);
|
|
|
|
if (enabled)
|
|
|
|
{
|
2016-05-19 12:11:50 +02:00
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
setPen(QPen(QColor(curve->GetColor()),
|
2015-06-15 11:32:27 +02:00
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2015-02-04 13:17:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-15 11:32:27 +02:00
|
|
|
setPen(QPen(Qt::gray,
|
|
|
|
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor));
|
2015-02-04 13:17:49 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-16 14:04:21 +01:00
|
|
|
|
2016-05-19 12:11:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractSpline::GetLineColor() const
|
|
|
|
{
|
|
|
|
const QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
return curve->GetColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::SetLineColor(const QString &value)
|
|
|
|
{
|
|
|
|
QSharedPointer<VAbstractCurve> curve = VAbstractTool::data.GeometricObject<VAbstractCurve>(id);
|
|
|
|
curve->SetColor(value);
|
|
|
|
QSharedPointer<VGObject> obj = qSharedPointerCast<VGObject>(curve);
|
|
|
|
SaveOption(obj);
|
|
|
|
}
|
|
|
|
|
2016-02-16 14:04:21 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VAbstractSpline::name() const
|
|
|
|
{
|
|
|
|
return ObjectName<VAbstractCurve>(id);
|
|
|
|
}
|
2016-04-06 11:03:34 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::GroupVisibility(quint32 object, bool visible)
|
|
|
|
{
|
|
|
|
Q_UNUSED(object);
|
|
|
|
setVisible(visible);
|
|
|
|
}
|