17#ifndef QGSGRAPHICSVIEWMOUSEHANDLES_H
18#define QGSGRAPHICSVIEWMOUSEHANDLES_H
23#include <QGraphicsRectItem>
45class GUI_EXPORT QgsGraphicsViewMouseHandles:
public QObject,
public QGraphicsRectItem
85 QgsGraphicsViewMouseHandles( QGraphicsView *view );
88 QgsGraphicsViewMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
91 bool isDragging()
const {
return mIsDragging; }
94 bool isResizing()
const {
return mIsResizing; }
96 bool shouldBlockEvent( QInputEvent *event )
const;
101 void selectedItemSizeChanged();
104 void selectedItemRotationChanged();
108 void paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
109 bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr );
112 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
114 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
115 virtual QList<QGraphicsItem *> selectedSceneItems(
bool includeLockedItems =
true )
const = 0;
116 virtual bool itemIsLocked( QGraphicsItem *item ) { Q_UNUSED( item );
return false; }
117 virtual bool itemIsGroupMember( QGraphicsItem *item ) { Q_UNUSED( item );
return false; }
118 virtual QRectF itemRect( QGraphicsItem *item )
const = 0;
119 virtual QRectF storedItemRect( QGraphicsItem *item )
const;
120 virtual void moveItem( QGraphicsItem *item,
double deltaX,
double deltaY ) = 0;
121 virtual void previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY );
122 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
132 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
134 virtual void startMacroCommand(
const QString &text );
135 virtual void endMacroCommand();
136 virtual void createItemCommand( QGraphicsItem *item );
137 virtual void endItemCommand( QGraphicsItem *item );
138 virtual void showStatusMessage(
const QString &message ) { Q_UNUSED( message ) }
139 virtual void hideAlignItems() {}
141 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode,
bool snapHorizontal =
true,
bool snapVertical =
true );
144 virtual void expandItemList(
const QList< QGraphicsItem * > &items, QList< QGraphicsItem * > &collected )
const;
146 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
147 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
148 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
149 void mousePressEvent( QGraphicsSceneMouseEvent *event )
override;
150 void mouseMoveEvent( QGraphicsSceneMouseEvent *event )
override;
151 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
override;
154 void resetStatusBar();
157 bool selectionRotation(
double &rotation )
const;
160 void updateHandles();
163 void dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap );
166 void resizeMouseMove( QPointF currentPosition,
bool lockAspect,
bool fromCenter );
168 void setHandleSize(
double size );
171 MouseAction mouseActionForPosition( QPointF itemCoordPos );
174 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
177 QRectF selectionBounds()
const;
187 static void relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter );
198 static double relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax );
202 QGraphicsView *mView =
nullptr;
204 double mHandleSize = 10;
206 QSizeF mCursorOffset;
207 double mResizeMoveX = 0;
208 double mResizeMoveY = 0;
211 double mBeginHandleWidth = 0;
212 double mBeginHandleHeight = 0;
217 QPointF mMouseMoveStartPos;
220 QPointF mLastMouseEventPos;
222 MouseAction mCurrentMouseMoveAction = NoAction;
225 bool mIsDragging =
false;
227 bool mIsResizing =
false;
230 QPointF mBeginMouseEventPos;
233 QPointF mBeginHandlePos;
236 void drawHandles( QPainter *painter,
double rectHandlerSize );
239 void drawSelectedItemBounds( QPainter *painter );
245 double rectHandlerBorderTolerance();
248 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );