Brush detail.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-01-10 15:31:43 +02:00
parent a97ce04ca5
commit 3d6f8e0caa
7 changed files with 155 additions and 19 deletions

View File

@ -446,9 +446,7 @@ QVector<QPointF> VDetail::SeamAllowancePoints(const VContainer *data) const
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VDetail::ContourPath(const VContainer *data) const
{
QVector<QPointF> points = ContourPoints(data);
QVector<QPointF> pointsEkv = SeamAllowancePoints(data);
const QVector<QPointF> points = ContourPoints(data);
QPainterPath path;
// contour
@ -458,25 +456,33 @@ QPainterPath VDetail::ContourPath(const VContainer *data) const
path.lineTo(points.at(i));
}
path.lineTo(points.at(0));
path.setFillRule(Qt::WindingFill);
return path;
}
//---------------------------------------------------------------------------------------------------------------------
QPainterPath VDetail::SeamAllowancePath(const VContainer *data) const
{
const QVector<QPointF> pointsEkv = SeamAllowancePoints(data);
QPainterPath ekv;
// seam allowence
if (getSeamAllowance() == true)
if (getSeamAllowance())
{
if (not pointsEkv.isEmpty())
{
QPainterPath ekv;
ekv.moveTo(pointsEkv.at(0));
for (qint32 i = 1; i < pointsEkv.count(); ++i)
{
ekv.lineTo(pointsEkv.at(i));
}
path.addPath(ekv);
path.setFillRule(Qt::WindingFill);
ekv.setFillRule(Qt::WindingFill);
}
}
return path;
return ekv;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -82,6 +82,7 @@ public:
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;
QPainterPath ContourPath(const VContainer *data) const;
QPainterPath SeamAllowancePath(const VContainer *data) const;
QVector<VNodeDetail> listNodePoint()const;
private:
QSharedDataPointer<VDetailData> d;

View File

@ -28,9 +28,9 @@
#include "vtooldetail.h"
#include "nodeDetails/nodedetails.h"
#include "../../vgeometry/varc.h"
#include "../../vgeometry/vsplinepath.h"
#include "../../vwidgets/vmaingraphicsscene.h"
#include "../vgeometry/varc.h"
#include "../vgeometry/vsplinepath.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "../dialogs/tools/dialogtool.h"
#include "../dialogs/tools/dialogdetail.h"
#include "../undocommands/savedetailoptions.h"
@ -75,7 +75,8 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath");
*/
VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation,
VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent)
:VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialog(nullptr), sceneDetails(scene), drawName(drawName)
:VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene),
drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this))
{
VDetail detail = data->GetDetail(id);
for (int i = 0; i< detail.CountNode(); ++i)
@ -102,6 +103,10 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
RefreshGeometry();
this->setBrush(QBrush(Qt::Dense7Pattern));
seamAllowance->setBrush(QBrush(Qt::FDiagPattern));
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
@ -404,7 +409,7 @@ void VToolDetail::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->accept();
}
}
QGraphicsPathItem::mousePressEvent(event);
VNoBrushScalePathItem::mousePressEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
@ -565,9 +570,23 @@ void VToolDetail::ShowVisualization(bool show)
void VToolDetail::RefreshGeometry()
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
VDetail detail = VAbstractTool::data.GetDetail(id);
this->setPath(detail.ContourPath(this->getData()));
const VDetail detail = VAbstractTool::data.GetDetail(id);
QPainterPath mainPath = detail.ContourPath(this->getData());
this->setPath(mainPath);
this->setPos(detail.getMx(), detail.getMy());
if (detail.getSeamAllowance())
{
mainPath.addPath(detail.SeamAllowancePath(this->getData()));
mainPath.setFillRule(Qt::OddEvenFill);
seamAllowance->setPath(mainPath);
}
else
{
seamAllowance->setPath(QPainterPath());
}
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}

View File

@ -30,7 +30,7 @@
#define VTOOLDETAIL_H
#include "vabstracttool.h"
#include <QGraphicsPathItem>
#include "../vwidgets/vnobrushscalepathitem.h"
class VMainGraphicsScene;
class DialogTool;
@ -38,7 +38,7 @@ class DialogTool;
/**
* @brief The VToolDetail class for working with detail.
*/
class VToolDetail: public VAbstractTool, public QGraphicsPathItem
class VToolDetail: public VAbstractTool, public VNoBrushScalePathItem
{
Q_OBJECT
public:
@ -111,6 +111,8 @@ private:
VMainGraphicsScene *sceneDetails;
QString drawName;
VNoBrushScalePathItem *seamAllowance;
void RefreshGeometry ();
template <typename Tool>
/**

View File

@ -0,0 +1,59 @@
/************************************************************************
**
** @file vnobrushscalepathitem.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 1, 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 "vnobrushscalepathitem.h"
#include <QBrush>
#include <QPainter>
//---------------------------------------------------------------------------------------------------------------------
VNoBrushScalePathItem::VNoBrushScalePathItem(QGraphicsItem *parent) :
QGraphicsPathItem(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
void VNoBrushScalePathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
/*
* how to avoid transformation of QBrush
* http://www.qtforum.org/article/23942/how-to-avoid-transformation-of-qbrush-texture.html
* ?s=b4ba78dd6758da78fe395d8f6bb7512511a0833e#post84983
*
* Not Scaling QBrush style fro qgraphics view item
* http://www.qtcentre.org/archive/index.php/t-13950.html
*
* You'll have to scale the brush down. The QStyleOptionGraphicsItem option passed in paint() will give you the
* transform being used, and you can set a matrix on a QBrush. Put the two together and you can scale the brush
* opposite of the item.
*/
QBrush brush = this->brush();
brush.setMatrix(painter->combinedMatrix().inverted());
this->setBrush(brush);
QGraphicsPathItem::paint(painter, option, widget);
}

View File

@ -0,0 +1,47 @@
/************************************************************************
**
** @file vnobrushscalepathitem.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 1, 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/>.
**
*************************************************************************/
#ifndef VNOBRUSHSCALEPATHITEM_H
#define VNOBRUSHSCALEPATHITEM_H
#include <QGraphicsPathItem>
class VNoBrushScalePathItem : public QGraphicsPathItem
{
public:
explicit VNoBrushScalePathItem(QGraphicsItem *parent = 0);
protected:
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option,
QWidget * widget = nullptr) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(VNoBrushScalePathItem)
};
#endif // VNOBRUSHSCALEPATHITEM_H

View File

@ -8,7 +8,8 @@ SOURCES += \
$$PWD/vcontrolpointspline.cpp \
$$PWD/vgraphicssimpletextitem.cpp \
$$PWD/vsimplepoint.cpp \
$$PWD/vabstractsimple.cpp
$$PWD/vabstractsimple.cpp \
$$PWD/vnobrushscalepathitem.cpp
win32-msvc*:SOURCES += $$PWD/stable.cpp
@ -20,4 +21,5 @@ HEADERS += \
$$PWD/vcontrolpointspline.h \
$$PWD/vgraphicssimpletextitem.h \
$$PWD/vsimplepoint.h \
$$PWD/vabstractsimple.h
$$PWD/vabstractsimple.h \
$$PWD/vnobrushscalepathitem.h