23
#include "PreCompiled.h"
27
# include <QGraphicsScene>
28
# include <QGraphicsSceneHoverEvent>
30
# include <QStyleOptionGraphicsItem>
33
#include <App/Application.h>
35
#include <Gui/Selection.h>
37
#include <Mod/TechDraw/App/DrawView.h>
39
#include "QGIPrimPath.h"
40
#include "PreferencesGui.h"
44
using namespace TechDrawGui;
45
using namespace TechDraw;
47
QGIPrimPath::QGIPrimPath():
49
m_capStyle(Qt::RoundCap),
50
m_fillStyleCurrent (Qt::NoBrush),
53
setCacheMode(QGraphicsItem::NoCache);
54
setFlag(QGraphicsItem::ItemIsSelectable, true);
55
setFlag(QGraphicsItem::ItemIsMovable, false);
56
setFlag(QGraphicsItem::ItemIsFocusable, true);
58
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
59
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
60
setAcceptHoverEvents(true);
62
isHighlighted = false;
63
multiselectActivated = false;
65
m_colOverride = false;
66
m_colNormal = getNormalColor();
67
m_colCurrent = m_colNormal;
68
m_styleNormal = Qt::SolidLine;
69
m_styleCurrent = m_styleNormal;
70
m_pen.setStyle(m_styleCurrent);
71
m_capStyle = prefCapStyle();
72
m_pen.setCapStyle(m_capStyle);
73
m_pen.setWidthF(m_width);
75
m_fillDef = Qt::NoBrush;
76
m_fillSelect = Qt::SolidPattern;
77
m_fillNormal = m_fillDef;
78
m_fillStyleCurrent = m_fillNormal;
80
m_colDefFill = Qt::white;
81
setFillColor(m_colDefFill);
86
QVariant QGIPrimPath::itemChange(GraphicsItemChange change, const QVariant &value)
88
if (change == ItemSelectedHasChanged && scene()) {
96
return QGraphicsPathItem::itemChange(change, value);
99
void QGIPrimPath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
105
QGraphicsPathItem::hoverEnterEvent(event);
108
void QGIPrimPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
114
QGraphicsPathItem::hoverLeaveEvent(event);
118
void QGIPrimPath::setPrettyNormal() {
120
m_colCurrent = m_colNormal;
121
m_fillColorCurrent = m_colNormalFill;
124
void QGIPrimPath::setPrettyPre() {
125
m_colCurrent = getPreColor();
126
if (!m_fillOverride) {
127
m_fillColorCurrent = getPreColor();
131
void QGIPrimPath::setPrettySel() {
132
m_colCurrent = getSelectColor();
133
if (!m_fillOverride) {
134
m_fillColorCurrent = getSelectColor();
140
QColor QGIPrimPath::getNormalColor()
148
QGraphicsItem* qparent = parentItem();
152
parent = dynamic_cast<QGIView *> (qparent);
156
return parent->getNormalColor();
158
return PreferencesGui::normalQColor();
161
QColor QGIPrimPath::getPreColor()
164
QGraphicsItem* qparent = parentItem();
168
parent = dynamic_cast<QGIView *> (qparent);
172
return parent->getPreColor();
174
return PreferencesGui::preselectQColor();
177
QColor QGIPrimPath::getSelectColor()
180
QGraphicsItem* qparent = parentItem();
184
parent = dynamic_cast<QGIView *> (qparent);
188
return parent->getSelectColor();
190
return PreferencesGui::selectQColor();
193
void QGIPrimPath::setWidth(double w)
197
m_pen.setWidthF(m_width);
200
void QGIPrimPath::setStyle(Qt::PenStyle s)
208
void QGIPrimPath::setStyle(int s)
212
m_styleCurrent = static_cast<Qt::PenStyle>(s);
213
m_styleNormal = static_cast<Qt::PenStyle>(s);
216
void QGIPrimPath::setNormalColor(QColor c)
219
m_colOverride = true;
220
m_colCurrent = m_colNormal;
223
void QGIPrimPath::setCapStyle(Qt::PenCapStyle c)
226
m_pen.setCapStyle(c);
229
Base::Reference<ParameterGrp> QGIPrimPath::getParmGroup()
231
return Preferences::getPreferenceGroup("Colors");
235
Qt::PenCapStyle QGIPrimPath::prefCapStyle()
237
return (Qt::PenCapStyle)Preferences::LineCapStyle();
240
void QGIPrimPath::mousePressEvent(QGraphicsSceneMouseEvent *event)
242
Qt::KeyboardModifiers originalModifiers = event->modifiers();
243
if (event->button()&Qt::LeftButton) {
244
multiselectActivated = false;
247
if (event->button() == Qt::LeftButton
248
&& multiselectEligible()
249
&& PreferencesGui::multiSelection()) {
251
auto parent = dynamic_cast<QGIView *>(parentItem());
253
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx();
254
if (selection.size() == 1
255
&& selection.front().getObject() == parent->getViewObject()) {
257
multiselectActivated = true;
258
event->setModifiers(originalModifiers | Qt::ControlModifier);
263
QGraphicsPathItem::mousePressEvent(event);
265
event->setModifiers(originalModifiers);
268
void QGIPrimPath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
270
Qt::KeyboardModifiers originalModifiers = event->modifiers();
271
if ((event->button()&Qt::LeftButton) && multiselectActivated) {
272
if (PreferencesGui::multiSelection()) {
273
event->setModifiers(originalModifiers | Qt::ControlModifier);
276
multiselectActivated = false;
279
QGraphicsPathItem::mouseReleaseEvent(event);
281
event->setModifiers(originalModifiers);
284
void QGIPrimPath::setFill(QColor c, Qt::BrushStyle s) {
287
m_fillStyleCurrent = s;
290
void QGIPrimPath::setFill(QBrush b) {
291
setFillColor(b.color());
292
m_fillNormal = b.style();
293
m_fillStyleCurrent = b.style();
296
void QGIPrimPath::resetFill() {
297
m_colNormalFill = m_colDefFill;
298
m_fillNormal = m_fillDef;
299
m_fillStyleCurrent = m_fillDef;
303
void QGIPrimPath::setFillColor(QColor c)
306
m_fillColorCurrent = m_colNormalFill;
309
void QGIPrimPath::setCurrentPen()
311
m_pen.setWidthF(m_width);
312
m_pen.setColor(m_colCurrent);
315
void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
316
QStyleOptionGraphicsItem myOption(*option);
317
myOption.state &= ~QStyle::State_Selected;
322
m_brush.setColor(m_fillColorCurrent);
323
m_brush.setStyle(m_fillStyleCurrent);
326
QGraphicsPathItem::paint (painter, &myOption, widget);