QGIS API Documentation 3.99.0-Master (a26b91b364d)
qgsgraphicsviewmousehandles.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgraphicsviewmousehandles.h
3 -----------------------
4 begin : March 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall.dawson@gmail.com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSGRAPHICSVIEWMOUSEHANDLES_H
18#define QGSGRAPHICSVIEWMOUSEHANDLES_H
19
20// We don't want to expose this in the public API
21#define SIP_NO_FILE
22
23#include <QGraphicsRectItem>
24#include <QObject>
25#include <QPointer>
26#include <memory>
27
28#include "qgis.h"
29#include "qgis_gui.h"
30
31class QGraphicsView;
32class QInputEvent;
33
35
46class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsRectItem
47{
48 Q_OBJECT
49 public:
50 enum ItemPositionMode
51 {
52 UpperLeft,
53 UpperMiddle,
54 UpperRight,
55 MiddleLeft,
56 Middle,
57 MiddleRight,
58 LowerLeft,
59 LowerMiddle,
60 LowerRight
61 };
62
63 enum SnapGuideMode
64 {
65 Item,
66 Point
67 };
68
69 QgsGraphicsViewMouseHandles( QGraphicsView *view );
70
72 Qgis::MouseHandlesAction mouseActionForScenePos( QPointF sceneCoordPos );
73
75 bool isDragging() const { return mIsDragging; }
76
78 bool isResizing() const { return mIsResizing; }
79
85 bool isRotating() const { return mIsRotating; }
86
87 bool shouldBlockEvent( QInputEvent *event ) const;
88
90 void startMove( QPointF sceneCoordPos );
91
99 bool isRotationEnabled() const { return mRotationEnabled; }
100
109 void setRotationEnabled( bool enable );
110
111 public slots:
112
114 void selectedItemSizeChanged();
115
117 void selectedItemRotationChanged();
118
119 protected:
120 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
121
123 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
124
125 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
126 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
127 virtual bool itemIsLocked( QGraphicsItem *item )
128 {
129 Q_UNUSED( item );
130 return false;
131 }
132 virtual bool itemIsGroupMember( QGraphicsItem *item )
133 {
134 Q_UNUSED( item );
135 return false;
136 }
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;
143
152 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
153
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 );
162
164 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
165
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;
172
173 //resets the layout designer status bar to the default message
174 void resetStatusBar();
175
177 bool selectionRotation( double &rotation ) const;
178
180 void updateHandles();
181
183 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
184
186 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
187
189 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
190
191 void setHandleSize( double size );
192
194 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
195
197 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
198
200 QRectF selectionBounds() const;
201
210 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
211
221 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
222
223 private:
224 QGraphicsView *mView = nullptr;
225
226 double mHandleSize = 10;
227 double mRotationHandleSize = 20;
228 QPainterPath mRotationHandlePath;
229
230 QSizeF mCursorOffset;
231 double mResizeMoveX = 0;
232 double mResizeMoveY = 0;
233
235 double mBeginHandleWidth = 0;
236 double mBeginHandleHeight = 0;
237
238 QRectF mResizeRect;
239
240 bool mRotationEnabled = false;
242 QPointF mRotationCenter;
244 double mRotationBegin = 0.0;
246 double mRotationCurrent = 0.0;
248 double mRotationDelta = 0.0;
249
251 QPointF mMouseMoveStartPos;
252
254 bool mDoubleClickInProgress = false;
255
257 bool mIsDragging = false;
259 bool mIsResizing = false;
261 bool mIsRotating = false;
262
264 QPointF mBeginMouseEventPos;
265
267 QPointF mBeginHandlePos;
268
270 void drawHandles( QPainter *painter, double rectHandlerSize );
271
273 void drawSelectedItemBounds( QPainter *painter );
274
279 double rectHandlerBorderTolerance() const;
280
282 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
283};
284
286
287#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:5890