FreeCAD

Форк
0
/
QGIDecoration.cpp 
152 строки · 4.4 Кб
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 <QStyleOptionGraphicsItem>
29
#endif
30

31
#include "QGIDecoration.h"
32
#include "QGICMark.h"
33
#include "PreferencesGui.h"
34
#include "ZVALUE.h"
35

36

37
using namespace TechDrawGui;
38
using namespace TechDraw;
39

40
QGIDecoration::QGIDecoration() :
41
    m_colCurrent(Qt::black),
42
    m_styleCurrent(Qt::SolidLine),
43
    m_brushCurrent(Qt::SolidPattern),
44
    m_dragState(DECORNODRAG)
45
{
46
    setCacheMode(QGraphicsItem::NoCache);
47
    setAcceptHoverEvents(false);
48
    setFlag(QGraphicsItem::ItemIsSelectable, false);
49
    setFlag(QGraphicsItem::ItemIsMovable, false);
50
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
51

52
    setWidth(1.0);
53
}
54

55
void QGIDecoration::draw()
56
{
57
}
58

59
void QGIDecoration::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
60
    QStyleOptionGraphicsItem myOption(*option);
61
    myOption.state &= ~QStyle::State_Selected;
62

63
    QGraphicsItemGroup::paint (painter, &myOption, widget);
64
}
65

66
void QGIDecoration::setWidth(double w)
67
{
68
    m_width = w;
69
    m_pen.setWidthF(m_width);
70
}
71

72
void QGIDecoration::setStyle(Qt::PenStyle s)
73
{
74
    m_styleCurrent = s;
75
    m_pen.setStyle(m_styleCurrent);
76
}
77

78
void QGIDecoration::setColor(QColor c)
79
{
80
    m_colNormal = c;
81
    m_colCurrent = c;
82
    m_pen.setColor(m_colCurrent);
83
    m_brush.setColor(m_colCurrent);
84
}
85

86
QColor QGIDecoration::prefNormalColor()
87
{
88
    return PreferencesGui::normalQColor();
89
}
90

91
QColor QGIDecoration::prefPreColor()
92
{
93
    return PreferencesGui::preselectQColor();
94
}
95

96
QColor QGIDecoration::prefSelectColor()
97
{
98
    return PreferencesGui::selectQColor();
99
}
100

101
QRectF QGIDecoration::boundingRect() const
102
{
103
    return childrenBoundingRect();
104
}
105

106

107
void QGIDecoration::makeMark(double x, double y)
108
{
109
    QGICMark* cmItem = new QGICMark(-1);
110
    cmItem->setParentItem(this);
111
    cmItem->setPos(x, y);
112
    cmItem->setThick(2.0);
113
    cmItem->setSize(40.0);
114
    cmItem->setZValue(ZVALUE::VERTEX);
115
}
116

117
void QGIDecoration::makeMark(Base::Vector3d v)
118
{
119
    makeMark(v.x, v.y);
120
}
121

122
void QGIDecoration::mousePressEvent(QGraphicsSceneMouseEvent * event)
123
{
124
//    Base::Console().Message("QGID::mousePressEvent() - %s\n", getViewName());
125
    m_dragState = DECORDRAGSTARTED;
126

127
    QGraphicsItem::mousePressEvent(event);
128
}
129

130
void QGIDecoration::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
131
{
132
    if (m_dragState == DECORDRAGSTARTED) {
133
        m_dragState = DECORDRAGGING;
134
    }
135
    QGraphicsItem::mouseMoveEvent(event);
136
}
137

138
void QGIDecoration::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
139
{
140
//    Base::Console().Message("QGID::mouseReleaseEvent() - %s\n", getViewName());
141
    if (m_dragState == DECORDRAGGING) {
142
        onDragFinished();
143
    }
144
    m_dragState = DECORNODRAG;
145

146
    QGraphicsItem::mouseReleaseEvent(event);
147
}
148

149
void QGIDecoration::onDragFinished()
150
{
151
    //override this
152
}
153

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

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

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

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