23
#include "PreCompiled.h"
25
# include <QGraphicsScene>
26
# include <QGraphicsSceneHoverEvent>
28
# include <QPainterPath>
29
# include <QPainterPathStroker>
32
#include <Base/Console.h>
33
#include <Mod/TechDraw/App/DrawLeaderLine.h>
34
#include <Mod/TechDraw/App/DrawUtil.h>
37
#include "PreferencesGui.h"
38
#include "QGILeaderLine.h"
39
#include "QGIPrimPath.h"
46
using namespace TechDrawGui;
47
using namespace TechDraw;
49
QGMarker::QGMarker(int idx) : QGIVertex(idx),
53
setFlag(QGraphicsItem::ItemIsMovable, true);
56
void QGMarker::mousePressEvent(QGraphicsSceneMouseEvent * event)
61
if (event->button() == Qt::RightButton) {
65
} else if(scene() && this == scene()->mouseGrabberItem()) {
68
Q_EMIT dragging(pos(), getProjIndex());
70
QGIVertex::mousePressEvent(event);
73
void QGMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
75
if (event->button() == Qt::RightButton) {
81
if(this->scene() && this == this->scene()->mouseGrabberItem()) {
85
Q_EMIT dragFinished(pos(), getProjIndex());
88
QGIVertex::mouseReleaseEvent(event);
91
void QGMarker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
94
if (event->button() == Qt::RightButton) {
98
QGIVertex::mouseDoubleClickEvent(event);
101
void QGMarker::keyPressEvent(QKeyEvent * event)
104
if (event->key() == Qt::Key_Escape) {
107
QGIVertex::keyPressEvent(event);
110
void QGMarker::setRadius(float radius)
117
p.addRect(-radius/2.0, -radius/2.0, radius, radius);
123
QGEPath::QGEPath(QGILeaderLine* leader) :
126
m_parentLeader(leader),
130
setHandlesChildEvents(false);
131
setAcceptHoverEvents(true);
132
setFlag(QGraphicsItem::ItemIsSelectable, true);
133
setFlag(QGraphicsItem::ItemIsMovable, false);
134
setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false);
135
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
137
m_ghost = new QGIPrimPath();
138
m_ghost->setParentItem(this);
139
m_ghost->setNormalColor(Qt::red);
140
m_ghost->setStyle(Qt::DashLine);
141
m_ghost->setPrettyNormal();
146
QVariant QGEPath::itemChange(GraphicsItemChange change, const QVariant &value)
149
if (change == ItemSelectedHasChanged && scene()) {
151
Q_EMIT selected(true);
154
Q_EMIT selected(false);
158
return QGIPrimPath::itemChange(change, value);
161
void QGEPath::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
167
QGIPrimPath::hoverEnterEvent(event);
170
void QGEPath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
172
QGIView *view = dynamic_cast<QGIView *> (parentItem());
177
QGraphicsItem* parent = parentItem();
178
bool parentSel(false);
180
parentSel = parent->isSelected();
182
if (!parentSel && !isSelected()) {
185
QGraphicsPathItem::hoverLeaveEvent(event);
189
void QGEPath::startPathEdit(std::vector<QPointF> pathPoints)
193
m_ghostPoints = pathPoints;
194
showMarkers(m_ghostPoints);
197
void QGEPath::showMarkers(std::vector<QPointF> points)
204
if (points.empty()) {
205
Base::Console().Message("QGEP::showMarkers - no deltas\n");
213
for (auto& p: points) {
214
QGMarker* v = new QGMarker(pointDx);
215
v->setFlag(QGraphicsItem::ItemIsMovable, true);
216
v->setFlag(QGraphicsItem::ItemIsFocusable, true);
217
v->setParentItem(this);
219
v, &QGMarker::dragFinished,
220
this, &QGEPath::onDragFinished
223
v, &QGMarker::dragging,
224
this, &QGEPath::onDragging
227
v, &QGMarker::doubleClick,
228
this, &QGEPath::onDoubleClick
231
v, &QGMarker::endEdit,
232
this, &QGEPath::onEndEdit
237
v->setNormalColor(PreferencesGui::getAccessibleQColor(QColor(Qt::black)));
238
v->setZValue(ZVALUE::VERTEX);
242
m_markers.push_back(v);
247
void QGEPath::clearMarkers()
250
if (m_markers.empty()) {
253
for (auto& m: m_markers) {
256
QGraphicsScene* s = m->scene();
267
void QGEPath::onDragFinished(QPointF dragEndPos, int markerIndex)
272
if ((int) m_ghostPoints.size() > markerIndex) {
273
m_ghostPoints.at(markerIndex) = dragEndPos;
278
void QGEPath::onDragging(QPointF pos, int markerIndex)
281
Q_UNUSED(markerIndex);
287
void QGEPath::onDoubleClick(QPointF pos, int markerIndex)
290
Q_UNUSED(markerIndex);
295
void QGEPath::onEndEdit()
299
scene()->removeItem(m_ghost);
307
std::vector<QPointF> QGEPath::getDeltasFromLeader()
309
std::vector<QPointF> qDeltas;
310
if (!m_parentLeader) {
311
Base::Console().Message("QGEP::getDeltasFromLeader - m_parentLeader is nullptr\n");
315
DrawLeaderLine* featLeader = m_parentLeader->getFeature();
317
Base::Console().Message("QGEP::getDeltasFromLeader - featLeader is nullptr\n");
321
std::vector<Base::Vector3d> vDeltas = featLeader->WayPoints.getValues();
322
for (auto& d: vDeltas) {
323
Base::Vector3d vTemp = Rez::guiX(d);
324
QPointF temp(vTemp.x, -vTemp.y);
325
qDeltas.push_back(temp);
327
if (qDeltas.empty()) {
328
Base::Console().Warning("QGEPath::getDeltasFromLeader - no points\n");
334
void QGEPath::updateParent()
338
QPointF attach = m_ghostPoints.front();
340
Q_EMIT pointsUpdated(attach, m_ghostPoints);
345
void QGEPath::drawGhost()
348
if (!m_ghost->scene()) {
349
m_ghost->setParentItem(this);
352
qpp.moveTo(m_ghostPoints.front());
353
for (int i = 1; i < (int)m_ghostPoints.size(); i++) {
354
qpp.lineTo(m_ghostPoints.at(i));
356
m_ghost->setPath(qpp);
360
void QGEPath::setStartAdjust(double adj)
362
m_startAdj = Rez::guiX(adj);
365
void QGEPath::setEndAdjust(double adj)
367
m_endAdj = Rez::guiX(adj);
370
QRectF QGEPath::boundingRect() const
372
return shape().controlPointRect();
375
QPainterPath QGEPath::shape() const
377
QPainterPath outline;
378
QPainterPathStroker stroker;
379
stroker.setWidth(getEdgeFuzz() * 2.0);
380
outline = stroker.createStroke(path()).simplified();
384
double QGEPath::getEdgeFuzz() const
386
return PreferencesGui::edgeFuzz();
389
void QGEPath::dumpGhostPoints(const char* text)
392
for (auto& d: m_ghostPoints) {
393
Base::Console().Message("%s - point: %d %s\n", text,
394
idb, TechDraw::DrawUtil::formatVector(d).c_str());
399
void QGEPath::dumpMarkerPos(const char* text)
402
for (auto& m: m_markers) {
403
Base::Console().Message("QGEP - %s - markerPos: %d %s\n", text,
404
idb, TechDraw::DrawUtil::formatVector(m->pos()).c_str());
409
#include <Mod/TechDraw/Gui/moc_QGEPath.cpp>