56 #include <QGraphicsLineItem>
57 #include <QGraphicsScene>
58 #include <QGraphicsSceneMouseEvent>
59 #include <QGraphicsView>
62 #include <QMessageLogger>
69 #include "../vwidgets/global.h"
70 #include "../vmisc/vabstractapplication.h"
71 #include "../vgeometry/vgobject.h"
80 , controlLine(nullptr)
81 , indexSpline(indexSpline)
99 const QPointF &controlPoint,
const QPointF &splinePoint,
bool freeAngle,
100 bool freeLength, QGraphicsItem *parent)
102 , controlLine(nullptr)
103 , indexSpline(indexSpline)
105 , freeAngle(freeAngle)
106 , freeLength(freeLength)
110 this->setFlag(QGraphicsItem::ItemIsMovable,
true);
111 this->setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
112 this->setAcceptHoverEvents(
true);
113 this->setPos(controlPoint);
147 setCursor(QCursor());
163 case ItemPositionChange:
167 const QPointF splPoint =
controlLine->line().p1() + pos();
169 QLineF newLine(splPoint, value.toPointF());
170 QLineF oldLine(splPoint, pos());
174 newLine.setAngle(oldLine.angle());
179 newLine.setLength(oldLine.length());
187 case ItemPositionHasChanged:
192 static bool changeFinished =
true;
195 changeFinished =
false;
201 if (not viewList.isEmpty())
203 if (QGraphicsView *view = viewList.at(0))
205 const int xmargin = 50;
206 const int ymargin = 50;
209 const QRectF itemRect = mapToScene(boundingRect()).boundingRect();
212 if (itemRect.height() + 2*ymargin < viewRect.height() &&
213 itemRect.width() + 2*xmargin < viewRect.width())
215 view->ensureVisible(itemRect, xmargin, ymargin);
222 const QPointF cursorPosition = currentScene->
getScenePos();
223 view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
228 changeFinished =
true;
235 return SceneRect::itemChange(change, value);
241 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
248 SceneRect::mousePressEvent(event);
254 if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
261 SceneRect::mouseReleaseEvent(event);
274 this->setBrush(QBrush(Qt::NoBrush));
275 this->setZValue(100);
279 controlLine->setFlag(QGraphicsItem::ItemStacksBehindParent,
true);
287 QLineF( QPointF(), splinePoint-controlPoint), p1, p2);
288 controlLine->setLine(QLineF(splinePoint-controlPoint, p1));
300 const QPointF &controlPoint,
const QPointF &splinePoint,
bool freeAngle,
307 this->setPos(controlPoint);
322 setFlag(QGraphicsItem::ItemIsSelectable, enable);
323 setFlag(QGraphicsItem::ItemIsMovable, enable);
324 setAcceptHoverEvents(enable);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE
void setOnlyPoint(bool value)
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
qint32 indexSpline
indexSpline index spline in list..
QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
itemChange handle item change.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
void showContextMenu(QGraphicsSceneContextMenuEvent *event)
showContextMenu emit when need show tool's context menu.
void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position, const QPointF &pos)
ControlPointChangePosition emit when control point change position.
SplinePointPosition position
position position point in spline.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverEnterEvent handle hover enter events.
void setCtrlLine(const QPointF &controlPoint, const QPointF &splinePoint)
void setEnabledPoint(bool enable)
setEnabledPoint disable or enable control point.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE
VScaledLine * controlLine
controlLine pointer to line control point.
VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, QGraphicsItem *parent=nullptr)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
void refreshCtrlPoint(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, const QPointF &splinePoint, bool freeAngle=true, bool freeLength=true)
refreshCtrlPoint refresh the control point.
static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2)
LineIntersectCircle find point intersection line and circle.
The VMainGraphicsScene class main scene.
QPointF getScenePos() const
static QRectF SceneVisibleArea(QGraphicsView *view)
void setBasicWidth(const qreal &value)
const QString cursorArrowOpenHand
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
const QString cursorArrowCloseHand
qreal sceneScale(QGraphicsScene *scene)
qreal scaledRadius(qreal scale)
QColor correctColor(const QGraphicsItem *item, const QColor &color)
const qreal widthHairLine