FreeCAD

Форк
0
/
QGIMatting.cpp 
124 строки · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2016 WandererFan <wandererfan@gmail.com>                *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <cassert>
26

27
# include <QPainter>
28
# include <QPainterPath>
29
# include <QRectF>
30
# include <QStyleOptionGraphicsItem>
31
#endif
32

33
#include <Mod/TechDraw/App/LineGroup.h>
34
#include <Mod/TechDraw/App/Preferences.h>
35

36
#include "QGIMatting.h"
37
#include "Rez.h"
38
#include "ZVALUE.h"
39

40

41
using namespace TechDrawGui;
42

43
QGIMatting::QGIMatting() :
44
    m_radius(5.0),
45
    m_fudge(1.01)       // same as m_fudge in DrawViewDetail
46

47
{
48
    setCacheMode(QGraphicsItem::NoCache);
49
    setAcceptHoverEvents(false);
50
    setFlag(QGraphicsItem::ItemIsSelectable, false);
51
    setFlag(QGraphicsItem::ItemIsMovable, false);
52

53
    m_border = new QGraphicsPathItem();
54
    addToGroup(m_border);
55

56
    m_pen.setColor(Qt::black);
57
    m_brush.setStyle(Qt::NoBrush);
58

59
    m_border->setPen(m_pen);
60
    m_border->setBrush(m_brush);
61

62
    m_mat = new QGraphicsPathItem();
63
    addToGroup(m_mat);
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);
70

71
    setZValue(ZVALUE::MATTING);
72
}
73

74
void QGIMatting::draw()
75
{
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);
82
    QPainterPath ppCut;
83
    QPainterPath ppMat;
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));
90
    } else {
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));
97
    }
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);
104
}
105

106
int QGIMatting::getHoleStyle()
107
{
108
    return TechDraw::Preferences::mattingStyle();
109
}
110

111
//need this because QQGIG only updates BR when items added/deleted.
112
QRectF QGIMatting::boundingRect() const
113
{
114
    return childrenBoundingRect().adjusted(-1, -1, 1,1);
115
}
116

117
void QGIMatting::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
118
    QStyleOptionGraphicsItem myOption(*option);
119
    myOption.state &= ~QStyle::State_Selected;
120

121
    //painter->drawRect(boundingRect().adjusted(-2.0, -2.0, 2.0, 2.0));
122

123
    QGraphicsItemGroup::paint (painter, &myOption, widget);
124
}
125

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.