QGIS API Documentation  2.99.0-Master (314842d)
qgscomposermousehandles.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermousehandles.h
3  -------------------
4  begin : September 2013
5  copyright : (C) 2013 by Nyall Dawson, Radim Blazek
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 QGSCOMPOSERMOUSEHANDLES_H
18 #define QGSCOMPOSERMOUSEHANDLES_H
19 
20 #include <QGraphicsRectItem>
21 #include <QObject>
22 #include <QPointer>
23 
24 #include "qgis_core.h"
25 
26 class QgsComposition;
27 class QgsComposerItem;
28 class QGraphicsView;
29 
35 class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectItem
36 {
37  Q_OBJECT
38  public:
39 
42  {
53  NoAction
54  };
55 
57  {
66  LowerRight
67  };
68 
70  {
72  Point
73  };
74 
76 
77  void setComposition( QgsComposition *c ) { mComposition = c; }
78  QgsComposition *composition() { return mComposition; }
79 
80  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
81 
83  QgsComposerMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
84 
86  bool isDragging() { return mIsDragging; }
87 
89  bool isResizing() { return mIsResizing; }
90 
91  protected:
92 
93  void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
94  void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
95  void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
96  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
97  void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
98  void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
99 
100  public slots:
101 
103  void selectionChanged();
104 
106  void selectedItemSizeChanged();
107 
109  void selectedItemRotationChanged();
110 
111  private:
112 
113  QgsComposition *mComposition; //reference to composition
114  QPointer< QGraphicsView > mGraphicsView; //reference to QGraphicsView
115 
116  QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
118  QPointF mMouseMoveStartPos;
120  QPointF mLastMouseEventPos;
122  QPointF mBeginMouseEventPos;
124  QPointF mBeginHandlePos;
126  double mBeginHandleWidth;
127  double mBeginHandleHeight;
128 
129  QRectF mResizeRect;
130  double mResizeMoveX;
131  double mResizeMoveY;
132 
134  bool mIsDragging;
136  bool mIsResizing;
137 
139  QGraphicsLineItem *mHAlignSnapItem = nullptr;
140  QGraphicsLineItem *mVAlignSnapItem = nullptr;
141 
142  QSizeF mCursorOffset;
143 
145  QRectF selectionBounds() const;
146 
148  bool selectionRotation( double &rotation ) const;
149 
151  void updateHandles();
153  void drawHandles( QPainter *painter, double rectHandlerSize );
155  void drawSelectedItemBounds( QPainter *painter );
156 
159  double rectHandlerBorderTolerance();
160 
162  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
163 
165  QgsComposerMouseHandles::MouseAction mouseActionForPosition( QPointF itemCoordPos );
166 
168  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
169 
171  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
172 
174  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
175 
177  QGraphicsLineItem *hAlignSnapItem();
178  void deleteHAlignSnapItem();
180  QGraphicsLineItem *vAlignSnapItem();
181  void deleteVAlignSnapItem();
182  void deleteAlignItems();
183 
185  QPointF snapPoint( QPointF originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
187  QPointF alignItem( double &alignX, double &alignY, double unalignedX, double unalignedY );
189  QPointF alignPos( QPointF pos, double &alignX, double &alignY );
190 
191  //helper functions for item align
192  void collectAlignCoordinates( QMap< double, const QgsComposerItem * > &alignCoordsX, QMap< double, const QgsComposerItem * > &alignCoordsY );
193  bool nearestItem( const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue ) const;
194  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem * > &alignCoords, double &smallestDiff, double itemCoordOffset, double &itemCoord, double &alignCoord );
195 
196  //tries to return the current QGraphicsView attached to the composition
197  QGraphicsView *graphicsView();
198 
199  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
200  void setViewportCursor( Qt::CursorShape cursor );
201 
202  //resets the composer window status bar to the default message
203  void resetStatusBar();
204 };
205 
206 #endif // QGSCOMPOSERMOUSEHANDLES_H
A item that forms part of a map composition.
bool isDragging()
Returns true is user is currently dragging the handles.
MouseAction
Describes the action (move or resize in different directon) to be done during mouse move...
bool isResizing()
Returns true is user is currently resizing with the handles.
Graphics scene for map printing.
void setComposition(QgsComposition *c)
Handles drawing of selection outlines and mouse handles.