QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 class QgsComposition;
24 class QgsComposerItem;
25 class QGraphicsView;
26 
32 class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectItem
33 {
34  Q_OBJECT
35  public:
36 
39  {
50  NoAction
51  };
52 
54  {
63  LowerRight
64  };
65 
67  {
69  Point
70  };
71 
73  virtual ~QgsComposerMouseHandles();
74 
75  void setComposition( QgsComposition* c ) { mComposition = c; }
76  QgsComposition* composition() { return mComposition; }
77 
78  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
79 
81  QgsComposerMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
82 
84  bool isDragging() { return mIsDragging; }
85 
87  bool isResizing() { return mIsResizing; }
88 
89  protected:
90 
91  void mouseMoveEvent( QGraphicsSceneMouseEvent* event ) override;
92  void mouseReleaseEvent( QGraphicsSceneMouseEvent* event ) override;
93  void mousePressEvent( QGraphicsSceneMouseEvent* event ) override;
94  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event ) override;
95  void hoverMoveEvent( QGraphicsSceneHoverEvent * event ) override;
96  void hoverLeaveEvent( QGraphicsSceneHoverEvent * event ) override;
97 
98  public slots:
99 
101  void selectionChanged();
102 
104  void selectedItemSizeChanged();
105 
107  void selectedItemRotationChanged();
108 
109  private:
110 
111  QgsComposition* mComposition; //reference to composition
112  QGraphicsView* mGraphicsView; //reference to QGraphicsView
113 
114  QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
116  QPointF mMouseMoveStartPos;
118  QPointF mLastMouseEventPos;
120  QPointF mBeginMouseEventPos;
122  QPointF mBeginHandlePos;
124  double mBeginHandleWidth;
125  double mBeginHandleHeight;
126 
127  QRectF mResizeRect;
128  double mResizeMoveX;
129  double mResizeMoveY;
130 
132  bool mIsDragging;
134  bool mIsResizing;
135 
137  QGraphicsLineItem* mHAlignSnapItem;
138  QGraphicsLineItem* mVAlignSnapItem;
139 
140  QSizeF mCursorOffset;
141 
143  QRectF selectionBounds() const;
144 
146  bool selectionRotation( double & rotation ) const;
147 
149  void updateHandles();
151  void drawHandles( QPainter* painter, double rectHandlerSize );
153  void drawSelectedItemBounds( QPainter* painter );
154 
157  double rectHandlerBorderTolerance();
158 
160  Qt::CursorShape cursorForPosition( QPointF itemCoordPos );
161 
163  QgsComposerMouseHandles::MouseAction mouseActionForPosition( QPointF itemCoordPos );
164 
166  void dragMouseMove( QPointF currentPosition, bool lockMovement, bool preventSnap );
167 
169  QSizeF calcCursorEdgeOffset( QPointF cursorPos );
170 
172  void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );
173 
175  QGraphicsLineItem* hAlignSnapItem();
176  void deleteHAlignSnapItem();
178  QGraphicsLineItem* vAlignSnapItem();
179  void deleteVAlignSnapItem();
180  void deleteAlignItems();
181 
183  QPointF snapPoint( QPointF originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
185  QPointF alignItem( double& alignX, double& alignY, double unalignedX, double unalignedY );
187  QPointF alignPos( QPointF pos, double& alignX, double& alignY );
188 
189  //helper functions for item align
190  void collectAlignCoordinates( QMap< double, const QgsComposerItem* >& alignCoordsX, QMap< double, const QgsComposerItem* >& alignCoordsY );
191  bool nearestItem( const QMap< double, const QgsComposerItem* >& coords, double value, double& nearestValue ) const;
192  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem* >& alignCoords, double& smallestDiff, double itemCoordOffset, double& itemCoord, double& alignCoord );
193 
194  //tries to return the current QGraphicsView attached to the composition
195  QGraphicsView* graphicsView();
196 
197  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
198  void setViewportCursor( Qt::CursorShape cursor );
199 
200  //resets the composer window status bar to the default message
201  void resetStatusBar();
202 };
203 
204 #endif // QGSCOMPOSERMOUSEHANDLES_H
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
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.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Graphics scene for map printing.
void setComposition(QgsComposition *c)
Handles drawing of selection outlines and mouse handles.
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)