From 3d6f8e0caaf5c87d81068ba9e7ebbc4c8abdaee1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 10 Jan 2016 15:31:43 +0200 Subject: [PATCH] Brush detail. --HG-- branch : develop --- src/libs/vpatterndb/vdetail.cpp | 22 +++++--- src/libs/vpatterndb/vdetail.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 33 +++++++++--- src/libs/vtools/tools/vtooldetail.h | 6 ++- src/libs/vwidgets/vnobrushscalepathitem.cpp | 59 +++++++++++++++++++++ src/libs/vwidgets/vnobrushscalepathitem.h | 47 ++++++++++++++++ src/libs/vwidgets/vwidgets.pri | 6 ++- 7 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 src/libs/vwidgets/vnobrushscalepathitem.cpp create mode 100644 src/libs/vwidgets/vnobrushscalepathitem.h diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 5dc511d55..05d123893 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -446,9 +446,7 @@ QVector VDetail::SeamAllowancePoints(const VContainer *data) const //--------------------------------------------------------------------------------------------------------------------- QPainterPath VDetail::ContourPath(const VContainer *data) const { - QVector points = ContourPoints(data); - QVector pointsEkv = SeamAllowancePoints(data); - + const QVector 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 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; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index e0402f94a..aa7262342 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -82,6 +82,7 @@ public: QVector SeamAllowancePoints(const VContainer *data) const; QPainterPath ContourPath(const VContainer *data) const; + QPainterPath SeamAllowancePath(const VContainer *data) const; QVector listNodePoint()const; private: QSharedDataPointer d; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index ad3838fef..f18621b73 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -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); } diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index ea05ab084..8190fb97e 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -30,7 +30,7 @@ #define VTOOLDETAIL_H #include "vabstracttool.h" -#include +#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 /** diff --git a/src/libs/vwidgets/vnobrushscalepathitem.cpp b/src/libs/vwidgets/vnobrushscalepathitem.cpp new file mode 100644 index 000000000..30676efca --- /dev/null +++ b/src/libs/vwidgets/vnobrushscalepathitem.cpp @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file vnobrushscalepathitem.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#include "vnobrushscalepathitem.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +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); +} diff --git a/src/libs/vwidgets/vnobrushscalepathitem.h b/src/libs/vwidgets/vnobrushscalepathitem.h new file mode 100644 index 000000000..bcf4d3aba --- /dev/null +++ b/src/libs/vwidgets/vnobrushscalepathitem.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file vnobrushscalepathitem.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VNOBRUSHSCALEPATHITEM_H +#define VNOBRUSHSCALEPATHITEM_H + +#include + +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 diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index f8798a032..619eb87e5 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -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