QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 : nyall.dawson@gmail.com
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 
31 class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectItem
32 {
33  Q_OBJECT
34  public:
35 
38  {
49  NoAction
50  };
51 
53  {
62  LowerRight
63  };
64 
66  {
68  Point
69  };
70 
72  virtual ~QgsComposerMouseHandles();
73 
74  void setComposition( QgsComposition* c ) { mComposition = c; }
75  QgsComposition* composition() { return mComposition; }
76 
77  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
78 
80  QgsComposerMouseHandles::MouseAction mouseActionForScenePos( const QPointF& sceneCoordPos );
81 
83  bool isDragging() { return mIsDragging; }
84 
86  bool isResizing() { return mIsResizing; }
87 
88  protected:
89 
90  void mouseMoveEvent( QGraphicsSceneMouseEvent* event );
91  void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
92  void mousePressEvent( QGraphicsSceneMouseEvent* event );
93  void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event );
94  void hoverMoveEvent( QGraphicsSceneHoverEvent * event );
95  void hoverLeaveEvent( QGraphicsSceneHoverEvent * event );
96 
97  public slots:
98 
100  void selectionChanged();
101 
103  void selectedItemSizeChanged();
104 
106  void selectedItemRotationChanged();
107 
108  private:
109 
110  QgsComposition* mComposition; //reference to composition
111  QGraphicsView* mGraphicsView; //reference to QGraphicsView
112 
113  QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
115  QPointF mMouseMoveStartPos;
117  QPointF mLastMouseEventPos;
119  QPointF mBeginMouseEventPos;
121  QPointF mBeginHandlePos;
123  double mBeginHandleWidth;
124  double mBeginHandleHeight;
125 
126  QRectF mResizeRect;
127  double mResizeMoveX;
128  double mResizeMoveY;
129 
131  bool mIsDragging;
133  bool mIsResizing;
134 
136  QGraphicsLineItem* mHAlignSnapItem;
137  QGraphicsLineItem* mVAlignSnapItem;
138 
139  QSizeF mCursorOffset;
140 
142  QRectF selectionBounds() const;
143 
145  bool selectionRotation( double & rotation ) const;
146 
148  void updateHandles();
150  void drawHandles( QPainter* painter, double rectHandlerSize );
152  void drawSelectedItemBounds( QPainter* painter );
153 
156  double rectHandlerBorderTolerance();
157 
159  Qt::CursorShape cursorForPosition( const QPointF& itemCoordPos );
160 
162  QgsComposerMouseHandles::MouseAction mouseActionForPosition( const QPointF& itemCoordPos );
163 
165  void dragMouseMove( const QPointF& currentPosition, bool lockMovement, bool preventSnap );
166 
168  QSizeF calcCursorEdgeOffset( const QPointF &cursorPos );
169 
171  void resizeMouseMove( const QPointF& currentPosition, bool lockAspect, bool fromCenter );
172 
174  QGraphicsLineItem* hAlignSnapItem();
175  void deleteHAlignSnapItem();
177  QGraphicsLineItem* vAlignSnapItem();
178  void deleteVAlignSnapItem();
179  void deleteAlignItems();
180 
182  QPointF snapPoint( const QPointF& originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
184  QPointF alignItem( double& alignX, double& alignY, double unalignedX, double unalignedY );
186  QPointF alignPos( const QPointF& pos, double& alignX, double& alignY );
187 
188  //helper functions for item align
189  void collectAlignCoordinates( QMap< double, const QgsComposerItem* >& alignCoordsX, QMap< double, const QgsComposerItem* >& alignCoordsY );
190  bool nearestItem( const QMap< double, const QgsComposerItem* >& coords, double value, double& nearestValue ) const;
191  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem* >& alignCoords, double& smallestDiff, double itemCoordOffset, double& itemCoord, double& alignCoord );
192 
193  //tries to return the current QGraphicsView attached to the composition
194  QGraphicsView* graphicsView();
195 
196  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
197  void setViewportCursor( Qt::CursorShape cursor );
198 
199  //resets the composer window status bar to the default message
200  void resetStatusBar();
201 };
202 
203 #endif // QGSCOMPOSERMOUSEHANDLES_H
MouseAction
Describes the action (move or resize in different directon) to be done during mouse move...
A item that forms part of a map composition.
bool isDragging()
Returns true is user is currently dragging the handles.
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.