QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
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
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 <memory>
24
25#include "qgis.h"
26#include "qgis_gui.h"
27
28#include <QGraphicsRectItem>
29#include <QObject>
30#include <QPointer>
31
32class QGraphicsView;
33class QInputEvent;
34
36
47class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsRectItem
48{
49 Q_OBJECT
50 public:
51 enum ItemPositionMode
52 {
53 UpperLeft,
54 UpperMiddle,
55 UpperRight,
56 MiddleLeft,
57 Middle,
58 MiddleRight,
59 LowerLeft,
60 LowerMiddle,
61 LowerRight
62 };
63
64 enum SnapGuideMode
65 {
66 Item,
67 Point
68 };
69
70 QgsGraphicsViewMouseHandles( QGraphicsView *view );
71
73 Qgis::MouseHandlesAction mouseActionForScenePos( QPointF sceneCoordPos );
74
76 bool isDragging() const { return mIsDragging; }
77
79 bool isResizing() const { return mIsResizing; }
80
86 bool isRotating() const { return mIsRotating; }
87
88 bool shouldBlockEvent( QInputEvent *event ) const;
89
91 void startMove( QPointF sceneCoordPos );
92
100 bool isRotationEnabled() const { return mRotationEnabled; }
101
110 void setRotationEnabled( bool enable );
111
119 void setCadMouseDigitizingModeEnabled( bool enable );
120
121 public slots:
122
124 void selectedItemSizeChanged();
125
127 void selectedItemRotationChanged();
128
129 protected:
130 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
131
133 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
134
135 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
136 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
137 virtual bool itemIsLocked( QGraphicsItem *item )
138 {
139 Q_UNUSED( item );
140 return false;
141 }
142 virtual bool itemIsGroupMember( QGraphicsItem *item )
143 {
144 Q_UNUSED( item );
145 return false;
146 }
147 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
148 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
149 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
150 virtual void rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY );
151 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
152 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
153
162 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
163
164 virtual void startMacroCommand( const QString &text );
165 virtual void endMacroCommand();
166 virtual void createItemCommand( QGraphicsItem *item );
167 virtual void endItemCommand( QGraphicsItem *item );
168 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
169 virtual void hideAlignItems() {}
171 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
172
174 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
175
176 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
177 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
178 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
179 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
180 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
181 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
182
183 //resets the layout designer status bar to the default message
184 void resetStatusBar();
185
187 bool selectionRotation( double &rotation ) const;
188
190 void updateHandles();
191
193 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
194
196 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
197
199 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
200
201 void setHandleSize( double size );
202
204 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
205
207 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
208
210 QRectF selectionBounds() const;
211
220 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
221
231 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
232
233 private:
234 QGraphicsView *mView = nullptr;
235
236 double mHandleSize = 10;
237 double mRotationHandleSize = 20;
238 QPainterPath mRotationHandlePath;
239
240 QSizeF mCursorOffset;
241 double mResizeMoveX = 0;
242 double mResizeMoveY = 0;
243
245 double mBeginHandleWidth = 0;
246 double mBeginHandleHeight = 0;
247
248 QRectF mResizeRect;
249
250 bool mCadMouseDigitizingMode = false;
251
252 bool mRotationEnabled = false;
254 QPointF mRotationCenter;
256 double mRotationBegin = 0.0;
258 double mRotationCurrent = 0.0;
260 double mRotationDelta = 0.0;
261
263 QPointF mMouseMoveStartPos;
264
266 bool mDoubleClickInProgress = false;
267
268
270 bool mIsDragging = false;
272 bool mIsDragStarting = false;
274 bool mIsResizing = false;
276 bool mIsRotating = false;
277
279 QPointF mBeginMouseEventPos;
280
282 QPointF mBeginHandlePos;
283
285 void drawHandles( QPainter *painter, double rectHandlerSize );
286
288 void drawSelectedItemBounds( QPainter *painter );
289
294 double rectHandlerBorderTolerance() const;
295
297 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
298
299 friend class QgsMapToolSelectAnnotation;
300};
301
303
304#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:6325
@ NoAction
No action.
Definition qgis.h:6340