2016-05-12 21:11:21 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vsimplecurve.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 5, 2016
|
|
|
|
**
|
|
|
|
** @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) 2016 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 "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>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
|
|
|
|
|
|
|
template <class T> class QSharedPointer;
|
2016-05-12 21:11:21 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSimpleCurve::VSimpleCurve(quint32 id, const QColor ¤tColor, Unit patternUnit, qreal *factor, QObject *parent)
|
|
|
|
: VAbstractSimple(id, currentColor, patternUnit, factor, parent),
|
|
|
|
QGraphicsPathItem(),
|
2016-05-25 10:16:21 +02:00
|
|
|
m_curve(),
|
|
|
|
m_isHovered(false)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
|
|
|
this->setBrush(QBrush(Qt::NoBrush));
|
|
|
|
SetPen(this, currentColor, WidthHairLine(patternUnit));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSimpleCurve::~VSimpleCurve()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-09-24 13:41:05 +02:00
|
|
|
void VSimpleCurve::RefreshGeometry(const QSharedPointer<VAbstractCurve> &curve)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
2016-09-24 13:41:05 +02:00
|
|
|
m_curve = curve;
|
|
|
|
ShowPath();
|
2016-05-12 21:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-09-24 13:41:05 +02:00
|
|
|
void VSimpleCurve::SetEnabled(bool enabled)
|
2016-05-12 21:11:21 +02:00
|
|
|
{
|
2016-09-24 13:41:05 +02:00
|
|
|
VAbstractSimple::SetEnabled(enabled);
|
|
|
|
SetPen(this, currentColor, WidthHairLine(patternUnit));
|
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
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (selectionType == SelectionType::ByMouseRelease)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
emit Choosed(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QGraphicsPathItem::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2016-05-25 10:16:21 +02:00
|
|
|
m_isHovered = true;
|
2016-05-12 21:11:21 +02:00
|
|
|
SetPen(this, currentColor, WidthMainLine(patternUnit));
|
2016-05-25 10:16:21 +02:00
|
|
|
ShowPath();
|
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;
|
2016-05-12 21:11:21 +02:00
|
|
|
SetPen(this, currentColor, WidthHairLine(patternUnit));
|
2016-05-25 10:16:21 +02:00
|
|
|
ShowPath();
|
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)
|
|
|
|
{
|
|
|
|
if (change == QGraphicsItem::ItemSelectedChange)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
emit ShowContextMenu(event);
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2016-05-25 10:16:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VSimpleCurve::ShowPath()
|
|
|
|
{
|
|
|
|
if (not m_curve.isNull())
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
m_isHovered ? path = m_curve->GetPath(PathDirection::Show) : path = m_curve->GetPath(PathDirection::Hide);
|
|
|
|
path.setFillRule( Qt::WindingFill );
|
|
|
|
setPath(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << tr("VSimpleCurve::RefreshGeometry: pointer to curve is null.");
|
|
|
|
}
|
|
|
|
}
|