2014-03-04 17:50:54 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vabstractspline.h
|
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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VABSTRACTSPLINE_H
|
|
|
|
#define VABSTRACTSPLINE_H
|
|
|
|
|
2015-06-19 16:17:31 +02:00
|
|
|
#include "../vdrawtool.h"
|
|
|
|
#include "../vwidgets/vcontrolpointspline.h"
|
2015-06-18 19:23:24 +02:00
|
|
|
|
2014-03-04 17:50:54 +01:00
|
|
|
#include <QGraphicsPathItem>
|
|
|
|
|
|
|
|
class VAbstractSpline:public VDrawTool, public QGraphicsPathItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-06-18 19:23:24 +02:00
|
|
|
VAbstractSpline(VAbstractPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr);
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual ~VAbstractSpline() Q_DECL_OVERRIDE;
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress duplInheritedMember
|
2014-03-04 17:50:54 +01:00
|
|
|
static const QString TagName;
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option,
|
|
|
|
QWidget * widget = 0) Q_DECL_OVERRIDE;
|
|
|
|
virtual int type() const Q_DECL_OVERRIDE {return Type;}
|
2014-08-26 20:31:28 +02:00
|
|
|
enum { Type = UserType + static_cast<int>(Tool::AbstractSpline)};
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual QString getTagName() const Q_DECL_OVERRIDE;
|
2015-04-22 16:30:48 +02:00
|
|
|
void ShowHandles(bool show);
|
2015-02-04 13:17:49 +01:00
|
|
|
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
|
2014-03-04 17:50:54 +01:00
|
|
|
public slots:
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual void FullUpdateFromFile () Q_DECL_OVERRIDE;
|
|
|
|
virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE;
|
2015-04-23 17:06:17 +02:00
|
|
|
void DetailsMode(bool mode);
|
2014-03-04 17:50:54 +01:00
|
|
|
signals:
|
|
|
|
/**
|
|
|
|
* @brief RefreshLine refresh control line.
|
|
|
|
* @param indexSpline position spline in spline list.
|
2014-06-02 09:43:27 +02:00
|
|
|
* @param pos position point in spline.
|
2014-03-04 17:50:54 +01:00
|
|
|
* @param controlPoint new position control point.
|
|
|
|
* @param splinePoint new position spline point.
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos,
|
2014-03-04 17:50:54 +01:00
|
|
|
const QPointF &controlPoint, const QPointF &splinePoint);
|
|
|
|
/**
|
|
|
|
* @brief setEnabledPoint disable control points.
|
|
|
|
* @param enable enable or diasable points.
|
|
|
|
*/
|
|
|
|
void setEnabledPoint(bool enable);
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief controlPoints list pointers of control points.
|
|
|
|
*/
|
|
|
|
QVector<VControlPointSpline *> controlPoints;
|
2014-08-17 17:50:33 +02:00
|
|
|
SceneObject sceneType;
|
2014-08-19 13:16:00 +02:00
|
|
|
bool isHovered;
|
2015-04-23 17:06:17 +02:00
|
|
|
bool detailsMode;
|
2014-03-04 17:50:54 +01:00
|
|
|
/**
|
|
|
|
* @brief RefreshGeometry refresh item on scene.
|
|
|
|
*/
|
|
|
|
virtual void RefreshGeometry ()=0;
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual void ShowTool(quint32 id, bool enable) Q_DECL_OVERRIDE;
|
|
|
|
virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE;
|
|
|
|
virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
|
|
|
|
virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE;
|
|
|
|
virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
|
|
|
|
virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
|
2014-08-17 16:22:30 +02:00
|
|
|
QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const;
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE;
|
|
|
|
virtual void SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj) Q_DECL_OVERRIDE;
|
2015-05-23 15:10:08 +02:00
|
|
|
|
|
|
|
template <typename T>
|
2015-07-03 16:03:19 +02:00
|
|
|
void ShowToolVisualization(bool show);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(VAbstractSpline)
|
|
|
|
};
|
2015-05-23 15:10:08 +02:00
|
|
|
|
2015-07-03 16:03:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
inline void VAbstractSpline::ShowToolVisualization(bool show)
|
|
|
|
{
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
if (vis == nullptr)
|
2015-05-23 15:10:08 +02:00
|
|
|
{
|
2015-07-03 16:03:19 +02:00
|
|
|
AddVisualization<T>();
|
|
|
|
SetVisualization();
|
2015-05-23 15:10:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-03 16:03:19 +02:00
|
|
|
if (T *visual = qobject_cast<T *>(vis))
|
|
|
|
{
|
|
|
|
visual->show();
|
|
|
|
}
|
2015-05-23 15:10:08 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 16:03:19 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delete vis;
|
|
|
|
vis = nullptr;
|
|
|
|
}
|
2015-05-23 15:10:08 +02:00
|
|
|
|
2015-07-03 16:03:19 +02:00
|
|
|
if (detailsMode)
|
|
|
|
{
|
|
|
|
ShowHandles(detailsMode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowHandles(show);
|
|
|
|
}
|
2016-01-15 13:57:41 +01:00
|
|
|
|
|
|
|
if (scene())
|
|
|
|
{ // Showing/hiding control points require recalculation scene size.
|
|
|
|
VMainGraphicsView::NewSceneRect(scene(), qApp->getSceneView());
|
|
|
|
}
|
2015-07-03 16:03:19 +02:00
|
|
|
}
|
2014-03-04 17:50:54 +01:00
|
|
|
|
|
|
|
#endif // VABSTRACTSPLINE_H
|