QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgslayoutmousehandles.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutmousehandles.h
3  -----------------------
4  begin : September 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : [email protected]
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 QGSLAYOUTMOUSEHANDLES_H
18 #define QGSLAYOUTMOUSEHANDLES_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 
30 class QgsLayout;
31 class QGraphicsView;
32 class QgsLayoutView;
33 class QgsLayoutItem;
34 class QInputEvent;
35 
37 
48 class GUI_EXPORT QgsLayoutMouseHandles: public QObject, public QGraphicsRectItem
49 {
50  Q_OBJECT
51  public:
52 
54  enum MouseAction
55  {
56  MoveItem,
57  ResizeUp,
58  ResizeDown,
59  ResizeLeft,
60  ResizeRight,
61  ResizeLeftUp,
62  ResizeRightUp,
63  ResizeLeftDown,
64  ResizeRightDown,
65  SelectItem,
66  NoAction
67  };
68 
69  enum ItemPositionMode
70  {
71  UpperLeft,
72  UpperMiddle,
73  UpperRight,
74  MiddleLeft,
75  Middle,
76  MiddleRight,
77  LowerLeft,
78  LowerMiddle,
79  LowerRight
80  };
81 
82  enum SnapGuideMode
83  {
84  Item,
85  Point
86  };
87 
88  QgsLayoutMouseHandles( QgsLayout *layout, QgsLayoutView *view );
89 
94  void setLayout( QgsLayout *layout ) { mLayout = layout; }
95 
100  QgsLayout *layout() { return mLayout; }
101 
102  void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
103 
105  QgsLayoutMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
106 
108  bool isDragging() const { return mIsDragging; }
109 
111  bool isResizing() const { return mIsResizing; }
112 
113  bool shouldBlockEvent( QInputEvent *event ) const;
114 
115  protected:
116 
117  void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
118  void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
119  void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
120  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
121  void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
122  void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
123 
124  public slots:
125 
127  void selectionChanged();
128 
130  void selectedItemSizeChanged();
131 
133  void selectedItemRotationChanged();
134 
135  private:
136 
137  QgsLayout *mLayout = nullptr;
138  QPointer< QgsLayoutView > mView;
139 
140  MouseAction mCurrentMouseMoveAction = NoAction;
142  QPointF mMouseMoveStartPos;
144  QPointF mLastMouseEventPos;
146  QPointF mBeginMouseEventPos;
148  QPointF mBeginHandlePos;
150  double mBeginHandleWidth = 0;
151  double mBeginHandleHeight = 0;
152 
153  QRectF mResizeRect;
154  double mResizeMoveX = 0;
155  double mResizeMoveY = 0;
156 
158  bool mIsDragging = false;
160  bool mIsResizing = false;
161 
163  QGraphicsLineItem *mHorizontalSnapLine = nullptr;
164  QGraphicsLineItem *mVerticalSnapLine = nullptr;
165 
166  QSizeF mCursorOffset;
167 
169  QRectF selectionBounds() const;
170 
172  bool selectionRotation( double &rotation ) const;
173 
175  void updateHandles();
177  void drawHandles( QPainter *painter, double rectHandlerSize );
179  void drawSelectedItemBounds( QPainter *painter );
180 
184  double rectHandlerBorderTolerance();
185 
187  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
188 
190  MouseAction mouseActionForPosition( QPointF itemCoordPos );
191 
193  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
194 
196  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
197 
199  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
200 
201  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
202  void setViewportCursor( Qt::CursorShape cursor );
203 
204  //resets the layout designer status bar to the default message
205  void resetStatusBar();
206 
208  QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
209 
210  void hideAlignItems();
211 
213  void collectItems( const QList< QgsLayoutItem * > &items, QList< QgsLayoutItem * > &collected );
214 
215 };
216 
218 
219 #endif // QGSLAYOUTMOUSEHANDLES_H
Base class for graphical items within a QgsLayout.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49