QGIS API Documentation 4.1.0-Master (d6fb7a379fb)
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
129 bool isResizeEnabled() const { return mResizeEnabled; }
130
139 void setResizeEnabled( bool enable );
140
141 public slots:
142
144 void selectedItemSizeChanged();
145
147 void selectedItemRotationChanged();
148
149 protected:
150 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
151
153 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
154
155 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
156 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
157 virtual bool itemIsLocked( QGraphicsItem *item )
158 {
159 Q_UNUSED( item );
160 return false;
161 }
162 virtual bool itemIsGroupMember( QGraphicsItem *item )
163 {
164 Q_UNUSED( item );
165 return false;
166 }
167 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
168 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
169 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
170 virtual void rotateItem( QGraphicsItem *item, double deltaDegree, double deltaCenterX, double deltaCenterY );
171 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
172 virtual void setItemRect( QGraphicsItem *item, QRectF rect );
173
182 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
183
184 virtual void startMacroCommand( const QString &text );
185 virtual void endMacroCommand();
186 virtual void createItemCommand( QGraphicsItem *item );
187 virtual void endItemCommand( QGraphicsItem *item );
188 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
189 virtual void hideAlignItems() {}
191 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
192
194 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
195
196 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
197 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
198 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
199 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
200 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
201 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
202
203 //resets the layout designer status bar to the default message
204 void resetStatusBar();
205
207 bool selectionRotation( double &rotation ) const;
208
210 void updateHandles();
211
213 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
214
216 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
217
219 void rotateMouseMove( QPointF currentPosition, bool snapToCommonAngles );
220
221 void setHandleSize( double size );
222
224 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
225
227 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
228
230 QRectF selectionBounds() const;
231
240 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
241
251 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
252
253 private:
254 QGraphicsView *mView = nullptr;
255
256 double mHandleSize = 10;
257 double mRotationHandleSize = 20;
258 QPainterPath mRotationHandlePath;
259
260 QSizeF mCursorOffset;
261 double mResizeMoveX = 0;
262 double mResizeMoveY = 0;
263
265 double mBeginHandleWidth = 0;
266 double mBeginHandleHeight = 0;
267
268 QRectF mResizeRect;
269
270 bool mCadMouseDigitizingMode = false;
271
272 bool mRotationEnabled = false;
273 bool mResizeEnabled = true;
275 QPointF mRotationCenter;
277 double mRotationBegin = 0.0;
279 double mRotationCurrent = 0.0;
281 double mRotationDelta = 0.0;
282
284 QPointF mMouseMoveStartPos;
285
287 bool mDoubleClickInProgress = false;
288
289
291 bool mIsDragging = false;
293 bool mIsDragStarting = false;
295 bool mIsResizing = false;
297 bool mIsRotating = false;
298
300 QPointF mBeginMouseEventPos;
301
303 QPointF mBeginHandlePos;
304
306 void drawHandles( QPainter *painter, double rectHandlerSize );
307
309 void drawSelectedItemBounds( QPainter *painter );
310
315 double rectHandlerBorderTolerance() const;
316
318 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
319
320 friend class QgsMapToolSelectAnnotation;
321};
322
324
325#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:6594
@ NoAction
No action.
Definition qgis.h:6609