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;
99 void startMove( QPointF sceneCoordPos );
104 void selectedItemSizeChanged();
107 void selectedItemRotationChanged();
111 void paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
112 bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr );
115 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
117 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
118 virtual QList<QGraphicsItem *> selectedSceneItems(
bool includeLockedItems =
true )
const = 0;
119 virtual bool itemIsLocked( QGraphicsItem *item ) { Q_UNUSED( item );
return false; }
120 virtual bool itemIsGroupMember( QGraphicsItem *item ) { Q_UNUSED( item );
return false; }
121 virtual QRectF itemRect( QGraphicsItem *item )
const = 0;
122 virtual QRectF storedItemRect( QGraphicsItem *item )
const;
123 virtual void moveItem( QGraphicsItem *item,
double deltaX,
double deltaY ) = 0;
124 virtual void previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY );
125 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
135 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
137 virtual void startMacroCommand(
const QString &text );
138 virtual void endMacroCommand();
139 virtual void createItemCommand( QGraphicsItem *item );
140 virtual void endItemCommand( QGraphicsItem *item );
141 virtual void showStatusMessage(
const QString &message ) { Q_UNUSED( message ) }
142 virtual void hideAlignItems() {}
144 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode,
bool snapHorizontal =
true,
bool snapVertical =
true );
147 virtual void expandItemList(
const QList< QGraphicsItem * > &items, QList< QGraphicsItem * > &collected )
const;
149 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
150 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
151 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
152 void mousePressEvent( QGraphicsSceneMouseEvent *event )
override;
153 void mouseMoveEvent( QGraphicsSceneMouseEvent *event )
override;
154 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
override;
157 void resetStatusBar();
160 bool selectionRotation(
double &rotation )
const;
163 void updateHandles();
166 void dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap );
169 void resizeMouseMove( QPointF currentPosition,
bool lockAspect,
bool fromCenter );
171 void setHandleSize(
double size );
174 MouseAction mouseActionForPosition( QPointF itemCoordPos );
177 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
180 QRectF selectionBounds()
const;
190 static void relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter );
201 static double relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax );
205 QGraphicsView *mView =
nullptr;
207 double mHandleSize = 10;
209 QSizeF mCursorOffset;
210 double mResizeMoveX = 0;
211 double mResizeMoveY = 0;
214 double mBeginHandleWidth = 0;
215 double mBeginHandleHeight = 0;
220 QPointF mMouseMoveStartPos;
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 );