QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
112 public slots:
113
115 void selectedItemSizeChanged();
116
118 void selectedItemRotationChanged();
119
120 protected:
121 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
122
124 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
125
126 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
127 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
128 virtual bool itemIsLocked( QGraphicsItem *item )
129 {
130 Q_UNUSED( item );
131 return false;
132 }
133 virtual bool itemIsGroupMember( QGraphicsItem *item )
134 {
135 Q_UNUSED( item );
136 return false;
137 }
138 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
139 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
140 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
141 virtual void rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY );
142 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
143 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
144
153 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
154
155 virtual void startMacroCommand( const QString &text );
156 virtual void endMacroCommand();
157 virtual void createItemCommand( QGraphicsItem *item );
158 virtual void endItemCommand( QGraphicsItem *item );
159 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
160 virtual void hideAlignItems() {}
162 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
163
165 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
166
167 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
168 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
169 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
170 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
171 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
172 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
173
174 //resets the layout designer status bar to the default message
175 void resetStatusBar();
176
178 bool selectionRotation( double &rotation ) const;
179
181 void updateHandles();
182
184 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
185
187 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
188
190 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
191
192 void setHandleSize( double size );
193
195 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
196
198 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
199
201 QRectF selectionBounds() const;
202
211 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
212
222 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
223
224 private:
225 QGraphicsView *mView = nullptr;
226
227 double mHandleSize = 10;
228 double mRotationHandleSize = 20;
229 QPainterPath mRotationHandlePath;
230
231 QSizeF mCursorOffset;
232 double mResizeMoveX = 0;
233 double mResizeMoveY = 0;
234
236 double mBeginHandleWidth = 0;
237 double mBeginHandleHeight = 0;
238
239 QRectF mResizeRect;
240
241 bool mRotationEnabled = false;
243 QPointF mRotationCenter;
245 double mRotationBegin = 0.0;
247 double mRotationCurrent = 0.0;
249 double mRotationDelta = 0.0;
250
252 QPointF mMouseMoveStartPos;
253
255 bool mDoubleClickInProgress = false;
256
258 bool mIsDragging = false;
260 bool mIsResizing = false;
262 bool mIsRotating = false;
263
265 QPointF mBeginMouseEventPos;
266
268 QPointF mBeginHandlePos;
269
271 void drawHandles( QPainter *painter, double rectHandlerSize );
272
274 void drawSelectedItemBounds( QPainter *painter );
275
280 double rectHandlerBorderTolerance() const;
281
283 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
284};
285
287
288#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:6024
@ NoAction
No action.
Definition qgis.h:6039