QGIS API Documentation  2.99.0-Master (cd0ba91)
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 #define SIP_NO_FILE
21 
22 #include <QGraphicsRectItem>
23 #include <QObject>
24 #include <QPointer>
25 
26 #include "qgis_core.h"
27 
28 class QgsComposition;
29 class QgsComposerItem;
30 class QGraphicsView;
31 
38 class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectItem
39 {
40  Q_OBJECT
41  public:
42 
45  {
56  NoAction
57  };
58 
60  {
69  LowerRight
70  };
71 
73  {
75  Point
76  };
77 
79 
80  void setComposition( QgsComposition *c ) { mComposition = c; }
81  QgsComposition *composition() { return mComposition; }
82 
83  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
84 
86  QgsComposerMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
87 
89  bool isDragging() { return mIsDragging; }
90 
92  bool isResizing() { return mIsResizing; }
93 
94  protected:
95 
96  void mouseMoveEvent( QGraphicsSceneMouseEvent *event ) override;
97  void mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) override;
98  void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;
99  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
100  void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
101  void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
102 
103  public slots:
104 
106  void selectionChanged();
107 
109  void selectedItemSizeChanged();
110 
112  void selectedItemRotationChanged();
113 
114  private:
115 
116  QgsComposition *mComposition; //reference to composition
117  QPointer< QGraphicsView > mGraphicsView; //reference to QGraphicsView
118 
119  QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
121  QPointF mMouseMoveStartPos;
123  QPointF mLastMouseEventPos;
125  QPointF mBeginMouseEventPos;
127  QPointF mBeginHandlePos;
129  double mBeginHandleWidth;
130  double mBeginHandleHeight;
131 
132  QRectF mResizeRect;
133  double mResizeMoveX;
134  double mResizeMoveY;
135 
137  bool mIsDragging;
139  bool mIsResizing;
140 
142  QGraphicsLineItem *mHAlignSnapItem = nullptr;
143  QGraphicsLineItem *mVAlignSnapItem = nullptr;
144 
145  QSizeF mCursorOffset;
146 
148  QRectF selectionBounds() const;
149 
151  bool selectionRotation( double &rotation ) const;
152 
154  void updateHandles();
156  void drawHandles( QPainter *painter, double rectHandlerSize );
158  void drawSelectedItemBounds( QPainter *painter );
159 
163  double rectHandlerBorderTolerance();
164 
166  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
167 
169  QgsComposerMouseHandles::MouseAction mouseActionForPosition( QPointF itemCoordPos );
170 
172  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
173 
175  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
176 
178  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
179 
181  QGraphicsLineItem *hAlignSnapItem();
182  void deleteHAlignSnapItem();
184  QGraphicsLineItem *vAlignSnapItem();
185  void deleteVAlignSnapItem();
186  void deleteAlignItems();
187 
189  QPointF snapPoint( QPointF originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
191  QPointF alignItem( double &alignX, double &alignY, double unalignedX, double unalignedY );
193  QPointF alignPos( QPointF pos, double &alignX, double &alignY );
194 
195  //helper functions for item align
196  void collectAlignCoordinates( QMap< double, const QgsComposerItem * > &alignCoordsX, QMap< double, const QgsComposerItem * > &alignCoordsY );
197  bool nearestItem( const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue ) const;
198  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem * > &alignCoords, double &smallestDiff, double itemCoordOffset, double &itemCoord, double &alignCoord );
199 
200  //tries to return the current QGraphicsView attached to the composition
201  QGraphicsView *graphicsView();
202 
203  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
204  void setViewportCursor( Qt::CursorShape cursor );
205 
206  //resets the composer window status bar to the default message
207  void resetStatusBar();
208 };
209 
210 #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.