2016-05-12 21:11:21 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vsimplecurve.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 5, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-05-12 21:11:21 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-05-12 21:11:21 +02:00
|
|
|
**
|
|
|
|
** 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 "vsimplecurve.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QBrush>
|
|
|
|
#include <QFlags>
|
2016-05-24 11:43:30 +02:00
|
|
|
#include <QGraphicsScene>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2016-05-25 10:59:59 +02:00
|
|
|
#include <QKeyEvent>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QPen>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "global.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
2017-06-16 13:53:08 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
template <class T> class QSharedPointer;
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-16 13:53:08 +02:00
|
|
|
VSimpleCurve::VSimpleCurve(quint32 id, const QSharedPointer<VAbstractCurve> &curve, QObject *parent)
|
|
|
|
: VAbstractSimple(id, parent),
|
2017-05-16 12:07:53 +02:00
|
|
|
VCurvePathItem(),
|
|
|
|
m_curve(curve),
|
2016-05-25 10:16:21 +02:00
|
|
|
m_isHovered(false)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
this->setBrush(QBrush(Qt::NoBrush));
|
|
|
|
this->setAcceptHoverEvents(true);
|
2016-05-25 10:59:59 +02:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-16 13:53:08 +02:00
|
|
|
void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
2017-06-16 13:53:08 +02:00
|
|
|
m_curve = curve;
|
|
|
|
|
|
|
|
if (not m_curve.isNull())
|
|
|
|
{
|
2017-06-23 13:18:31 +02:00
|
|
|
m_isHovered ? SetDirectionArrows(m_curve->DirectionArrows()) : SetDirectionArrows(QVector<DirectionArrow>());
|
2017-06-16 13:53:08 +02:00
|
|
|
setPath(m_curve->GetPath());
|
2017-07-27 16:15:53 +02:00
|
|
|
SetPoints(m_curve->GetPoints());
|
2017-06-16 13:53:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-02 17:27:14 +02:00
|
|
|
qWarning() << "VSimpleCurve::RefreshGeometry: pointer to curve is null.";
|
2017-06-16 13:53:08 +02:00
|
|
|
}
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::CurveChoosed()
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::CurveSelected(bool selected)
|
|
|
|
{
|
|
|
|
emit Selected(selected, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
QGraphicsPathItem::mousePressEvent(event);
|
2016-05-24 11:43:30 +02:00
|
|
|
|
|
|
|
// Somehow clicking on notselectable object do not clean previous selections.
|
|
|
|
if (not (flags() & ItemIsSelectable) && scene())
|
|
|
|
{
|
|
|
|
scene()->clearSelection();
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:11:21 +02:00
|
|
|
if (selectionType == SelectionType::ByMouseRelease)
|
|
|
|
{
|
|
|
|
event->accept();// Special for not selectable item first need to call standard mousePressEvent then accept event
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-31 09:31:50 +01:00
|
|
|
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
emit Choosed(id);
|
2017-10-31 09:31:50 +01:00
|
|
|
event->accept();
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2017-10-31 09:31:50 +01:00
|
|
|
if (selectionType == SelectionType::ByMouseRelease && IsSelectedByReleaseEvent(this, event))
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
2017-10-31 09:31:50 +01:00
|
|
|
emit Choosed(id);
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2016-05-25 10:16:21 +02:00
|
|
|
m_isHovered = true;
|
2017-07-27 15:25:24 +02:00
|
|
|
if (not m_curve.isNull())
|
|
|
|
{
|
|
|
|
SetDirectionArrows(m_curve->DirectionArrows());
|
|
|
|
}
|
2016-05-12 21:11:21 +02:00
|
|
|
QGraphicsPathItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2016-05-25 10:16:21 +02:00
|
|
|
m_isHovered = false;
|
2017-07-27 15:25:24 +02:00
|
|
|
SetDirectionArrows(QVector<DirectionArrow>());
|
2016-05-12 21:11:21 +02:00
|
|
|
QGraphicsPathItem::hoverLeaveEvent(event);
|
|
|
|
}
|
2016-05-19 16:11:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVariant VSimpleCurve::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2017-10-30 07:34:18 +01:00
|
|
|
if (change == QGraphicsItem::ItemSelectedHasChanged)
|
2016-05-19 16:11:02 +02:00
|
|
|
{
|
|
|
|
emit Selected(value.toBool(), id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsPathItem::itemChange(change, value);
|
|
|
|
}
|
2016-05-25 10:16:21 +02:00
|
|
|
|
2016-05-25 10:43:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2018-03-29 23:13:33 +02:00
|
|
|
emit ShowContextMenu(event, id);
|
2016-05-25 10:43:36 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 10:59:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
emit Delete();
|
|
|
|
return; //Leave this method immediately after call!!!
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QGraphicsPathItem::keyReleaseEvent ( event );
|
|
|
|
}
|
2017-06-23 11:25:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::ScalePenWidth()
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
qreal width = m_isHovered ? VAbstractApplication::VApp()->Settings()->WidthMainLine()
|
|
|
|
: VAbstractApplication::VApp()->Settings()->WidthHairLine();
|
2017-06-23 11:25:02 +02:00
|
|
|
width = ScaleWidth(width, SceneScale(scene()));
|
|
|
|
setPen(QPen(CorrectColor(this, m_curve->GetColor()), width, LineStyleToPenStyle(m_curve->GetPenStyle())));
|
|
|
|
}
|