QGIS API Documentation 3.37.0-Master (49cede7946b)
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 <QGraphicsRectItem>
24#include <QObject>
25#include <QPointer>
26#include <memory>
27
28#include "qgis_gui.h"
29
30class QGraphicsView;
31class QInputEvent;
32
34
45class GUI_EXPORT QgsGraphicsViewMouseHandles: public QObject, public QGraphicsRectItem
46{
47 Q_OBJECT
48 public:
49
51 enum MouseAction
52 {
53 MoveItem,
54 ResizeUp,
55 ResizeDown,
56 ResizeLeft,
57 ResizeRight,
58 ResizeLeftUp,
59 ResizeRightUp,
60 ResizeLeftDown,
61 ResizeRightDown,
62 SelectItem,
63 NoAction
64 };
65
66 enum ItemPositionMode
67 {
68 UpperLeft,
69 UpperMiddle,
70 UpperRight,
71 MiddleLeft,
72 Middle,
73 MiddleRight,
74 LowerLeft,
75 LowerMiddle,
76 LowerRight
77 };
78
79 enum SnapGuideMode
80 {
81 Item,
82 Point
83 };
84
85 QgsGraphicsViewMouseHandles( QGraphicsView *view );
86
88 QgsGraphicsViewMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
89
91 bool isDragging() const { return mIsDragging; }
92
94 bool isResizing() const { return mIsResizing; }
95
96 bool shouldBlockEvent( QInputEvent *event ) const;
97
99 void startMove( QPointF sceneCoordPos );
100
101 public slots:
102
104 void selectedItemSizeChanged();
105
107 void selectedItemRotationChanged();
108
109 protected:
110
111 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes,
112 bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
113
115 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
116
117 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
118 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
119 virtual bool itemIsLocked( QGraphicsItem *item ) { Q_UNUSED( item ); return false; }
120 virtual bool itemIsGroupMember( QGraphicsItem *item ) { Q_UNUSED( item ); return false; }
121 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
122 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
123 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
124 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
125 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
126
135 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
136
137 virtual void startMacroCommand( const QString &text );
138 virtual void endMacroCommand();
139 virtual void createItemCommand( QGraphicsItem *item );
140 virtual void endItemCommand( QGraphicsItem *item );
141 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
142 virtual void hideAlignItems() {}
144 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
145
147 virtual void expandItemList( const QList< QGraphicsItem * > &items, QList< QGraphicsItem * > &collected ) const;
148
149 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
150 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
151 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
152 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
153 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
154 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
155
156 //resets the layout designer status bar to the default message
157 void resetStatusBar();
158
160 bool selectionRotation( double &rotation ) const;
161
163 void updateHandles();
164
166 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
167
169 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
170
171 void setHandleSize( double size );
172
174 MouseAction mouseActionForPosition( QPointF itemCoordPos );
175
177 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
178
180 QRectF selectionBounds() const;
181
190 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
191
201 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
202
203 private:
204
205 QGraphicsView *mView = nullptr;
206
207 double mHandleSize = 10;
208
209 QSizeF mCursorOffset;
210 double mResizeMoveX = 0;
211 double mResizeMoveY = 0;
212
214 double mBeginHandleWidth = 0;
215 double mBeginHandleHeight = 0;
216
217 QRectF mResizeRect;
218
220 QPointF mMouseMoveStartPos;
221
222 MouseAction mCurrentMouseMoveAction = NoAction;
223
225 bool mIsDragging = false;
227 bool mIsResizing = false;
228
230 QPointF mBeginMouseEventPos;
231
233 QPointF mBeginHandlePos;
234
236 void drawHandles( QPainter *painter, double rectHandlerSize );
237
239 void drawSelectedItemBounds( QPainter *painter );
240
245 double rectHandlerBorderTolerance();
246
248 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
249
250
251
252};
253
255
256#endif // QGSLAYOUTMOUSEHANDLES_H