QGIS API Documentation  2.99.0-Master (5753576)
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 
23 #include "qgis_core.h"
24 
25 class QgsComposition;
26 class QgsComposerItem;
27 class QGraphicsView;
28 
34 class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectItem
35 {
36  Q_OBJECT
37  public:
38 
41  {
52  NoAction
53  };
54 
56  {
65  LowerRight
66  };
67 
69  {
71  Point
72  };
73 
75 
76  void setComposition( QgsComposition* c ) { mComposition = c; }
77  QgsComposition* composition() { return mComposition; }
78 
79  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
80 
82  QgsComposerMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
83 
85  bool isDragging() { return mIsDragging; }
86 
88  bool isResizing() { return mIsResizing; }
89 
90  protected:
91 
92  void mouseMoveEvent( QGraphicsSceneMouseEvent* event ) override;
93  void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) override;
94  void mousePressEvent( QGraphicsSceneMouseEvent* event ) override;
95  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event ) override;
96  void hoverMoveEvent( QGraphicsSceneHoverEvent * event ) override;
97  void hoverLeaveEvent( QGraphicsSceneHoverEvent * event ) override;
98 
99  public slots:
100 
102  void selectionChanged();
103 
105  void selectedItemSizeChanged();
106 
108  void selectedItemRotationChanged();
109 
110  private:
111 
112  QgsComposition* mComposition; //reference to composition
113  QGraphicsView* mGraphicsView; //reference to QGraphicsView
114 
115  QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
117  QPointF mMouseMoveStartPos;
119  QPointF mLastMouseEventPos;
121  QPointF mBeginMouseEventPos;
123  QPointF mBeginHandlePos;
125  double mBeginHandleWidth;
126  double mBeginHandleHeight;
127 
128  QRectF mResizeRect;
129  double mResizeMoveX;
130  double mResizeMoveY;
131 
133  bool mIsDragging;
135  bool mIsResizing;
136 
138  QGraphicsLineItem* mHAlignSnapItem;
139  QGraphicsLineItem* mVAlignSnapItem;
140 
141  QSizeF mCursorOffset;
142 
144  QRectF selectionBounds() const;
145 
147  bool selectionRotation( double & rotation ) const;
148 
150  void updateHandles();
152  void drawHandles( QPainter* painter, double rectHandlerSize );
154  void drawSelectedItemBounds( QPainter* painter );
155 
158  double rectHandlerBorderTolerance();
159 
161  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
162 
164  QgsComposerMouseHandles::MouseAction mouseActionForPosition( QPointF itemCoordPos );
165 
167  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
168 
170  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
171 
173  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
174 
176  QGraphicsLineItem* hAlignSnapItem();
177  void deleteHAlignSnapItem();
179  QGraphicsLineItem* vAlignSnapItem();
180  void deleteVAlignSnapItem();
181  void deleteAlignItems();
182 
184  QPointF snapPoint( QPointF originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
186  QPointF alignItem( double& alignX, double& alignY, double unalignedX, double unalignedY );
188  QPointF alignPos( QPointF pos, double& alignX, double& alignY );
189 
190  //helper functions for item align
191  void collectAlignCoordinates( QMap< double, const QgsComposerItem* >& alignCoordsX, QMap< double, const QgsComposerItem* >& alignCoordsY );
192  bool nearestItem( const QMap< double, const QgsComposerItem* >& coords, double value, double& nearestValue ) const;
193  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem* >& alignCoords, double& smallestDiff, double itemCoordOffset, double& itemCoord, double& alignCoord );
194 
195  //tries to return the current QGraphicsView attached to the composition
196  QGraphicsView* graphicsView();
197 
198  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
199  void setViewportCursor( Qt::CursorShape cursor );
200 
201  //resets the composer window status bar to the default message
202  void resetStatusBar();
203 };
204 
205 #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.