QGIS API Documentation 4.3.0-Master (91d4a333d5d)
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
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
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
129 bool isResizeEnabled() const { return mResizeEnabled; }
130
139 void setResizeEnabled( bool enable );
140
146 void reset();
147
148 public slots:
149
151 void selectedItemSizeChanged();
152
154 void selectedItemRotationChanged();
155
156 protected:
157 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
158
160 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
161
162 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
163 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
164 virtual bool itemIsLocked( QGraphicsItem *item )
165 {
166 Q_UNUSED( item );
167 return false;
168 }
169 virtual bool itemIsGroupMember( QGraphicsItem *item )
170 {
171 Q_UNUSED( item );
172 return false;
173 }
174 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
175 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
176 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
177 virtual void rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY );
178 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
179 virtual void setItemRect( QGraphicsItem *item, QRectF rect );
180
189 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
190
191 virtual void startMacroCommand( const QString &text );
192 virtual void endMacroCommand();
193 virtual void createItemCommand( QGraphicsItem *item );
194 virtual void endItemCommand( QGraphicsItem *item );
195 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
196 virtual void hideAlignItems() {}
198 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
199
201 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
202
203 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
204 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
205 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
206 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
207 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
208 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
209
210 //resets the layout designer status bar to the default message
211 void resetStatusBar();
212
214 bool selectionRotation( double &rotation ) const;
215
217 void updateHandles();
218
220 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
221
223 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
224
226 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
227
228 void setHandleSize( double size );
229
231 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
232
234 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
235
237 QRectF selectionBounds() const;
238
247 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
248
258 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
259
260 private:
261 QGraphicsView *mView = nullptr;
262
263 double mHandleSize = 10;
264 double mRotationHandleSize = 20;
265 QPainterPath mRotationHandlePath;
266
267 QSizeF mCursorOffset;
268 double mResizeMoveX = 0;
269 double mResizeMoveY = 0;
270
272 double mBeginHandleWidth = 0;
273 double mBeginHandleHeight = 0;
274
275 QRectF mResizeRect;
276
277 bool mCadMouseDigitizingMode = false;
278
279 bool mRotationEnabled = false;
280 bool mResizeEnabled = true;
282 QPointF mRotationCenter;
284 double mRotationBegin = 0.0;
286 double mRotationCurrent = 0.0;
288 double mRotationDelta = 0.0;
289
291 QPointF mMouseMoveStartPos;
292
294 bool mDoubleClickInProgress = false;
295
296
298 bool mIsDragging = false;
300 bool mIsDragStarting = false;
302 bool mIsResizing = false;
304 bool mIsRotating = false;
305
307 QPointF mBeginMouseEventPos;
308
310 QPointF mBeginHandlePos;
311
313 void drawHandles( QPainter *painter, double rectHandlerSize );
314
316 void drawSelectedItemBounds( QPainter *painter );
317
322 double rectHandlerBorderTolerance() const;
323
325 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
326
327 friend class QgsMapToolSelectAnnotation;
328};
329
331
332#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:6934
@ NoAction
No action.
Definition qgis.h:6949