QGIS API Documentation 3.41.0-Master (cea29feecf2)
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.h"
29#include "qgis_gui.h"
30
31class QGraphicsView;
32class QInputEvent;
33
35
46class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsRectItem
47{
48 Q_OBJECT
49 public:
50 enum ItemPositionMode
51 {
52 UpperLeft,
53 UpperMiddle,
54 UpperRight,
55 MiddleLeft,
56 Middle,
57 MiddleRight,
58 LowerLeft,
59 LowerMiddle,
60 LowerRight
61 };
62
63 enum SnapGuideMode
64 {
65 Item,
66 Point
67 };
68
69 QgsGraphicsViewMouseHandles( QGraphicsView *view );
70
72 Qgis::MouseHandlesAction mouseActionForScenePos( QPointF sceneCoordPos );
73
75 bool isDragging() const { return mIsDragging; }
76
78 bool isResizing() const { return mIsResizing; }
79
80 bool shouldBlockEvent( QInputEvent *event ) const;
81
83 void startMove( QPointF sceneCoordPos );
84
85 public slots:
86
88 void selectedItemSizeChanged();
89
91 void selectedItemRotationChanged();
92
93 protected:
94 void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
95
97 virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
98
99 virtual QList<QGraphicsItem *> sceneItemsAtPoint( QPointF scenePoint ) = 0;
100 virtual QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const = 0;
101 virtual bool itemIsLocked( QGraphicsItem *item )
102 {
103 Q_UNUSED( item );
104 return false;
105 }
106 virtual bool itemIsGroupMember( QGraphicsItem *item )
107 {
108 Q_UNUSED( item );
109 return false;
110 }
111 virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
112 virtual QRectF storedItemRect( QGraphicsItem *item ) const;
113 virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
114 virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
115 virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
116
125 virtual QRectF previewSetItemRect( QGraphicsItem *item, QRectF rect );
126
127 virtual void startMacroCommand( const QString &text );
128 virtual void endMacroCommand();
129 virtual void createItemCommand( QGraphicsItem *item );
130 virtual void endItemCommand( QGraphicsItem *item );
131 virtual void showStatusMessage( const QString &message ) { Q_UNUSED( message ) }
132 virtual void hideAlignItems() {}
134 virtual QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
135
137 virtual void expandItemList( const QList<QGraphicsItem *> &items, QList<QGraphicsItem *> &collected ) const;
138
139 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
140 void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
141 void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
142 void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
143 void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
144 void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
145
146 //resets the layout designer status bar to the default message
147 void resetStatusBar();
148
150 bool selectionRotation( double &rotation ) const;
151
153 void updateHandles();
154
156 void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
157
159 void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
160
161 void setHandleSize( double size );
162
164 Qgis::MouseHandlesAction mouseActionForPosition( QPointF itemCoordPos );
165
167 QSizeF calcCursorEdgeOffset( QPointF cursorPos );
168
170 QRectF selectionBounds() const;
171
180 static void relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter );
181
191 static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );
192
193 private:
194 QGraphicsView *mView = nullptr;
195
196 double mHandleSize = 10;
197
198 QSizeF mCursorOffset;
199 double mResizeMoveX = 0;
200 double mResizeMoveY = 0;
201
203 double mBeginHandleWidth = 0;
204 double mBeginHandleHeight = 0;
205
206 QRectF mResizeRect;
207
209 QPointF mMouseMoveStartPos;
210
212 bool mDoubleClickInProgress = false;
213
215 bool mIsDragging = false;
217 bool mIsResizing = false;
218
220 QPointF mBeginMouseEventPos;
221
223 QPointF mBeginHandlePos;
224
226 void drawHandles( QPainter *painter, double rectHandlerSize );
227
229 void drawSelectedItemBounds( QPainter *painter );
230
235 double rectHandlerBorderTolerance();
236
238 Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
239};
240
242
243#endif // QGSLAYOUTMOUSEHANDLES_H
MouseHandlesAction
Action to be performed by the mouse handles.
Definition qgis.h:5667