17#ifndef QGSGRAPHICSVIEWMOUSEHANDLES_H
18#define QGSGRAPHICSVIEWMOUSEHANDLES_H
28#include <QGraphicsRectItem>
47class GUI_EXPORT QgsGraphicsViewMouseHandles :
public QObject,
public QGraphicsRectItem
70 QgsGraphicsViewMouseHandles( QGraphicsView *view );
76 bool isDragging()
const {
return mIsDragging; }
79 bool isResizing()
const {
return mIsResizing; }
86 bool isRotating()
const {
return mIsRotating; }
88 bool shouldBlockEvent( QInputEvent *event )
const;
91 void startMove( QPointF sceneCoordPos );
100 bool isRotationEnabled()
const {
return mRotationEnabled; }
110 void setRotationEnabled(
bool enable );
115 void selectedItemSizeChanged();
118 void selectedItemRotationChanged();
121 void paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr );
124 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
126 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
127 virtual QList<QGraphicsItem *> selectedSceneItems(
bool includeLockedItems =
true )
const = 0;
128 virtual bool itemIsLocked( QGraphicsItem *item )
133 virtual bool itemIsGroupMember( QGraphicsItem *item )
138 virtual QRectF itemRect( QGraphicsItem *item )
const = 0;
139 virtual QRectF storedItemRect( QGraphicsItem *item )
const;
140 virtual void moveItem( QGraphicsItem *item,
double deltaX,
double deltaY ) = 0;
141 virtual void rotateItem( QGraphicsItem *item,
double deltaDegree,
double deltaCenterX,
double deltaCenterY );
142 virtual void previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY );
143 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
153 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
155 virtual void startMacroCommand(
const QString &text );
156 virtual void endMacroCommand();
157 virtual void createItemCommand( QGraphicsItem *item );
158 virtual void endItemCommand( QGraphicsItem *item );
159 virtual void showStatusMessage(
const QString &message ) { Q_UNUSED( message ) }
160 virtual void hideAlignItems() {}
162 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode,
bool snapHorizontal =
true,
bool snapVertical =
true );
165 virtual void expandItemList(
const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected )
const;
167 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
168 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
169 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
170 void mousePressEvent( QGraphicsSceneMouseEvent *event )
override;
171 void mouseMoveEvent( QGraphicsSceneMouseEvent *event )
override;
172 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
override;
175 void resetStatusBar();
178 bool selectionRotation(
double &rotation )
const;
181 void updateHandles();
184 void dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap );
187 void resizeMouseMove( QPointF currentPosition,
bool lockAspect,
bool fromCenter );
190 void rotateMouseMove( QPointF currentPosition,
bool snapToCommonAngles );
192 void setHandleSize(
double size );
198 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
201 QRectF selectionBounds()
const;
211 static void relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter );
222 static double relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax );
225 QGraphicsView *mView =
nullptr;
227 double mHandleSize = 10;
228 double mRotationHandleSize = 20;
229 QPainterPath mRotationHandlePath;
231 QSizeF mCursorOffset;
232 double mResizeMoveX = 0;
233 double mResizeMoveY = 0;
236 double mBeginHandleWidth = 0;
237 double mBeginHandleHeight = 0;
241 bool mRotationEnabled =
false;
243 QPointF mRotationCenter;
245 double mRotationBegin = 0.0;
247 double mRotationCurrent = 0.0;
249 double mRotationDelta = 0.0;
252 QPointF mMouseMoveStartPos;
255 bool mDoubleClickInProgress =
false;
258 bool mIsDragging =
false;
260 bool mIsResizing =
false;
262 bool mIsRotating =
false;
265 QPointF mBeginMouseEventPos;
268 QPointF mBeginHandlePos;
271 void drawHandles( QPainter *painter,
double rectHandlerSize );
274 void drawSelectedItemBounds( QPainter *painter );
280 double rectHandlerBorderTolerance()
const;
283 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
MouseHandlesAction
Action to be performed by the mouse handles.