2017-05-16 12:07:53 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 16 5, 2017
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2017-05-16 12:07:53 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2017 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 "vcurvepathitem.h"
|
2017-06-23 11:25:02 +02:00
|
|
|
#include "../vwidgets/global.h"
|
2017-06-23 13:18:31 +02:00
|
|
|
#include "../vgeometry/vabstractcurve.h"
|
2018-02-06 18:30:27 +01:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2017-05-16 12:07:53 +02:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCurvePathItem::VCurvePathItem(QGraphicsItem *parent)
|
|
|
|
: QGraphicsPathItem(parent),
|
2017-07-27 16:15:53 +02:00
|
|
|
m_directionArrows(),
|
2017-10-24 15:42:09 +02:00
|
|
|
m_points(),
|
2018-02-06 18:30:27 +01:00
|
|
|
m_defaultWidth(qApp->Settings()->WidthMainLine())
|
|
|
|
{}
|
2017-05-16 12:07:53 +02:00
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPainterPath VCurvePathItem::shape() const
|
|
|
|
{
|
2017-07-27 16:15:53 +02:00
|
|
|
QPainterPath itemPath;
|
|
|
|
|
|
|
|
if (not m_points.isEmpty())
|
|
|
|
{
|
|
|
|
for (qint32 i = 0; i < m_points.count()-1; ++i)
|
|
|
|
{
|
|
|
|
itemPath.moveTo(m_points.at(i));
|
|
|
|
itemPath.lineTo(m_points.at(i+1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itemPath = path();
|
|
|
|
}
|
2017-06-23 11:25:02 +02:00
|
|
|
|
2017-06-23 13:18:31 +02:00
|
|
|
const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows,
|
2018-02-06 19:45:07 +01:00
|
|
|
ScaleWidth(VAbstractCurve::LengthCurveDirectionArrow(),
|
2017-06-23 13:18:31 +02:00
|
|
|
SceneScale(scene())));
|
|
|
|
if (arrowsPath != QPainterPath())
|
2017-06-23 11:25:02 +02:00
|
|
|
{
|
2017-06-23 13:18:31 +02:00
|
|
|
itemPath.addPath(arrowsPath);
|
2017-06-23 11:25:02 +02:00
|
|
|
}
|
2017-07-27 16:15:53 +02:00
|
|
|
itemPath.setFillRule(Qt::WindingFill);
|
2017-08-01 11:57:19 +02:00
|
|
|
return ItemShapeFromPath(itemPath, pen());
|
2017-06-23 11:25:02 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCurvePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2017-06-23 11:25:02 +02:00
|
|
|
ScalePenWidth();
|
|
|
|
|
2017-06-23 13:18:31 +02:00
|
|
|
const QPainterPath arrowsPath = VAbstractCurve::ShowDirection(m_directionArrows,
|
2018-02-06 19:45:07 +01:00
|
|
|
ScaleWidth(VAbstractCurve::LengthCurveDirectionArrow(),
|
2017-06-23 13:18:31 +02:00
|
|
|
SceneScale(scene())));
|
|
|
|
|
|
|
|
if (arrowsPath != QPainterPath())
|
2017-05-16 12:07:53 +02:00
|
|
|
{
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
QPen arrowPen(pen());
|
|
|
|
arrowPen.setStyle(Qt::SolidLine);
|
|
|
|
|
|
|
|
painter->setPen(arrowPen);
|
|
|
|
painter->setBrush(brush());
|
2017-06-23 13:18:31 +02:00
|
|
|
painter->drawPath(arrowsPath);
|
2017-05-16 12:07:53 +02:00
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2017-10-29 10:06:17 +01:00
|
|
|
PaintWithFixItemHighlightSelected<QGraphicsPathItem>(this, painter, option, widget);
|
2017-05-16 12:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-06-23 13:18:31 +02:00
|
|
|
void VCurvePathItem::SetDirectionArrows(const QVector<QPair<QLineF, QLineF> > &arrows)
|
2017-05-16 12:07:53 +02:00
|
|
|
{
|
2017-06-23 13:18:31 +02:00
|
|
|
m_directionArrows = arrows;
|
2017-05-16 12:07:53 +02:00
|
|
|
}
|
2017-06-23 11:25:02 +02:00
|
|
|
|
2017-07-27 16:15:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCurvePathItem::SetPoints(const QVector<QPointF> &points)
|
|
|
|
{
|
|
|
|
m_points = points;
|
|
|
|
}
|
|
|
|
|
2017-10-24 15:42:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCurvePathItem::SetWidth(qreal width)
|
|
|
|
{
|
|
|
|
m_defaultWidth = width;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:25:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCurvePathItem::ScalePenWidth()
|
|
|
|
{
|
2017-10-24 15:42:09 +02:00
|
|
|
const qreal width = ScaleWidth(m_defaultWidth, SceneScale(scene()));
|
2017-06-23 11:25:02 +02:00
|
|
|
|
|
|
|
QPen toolPen = pen();
|
|
|
|
toolPen.setWidthF(width);
|
|
|
|
|
|
|
|
setPen(toolPen);
|
|
|
|
}
|