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.
|
|
|
|
** Copyright (C) 2013 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 "vabstractspline.h"
|
2014-04-17 19:18:26 +02:00
|
|
|
#include <QKeyEvent>
|
2014-03-04 17:50:54 +01:00
|
|
|
|
|
|
|
const QString VAbstractSpline::TagName = QStringLiteral("spline");
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-04 17:50:54 +01:00
|
|
|
VAbstractSpline::VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent)
|
|
|
|
:VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector<VControlPointSpline *>())
|
|
|
|
{
|
|
|
|
ignoreFullUpdate = true;
|
|
|
|
}
|
|
|
|
|
2014-07-24 12:20:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
/* From question on StackOverflow
|
|
|
|
* https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected
|
|
|
|
*
|
|
|
|
* There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way
|
|
|
|
* I can think of is derive your own items from the build-in ones and override the paint() function:*/
|
|
|
|
QStyleOptionGraphicsItem myOption(*option);
|
|
|
|
myOption.state &= ~QStyle::State_Selected;
|
|
|
|
QGraphicsPathItem::paint(painter, &myOption, widget);
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
RefreshGeometry();
|
|
|
|
}
|
|
|
|
|
2014-06-24 10:23:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VAbstractSpline::Disable(bool disable)
|
|
|
|
{
|
|
|
|
DisableItem(this, disable);
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-13 19:02:41 +02:00
|
|
|
/**
|
|
|
|
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace.
|
|
|
|
* @param newName new name active pattern peace.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::ChangedActivDraw(const QString &newName)
|
|
|
|
{
|
|
|
|
bool selectable = false;
|
|
|
|
if (nameActivDraw == newName)
|
|
|
|
{
|
|
|
|
selectable = true;
|
|
|
|
currentColor = Qt::black;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectable = false;
|
|
|
|
currentColor = Qt::gray;
|
|
|
|
}
|
2014-03-26 05:39:07 +01:00
|
|
|
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
2014-03-04 17:50:54 +01:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, selectable);
|
|
|
|
this->setAcceptHoverEvents (selectable);
|
|
|
|
emit setEnabledPoint(selectable);
|
|
|
|
VDrawTool::ChangedActivDraw(newName);
|
|
|
|
}
|
|
|
|
|
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 color highlight color.
|
|
|
|
* @param enable enable or disable highlight.
|
|
|
|
*/
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::ShowTool(quint32 id, Qt::GlobalColor color, bool enable)
|
|
|
|
{
|
|
|
|
ShowItem(this, id, color, enable);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @brief hoverMoveEvent handle hover move events.
|
|
|
|
* @param event hover move event.
|
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2014-03-04 17:50:54 +01:00
|
|
|
void VAbstractSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2014-03-26 05:39:07 +01:00
|
|
|
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor));
|
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);
|
2014-03-26 05:39:07 +01:00
|
|
|
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
|
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)
|
|
|
|
{
|
|
|
|
if (value == true)
|
|
|
|
{
|
|
|
|
// do stuff if selected
|
|
|
|
this->setFocus();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// do stuff if not selected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
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:
|
2014-06-16 09:52:55 +02:00
|
|
|
DeleteTool(this);
|
2014-03-04 17:50:54 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QGraphicsItem::keyReleaseEvent ( event );
|
|
|
|
}
|