1
/***************************************************************************
2
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
# include <QPainterPath>
30
# include <QStyleOptionGraphicsItem>
33
#include <Mod/TechDraw/App/LineGroup.h>
34
#include <Mod/TechDraw/App/Preferences.h>
36
#include "QGIMatting.h"
41
using namespace TechDrawGui;
43
QGIMatting::QGIMatting() :
45
m_fudge(1.01) // same as m_fudge in DrawViewDetail
48
setCacheMode(QGraphicsItem::NoCache);
49
setAcceptHoverEvents(false);
50
setFlag(QGraphicsItem::ItemIsSelectable, false);
51
setFlag(QGraphicsItem::ItemIsMovable, false);
53
m_border = new QGraphicsPathItem();
56
m_pen.setColor(Qt::black);
57
m_brush.setStyle(Qt::NoBrush);
59
m_border->setPen(m_pen);
60
m_border->setBrush(m_brush);
62
m_mat = new QGraphicsPathItem();
64
m_matPen.setColor(Qt::white);
65
m_matPen.setStyle(Qt::SolidLine);
66
m_matBrush.setStyle(Qt::SolidPattern);
67
m_matBrush.setColor(Qt::white);
68
m_mat->setPen(m_matPen);
69
m_mat->setBrush(m_matBrush);
71
setZValue(ZVALUE::MATTING);
74
void QGIMatting::draw()
76
prepareGeometryChange();
77
double penWidth = Rez::guiX(TechDraw::LineGroup::getDefaultWidth("Graphic"));
78
double penWidth_2 = penWidth / 2.0;
79
m_pen.setWidthF(penWidth);
80
double matSize = m_radius * m_fudge + 2 * penWidth; // outer bound of mat
81
m_matPen.setWidthF(2.0 * penWidth);
84
if (getHoleStyle() == 0) {
85
QRectF roundCutout (-m_radius, -m_radius, 2.0 * m_radius, 2.0 * m_radius);
86
ppCut.addEllipse(roundCutout);
87
QRectF roundMat(-matSize, -matSize, 2.0 * matSize, 2.0 * matSize);
88
ppMat.addEllipse(roundMat);
89
ppMat.addEllipse(roundCutout.adjusted(-penWidth_2, -penWidth_2, penWidth_2, penWidth_2));
91
double squareSize = m_radius;
92
QRectF squareCutout (-squareSize, -squareSize, 2.0 * squareSize, 2.0 * squareSize);
93
ppCut.addRect(squareCutout);
94
QRectF squareMat(-matSize, -matSize, 2.0 * matSize, 2.0 * matSize);
95
ppMat.addRect(squareMat);
96
ppMat.addRect(squareCutout.adjusted(-penWidth_2, -penWidth_2, penWidth_2, penWidth_2));
98
m_border->setPen(m_pen);
99
m_border->setPath(ppCut);
100
m_border->setZValue(ZVALUE::MATTING);
101
m_mat->setPen(m_matPen);
102
m_mat->setPath(ppMat);
103
m_mat->setZValue(ZVALUE::MATTING - 1.0);
106
int QGIMatting::getHoleStyle()
108
return TechDraw::Preferences::mattingStyle();
111
//need this because QQGIG only updates BR when items added/deleted.
112
QRectF QGIMatting::boundingRect() const
114
return childrenBoundingRect().adjusted(-1, -1, 1,1);
117
void QGIMatting::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
118
QStyleOptionGraphicsItem myOption(*option);
119
myOption.state &= ~QStyle::State_Selected;
121
//painter->drawRect(boundingRect().adjusted(-2.0, -2.0, 2.0, 2.0));
123
QGraphicsItemGroup::paint (painter, &myOption, widget);