QGIS API Documentation  3.6.0-Noosa (5873452)
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 #define SIP_NO_FILE
21 
22 #include <QGraphicsRectItem>
23 #include <QObject>
24 #include <QPointer>
25 #include <memory>
26 
27 #include "qgis_gui.h"
28 
29 class QgsLayout;
30 class QGraphicsView;
31 class QgsLayoutView;
32 class QgsLayoutItem;
33 class QInputEvent;
34 
36 
47 class GUI_EXPORT QgsLayoutMouseHandles: public QObject, public QGraphicsRectItem
48 {
49  Q_OBJECT
50  public:
51 
53  enum MouseAction
54  {
55  MoveItem,
56  ResizeUp,
57  ResizeDown,
58  ResizeLeft,
59  ResizeRight,
60  ResizeLeftUp,
61  ResizeRightUp,
62  ResizeLeftDown,
63  ResizeRightDown,
64  SelectItem,
65  NoAction
66  };
67 
68  enum ItemPositionMode
69  {
70  UpperLeft,
71  UpperMiddle,
72  UpperRight,
73  MiddleLeft,
74  Middle,
75  MiddleRight,
76  LowerLeft,
77  LowerMiddle,
78  LowerRight
79  };
80 
81  enum SnapGuideMode
82  {
83  Item,
84  Point
85  };
86 
87  QgsLayoutMouseHandles( QgsLayout *layout, QgsLayoutView *view );
88 
93  void setLayout( QgsLayout *layout ) { mLayout = layout; }
94 
99  QgsLayout *layout() { return mLayout; }
100 
101  void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
102 
104  QgsLayoutMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
105 
107  bool isDragging() const { return mIsDragging; }
108 
110  bool isResizing() const { return mIsResizing; }
111 
112  bool shouldBlockEvent( QInputEvent *event ) const;
113 
114  protected:
115 
116  void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
117  void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
118  void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
119  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
120  void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
121  void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
122 
123  public slots:
124 
126  void selectionChanged();
127 
129  void selectedItemSizeChanged();
130 
132  void selectedItemRotationChanged();
133 
134  private:
135 
136  QgsLayout *mLayout = nullptr;
137  QPointer< QgsLayoutView > mView;
138 
139  MouseAction mCurrentMouseMoveAction = NoAction;
141  QPointF mMouseMoveStartPos;
143  QPointF mLastMouseEventPos;
145  QPointF mBeginMouseEventPos;
147  QPointF mBeginHandlePos;
149  double mBeginHandleWidth = 0;
150  double mBeginHandleHeight = 0;
151 
152  QRectF mResizeRect;
153  double mResizeMoveX = 0;
154  double mResizeMoveY = 0;
155 
157  bool mIsDragging = false;
159  bool mIsResizing = false;
160 
162  QGraphicsLineItem *mHorizontalSnapLine = nullptr;
163  QGraphicsLineItem *mVerticalSnapLine = nullptr;
164 
165  QSizeF mCursorOffset;
166 
168  QRectF selectionBounds() const;
169 
171  bool selectionRotation( double &rotation ) const;
172 
174  void updateHandles();
176  void drawHandles( QPainter *painter, double rectHandlerSize );
178  void drawSelectedItemBounds( QPainter *painter );
179 
183  double rectHandlerBorderTolerance();
184 
186  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
187 
189  MouseAction mouseActionForPosition( QPointF itemCoordPos );
190 
192  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
193 
195  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
196 
198  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
199 
200  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
201  void setViewportCursor( Qt::CursorShape cursor );
202 
203  //resets the layout designer status bar to the default message
204  void resetStatusBar();
205 
207  QPointF snapPoint( QPointF originalPoint, SnapGuideMode mode, bool snapHorizontal = true, bool snapVertical = true );
208 
209  void hideAlignItems();
210 
212  void collectItems( QList< QgsLayoutItem * > items, QList< QgsLayoutItem * > &collected );
213 
214 };
215 
217 
218 #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