17#ifndef QGSGRAPHICSVIEWMOUSEHANDLES_H
18#define QGSGRAPHICSVIEWMOUSEHANDLES_H
23#include <QGraphicsRectItem>
46class GUI_EXPORT QgsGraphicsViewMouseHandles :
public QObject,
public QGraphicsRectItem
69 QgsGraphicsViewMouseHandles( QGraphicsView *view );
75 bool isDragging()
const {
return mIsDragging; }
78 bool isResizing()
const {
return mIsResizing; }
85 bool isRotating()
const {
return mIsRotating; }
87 bool shouldBlockEvent( QInputEvent *event )
const;
90 void startMove( QPointF sceneCoordPos );
99 bool isRotationEnabled()
const {
return mRotationEnabled; }
109 void setRotationEnabled(
bool enable );
114 void selectedItemSizeChanged();
117 void selectedItemRotationChanged();
120 void paintInternal( QPainter *painter,
bool showHandles,
bool showStaticBoundingBoxes,
bool showTemporaryBoundingBoxes,
const QStyleOptionGraphicsItem *option, QWidget *widget =
nullptr );
123 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
125 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
126 virtual QList<QGraphicsItem *> selectedSceneItems(
bool includeLockedItems =
true )
const = 0;
127 virtual bool itemIsLocked( QGraphicsItem *item )
132 virtual bool itemIsGroupMember( QGraphicsItem *item )
137 virtual QRectF itemRect( QGraphicsItem *item )
const = 0;
138 virtual QRectF storedItemRect( QGraphicsItem *item )
const;
139 virtual void moveItem( QGraphicsItem *item,
double deltaX,
double deltaY ) = 0;
140 virtual void rotateItem( QGraphicsItem *item,
double deltaDegree,
double deltaCenterX,
double deltaCenterY );
141 virtual void previewItemMove( QGraphicsItem *item,
double deltaX,
double deltaY );
142 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
152 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
154 virtual void startMacroCommand(
const QString &text );
155 virtual void endMacroCommand();
156 virtual void createItemCommand( QGraphicsItem *item );
157 virtual void endItemCommand( QGraphicsItem *item );
158 virtual void showStatusMessage(
const QString &message ) { Q_UNUSED( message ) }
159 virtual void hideAlignItems() {}
161 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode,
bool snapHorizontal =
true,
bool snapVertical =
true );
164 virtual void expandItemList(
const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected )
const;
166 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
override;
167 void hoverMoveEvent( QGraphicsSceneHoverEvent *event )
override;
168 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
override;
169 void mousePressEvent( QGraphicsSceneMouseEvent *event )
override;
170 void mouseMoveEvent( QGraphicsSceneMouseEvent *event )
override;
171 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
override;
174 void resetStatusBar();
177 bool selectionRotation(
double &rotation )
const;
180 void updateHandles();
183 void dragMouseMove( QPointF currentPosition,
bool lockMovement,
bool preventSnap );
186 void resizeMouseMove( QPointF currentPosition,
bool lockAspect,
bool fromCenter );
189 void rotateMouseMove( QPointF currentPosition,
bool snapToCommonAngles );
191 void setHandleSize(
double size );
197 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
200 QRectF selectionBounds()
const;
210 static void relativeResizeRect( QRectF &rectToResize,
const QRectF &boundsBefore,
const QRectF &boundsAfter );
221 static double relativePosition(
double position,
double beforeMin,
double beforeMax,
double afterMin,
double afterMax );
224 QGraphicsView *mView =
nullptr;
226 double mHandleSize = 10;
227 double mRotationHandleSize = 20;
228 QPainterPath mRotationHandlePath;
230 QSizeF mCursorOffset;
231 double mResizeMoveX = 0;
232 double mResizeMoveY = 0;
235 double mBeginHandleWidth = 0;
236 double mBeginHandleHeight = 0;
240 bool mRotationEnabled =
false;
242 QPointF mRotationCenter;
244 double mRotationBegin = 0.0;
246 double mRotationCurrent = 0.0;
248 double mRotationDelta = 0.0;
251 QPointF mMouseMoveStartPos;
254 bool mDoubleClickInProgress =
false;
257 bool mIsDragging =
false;
259 bool mIsResizing =
false;
261 bool mIsRotating =
false;
264 QPointF mBeginMouseEventPos;
267 QPointF mBeginHandlePos;
270 void drawHandles( QPainter *painter,
double rectHandlerSize );
273 void drawSelectedItemBounds( QPainter *painter );
279 double rectHandlerBorderTolerance()
const;
282 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
MouseHandlesAction
Action to be performed by the mouse handles.