QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 : [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 
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 hoverMoveEvent( QGraphicsSceneHoverEvent * event );
94  void hoverLeaveEvent( QGraphicsSceneHoverEvent * event );
95 
96  public slots:
97 
99  void selectionChanged();
100 
102  void selectedItemSizeChanged();
103 
105  void selectedItemRotationChanged();
106 
107  private:
108 
109  QgsComposition* mComposition; //reference to composition
110  QGraphicsView* mGraphicsView; //reference to QGraphicsView
111 
124 
125  QRectF mResizeRect;
126  double mResizeMoveX;
127  double mResizeMoveY;
128 
133 
135  QGraphicsLineItem* mHAlignSnapItem;
136  QGraphicsLineItem* mVAlignSnapItem;
137 
139 
141  QRectF selectionBounds() const;
142 
144  bool selectionRotation( double & rotation ) const;
145 
147  void updateHandles();
149  void drawHandles( QPainter* painter, double rectHandlerSize );
151  void drawSelectedItemBounds( QPainter* painter );
152 
155  double rectHandlerBorderTolerance();
156 
158  Qt::CursorShape cursorForPosition( const QPointF& itemCoordPos );
159 
161  QgsComposerMouseHandles::MouseAction mouseActionForPosition( const QPointF& itemCoordPos );
162 
164  void dragMouseMove( const QPointF& currentPosition, bool lockMovement, bool preventSnap );
165 
167  QSizeF calcCursorEdgeOffset( const QPointF &cursorPos );
168 
170  void resizeMouseMove( const QPointF& currentPosition, bool lockAspect, bool fromCenter );
171 
173  QGraphicsLineItem* hAlignSnapItem();
174  void deleteHAlignSnapItem();
176  QGraphicsLineItem* vAlignSnapItem();
177  void deleteVAlignSnapItem();
178  void deleteAlignItems();
179 
181  QPointF snapPoint( const QPointF& originalPoint, QgsComposerMouseHandles::SnapGuideMode mode );
183  QPointF alignItem( double& alignX, double& alignY, double unalignedX, double unalignedY );
185  QPointF alignPos( const QPointF& pos, double& alignX, double& alignY );
186 
187  //helper functions for item align
188  void collectAlignCoordinates( QMap< double, const QgsComposerItem* >& alignCoordsX, QMap< double, const QgsComposerItem* >& alignCoordsY );
189  bool nearestItem( const QMap< double, const QgsComposerItem* >& coords, double value, double& nearestValue ) const;
190  void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem* >& alignCoords, double& smallestDiff, double itemCoordOffset, double& itemCoord, double& alignCoord ) const;
191 
192  //tries to return the current QGraphicsView attached to the composition
193  QGraphicsView* graphicsView();
194 
195  //sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
196  void setViewportCursor( Qt::CursorShape cursor );
197 
198  //resets the composer window status bar to the default message
199  void resetStatusBar();
200 };
201 
202 #endif // QGSCOMPOSERMOUSEHANDLES_H