QGIS API Documentation 3.99.0-Master (0c964c3d988)
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
22#include <memory>
23
24#include "qgis.h"
25#include "qgis_gui.h"
26
27#include <QGraphicsRectItem>
28#include <QObject>
29#include <QPointer>
30
31#define SIP_NO_FILE
32
33class QGraphicsView;
34class QInputEvent;
35
37
48class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsRectItem
49{
50 Q_OBJECT
51 public:
52 enum ItemPositionMode
53 {
54 UpperLeft,
55 UpperMiddle,
56 UpperRight,
57 MiddleLeft,
58 Middle,
59 MiddleRight,
60 LowerLeft,
61 LowerMiddle,
62 LowerRight
63 };
64
65 enum SnapGuideMode
66 {
67 Item,
68 Point
69 };
70
71 QgsGraphicsViewMouseHandles( QGraphicsView *view );
72
74 Qgis::MouseHandlesAction mouseActionForScenePos( QPointF sceneCoordPos );
75
77 bool isDragging() const { return mIsDragging; }
78
80 bool isResizing() const { return mIsResizing; }
81
87 bool isRotating() const { return mIsRotating; }
88
89 bool shouldBlockEvent( QInputEvent *event ) const;
90
92 void startMove( QPointF sceneCoordPos );
93
101 bool isRotationEnabled() const { return mRotationEnabled; }
102
111 void setRotationEnabled( bool enable );
112
120 void setCadMouseDigitizingModeEnabled( bool enable );
121
122 public slots:
123
125 void selectedItemSizeChanged();
126
128 void selectedItemRotationChanged();
129
130 protected:
131 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
132
134 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
135
136 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
137 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
138 virtual bool itemIsLocked( QGraphicsItem *item )
139 {
140 Q_UNUSED( item );
141 return false;
142 }
143 virtual bool itemIsGroupMember( QGraphicsItem *item )
144 {
145 Q_UNUSED( item );
146 return false;
147 }
148 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
149 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
150 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
151 virtual void rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY );
152 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
153 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
154
163 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
164
165 virtual void startMacroCommand( const QString &text );
166 virtual void endMacroCommand();
167 virtual void createItemCommand( QGraphicsItem *item );
168 virtual void endItemCommand( QGraphicsItem *item );
169 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
170 virtual void hideAlignItems() {}
172 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
173
175 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
176
177 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
178 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
179 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
180 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
181 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
182 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
183
184 //resets the layout designer status bar to the default message
185 void resetStatusBar();
186
188 bool selectionRotation( double &rotation ) const;
189
191 void updateHandles();
192
194 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
195
197 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
198
200 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
201
202 void setHandleSize( double size );
203
205 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
206
208 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
209
211 QRectF selectionBounds() const;
212
221 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
222
232 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
233
234 private:
235 QGraphicsView *mView = nullptr;
236
237 double mHandleSize = 10;
238 double mRotationHandleSize = 20;
239 QPainterPath mRotationHandlePath;
240
241 QSizeF mCursorOffset;
242 double mResizeMoveX = 0;
243 double mResizeMoveY = 0;
244
246 double mBeginHandleWidth = 0;
247 double mBeginHandleHeight = 0;
248
249 QRectF mResizeRect;
250
251 bool mCadMouseDigitizingMode = false;
252
253 bool mRotationEnabled = false;
255 QPointF mRotationCenter;
257 double mRotationBegin = 0.0;
259 double mRotationCurrent = 0.0;
261 double mRotationDelta = 0.0;
262
264 QPointF mMouseMoveStartPos;
265
267 bool mDoubleClickInProgress = false;
268
269
271 bool mIsDragging = false;
273 bool mIsDragStarting = false;
275 bool mIsResizing = false;
277 bool mIsRotating = false;
278
280 QPointF mBeginMouseEventPos;
281
283 QPointF mBeginHandlePos;
284
286 void drawHandles( QPainter *painter, double rectHandlerSize );
287
289 void drawSelectedItemBounds( QPainter *painter );
290
295 double rectHandlerBorderTolerance() const;
296
298 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
299
300 friend class QgsMapToolSelectAnnotation;
301};
302
304
305#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:6340
@ NoAction
No action.
Definition qgis.h:6355