QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Slots | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
QgsComposerMouseHandles Class Reference

Handles drawing of selection outlines and mouse handles. More...

#include <qgscomposermousehandles.h>

Inheritance diagram for QgsComposerMouseHandles:
Inheritance graph
[legend]
Collaboration diagram for QgsComposerMouseHandles:
Collaboration graph
[legend]

Public Types

enum  MouseAction {
  MoveItem, ResizeUp, ResizeDown, ResizeLeft,
  ResizeRight, ResizeLeftUp, ResizeRightUp, ResizeLeftDown,
  ResizeRightDown, SelectItem, NoAction
}
 Describes the action (move or resize in different directon) to be done during mouse move. More...
 
enum  ItemPositionMode {
  UpperLeft, UpperMiddle, UpperRight, MiddleLeft,
  Middle, MiddleRight, LowerLeft, LowerMiddle,
  LowerRight
}
 
enum  SnapGuideMode { Item, Point }
 

Public Slots

void selectionChanged ()
 Sets up listeners to sizeChanged signal for all selected items. More...
 
void selectedItemSizeChanged ()
 Redraws handles when selected item size changes. More...
 
void selectedItemRotationChanged ()
 Redraws handles when selected item rotation changes. More...
 

Public Member Functions

 QgsComposerMouseHandles (QgsComposition *composition)
 
virtual ~QgsComposerMouseHandles ()
 
void setComposition (QgsComposition *c)
 
QgsCompositioncomposition ()
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
 
QgsComposerMouseHandles::MouseAction mouseActionForScenePos (const QPointF &sceneCoordPos)
 Finds out which mouse move action to choose depending on the scene cursor position. More...
 
bool isDragging ()
 Returns true is user is currently dragging the handles. More...
 
bool isResizing ()
 Returns true is user is currently resizing with the handles. More...
 

Protected Member Functions

void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 
void mousePressEvent (QGraphicsSceneMouseEvent *event)
 
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event)
 
void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 
void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 

Private Member Functions

QRectF selectionBounds () const
 Returns the mouse handle bounds of current selection. More...
 
bool selectionRotation (double &rotation) const
 Returns true if all selected items have same rotation, and if so, updates passed rotation variable. More...
 
void updateHandles ()
 Redraws or hides the handles based on the current selection. More...
 
void drawHandles (QPainter *painter, double rectHandlerSize)
 Draws the handles. More...
 
void drawSelectedItemBounds (QPainter *painter)
 Draw outlines for selected items. More...
 
double rectHandlerBorderTolerance ()
 Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the item border for resizing. More...
 
Qt::CursorShape cursorForPosition (const QPointF &itemCoordPos)
 Finds out the appropriate cursor for the current mouse position in the widget (e.g. More...
 
QgsComposerMouseHandles::MouseAction mouseActionForPosition (const QPointF &itemCoordPos)
 Finds out which mouse move action to choose depending on the cursor position inside the widget. More...
 
void dragMouseMove (const QPointF &currentPosition, bool lockMovement, bool preventSnap)
 Handles dragging of items during mouse move. More...
 
QSizeF calcCursorEdgeOffset (const QPointF &cursorPos)
 Calculates the distance of the mouse cursor from thed edge of the mouse handles. More...
 
void resizeMouseMove (const QPointF &currentPosition, bool lockAspect, bool fromCenter)
 Handles resizing of items during mouse move. More...
 
QGraphicsLineItem * hAlignSnapItem ()
 Return horizontal align snap item. More...
 
void deleteHAlignSnapItem ()
 
QGraphicsLineItem * vAlignSnapItem ()
 Return vertical align snap item. More...
 
void deleteVAlignSnapItem ()
 
void deleteAlignItems ()
 
QPointF snapPoint (const QPointF &originalPoint, QgsComposerMouseHandles::SnapGuideMode mode)
 Snaps an item or point (depending on mode) originating at originalPoint to the grid or align rulers. More...
 
QPointF alignItem (double &alignX, double &alignY, double unalignedX, double unalignedY)
 Snaps an item originating at unalignedX, unalignedY to the grid or align rulers. More...
 
QPointF alignPos (const QPointF &pos, double &alignX, double &alignY)
 Snaps a point to to the grid or align rulers. More...
 
void collectAlignCoordinates (QMap< double, const QgsComposerItem * > &alignCoordsX, QMap< double, const QgsComposerItem * > &alignCoordsY)
 
bool nearestItem (const QMap< double, const QgsComposerItem * > &coords, double value, double &nearestValue) const
 
void checkNearestItem (double checkCoord, const QMap< double, const QgsComposerItem * > &alignCoords, double &smallestDiff, double itemCoordOffset, double &itemCoord, double &alignCoord)
 
QGraphicsView * graphicsView ()
 
void setViewportCursor (Qt::CursorShape cursor)
 
void resetStatusBar ()
 

Private Attributes

QgsCompositionmComposition
 
QGraphicsView * mGraphicsView
 
QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction
 
QPointF mMouseMoveStartPos
 Start point of the last mouse move action (in scene coordinates) More...
 
QPointF mLastMouseEventPos
 Position of the last mouse move event (in scene coordinates) More...
 
QPointF mBeginMouseEventPos
 Position of the mouse at beginning of move/resize (in scene coordinates) More...
 
QPointF mBeginHandlePos
 Position of composer handles at beginning of move/resize (in scene coordinates) More...
 
double mBeginHandleWidth
 Width and height of composer handles at beginning of resize. More...
 
double mBeginHandleHeight
 
QRectF mResizeRect
 
double mResizeMoveX
 
double mResizeMoveY
 
bool mIsDragging
 True if user is currently dragging items. More...
 
bool mIsResizing
 True is user is currently resizing items. More...
 
QGraphicsLineItem * mHAlignSnapItem
 Align snap lines. More...
 
QGraphicsLineItem * mVAlignSnapItem
 
QSizeF mCursorOffset
 

Detailed Description

Handles drawing of selection outlines and mouse handles.

Responsible for mouse interactions such as resizing and moving selected items.

Definition at line 31 of file qgscomposermousehandles.h.

Member Enumeration Documentation

Enumerator
UpperLeft 
UpperMiddle 
UpperRight 
MiddleLeft 
Middle 
MiddleRight 
LowerLeft 
LowerMiddle 
LowerRight 

Definition at line 52 of file qgscomposermousehandles.h.

Describes the action (move or resize in different directon) to be done during mouse move.

Enumerator
MoveItem 
ResizeUp 
ResizeDown 
ResizeLeft 
ResizeRight 
ResizeLeftUp 
ResizeRightUp 
ResizeLeftDown 
ResizeRightDown 
SelectItem 
NoAction 

Definition at line 37 of file qgscomposermousehandles.h.

Enumerator
Item 
Point 

Definition at line 65 of file qgscomposermousehandles.h.

Constructor & Destructor Documentation

QgsComposerMouseHandles::QgsComposerMouseHandles ( QgsComposition composition)

Definition at line 33 of file qgscomposermousehandles.cpp.

References mComposition, and selectionChanged().

QgsComposerMouseHandles::~QgsComposerMouseHandles ( )
virtual

Definition at line 53 of file qgscomposermousehandles.cpp.

Member Function Documentation

QPointF QgsComposerMouseHandles::alignItem ( double &  alignX,
double &  alignY,
double  unalignedX,
double  unalignedY 
)
private

Snaps an item originating at unalignedX, unalignedY to the grid or align rulers.

Definition at line 1170 of file qgscomposermousehandles.cpp.

References checkNearestItem(), and collectAlignCoordinates().

Referenced by snapPoint().

QPointF QgsComposerMouseHandles::alignPos ( const QPointF &  pos,
double &  alignX,
double &  alignY 
)
private

Snaps a point to to the grid or align rulers.

Definition at line 1208 of file qgscomposermousehandles.cpp.

References collectAlignCoordinates(), graphicsView(), mComposition, nearestItem(), and QgsComposition::snapTolerance().

Referenced by snapPoint().

QSizeF QgsComposerMouseHandles::calcCursorEdgeOffset ( const QPointF &  cursorPos)
private

Calculates the distance of the mouse cursor from thed edge of the mouse handles.

Definition at line 740 of file qgscomposermousehandles.cpp.

References mCurrentMouseMoveAction, ResizeDown, ResizeLeft, ResizeLeftDown, ResizeLeftUp, ResizeRight, ResizeRightDown, ResizeRightUp, and ResizeUp.

Referenced by mousePressEvent().

void QgsComposerMouseHandles::checkNearestItem ( double  checkCoord,
const QMap< double, const QgsComposerItem * > &  alignCoords,
double &  smallestDiff,
double  itemCoordOffset,
double &  itemCoord,
double &  alignCoord 
)
private
void QgsComposerMouseHandles::collectAlignCoordinates ( QMap< double, const QgsComposerItem * > &  alignCoordsX,
QMap< double, const QgsComposerItem * > &  alignCoordsY 
)
private
QgsComposition* QgsComposerMouseHandles::composition ( )
inline

Definition at line 75 of file qgscomposermousehandles.h.

Referenced by selectionChanged().

Qt::CursorShape QgsComposerMouseHandles::cursorForPosition ( const QPointF &  itemCoordPos)
private

Finds out the appropriate cursor for the current mouse position in the widget (e.g.

move in the middle, resize at border)

Definition at line 345 of file qgscomposermousehandles.cpp.

References mouseActionForPosition(), MoveItem, NoAction, ResizeDown, ResizeLeft, ResizeLeftDown, ResizeLeftUp, ResizeRight, ResizeRightDown, ResizeRightUp, ResizeUp, and SelectItem.

Referenced by hoverMoveEvent().

void QgsComposerMouseHandles::deleteAlignItems ( )
private
void QgsComposerMouseHandles::deleteHAlignSnapItem ( )
private

Definition at line 1144 of file qgscomposermousehandles.cpp.

References mHAlignSnapItem.

Referenced by deleteAlignItems(), and snapPoint().

void QgsComposerMouseHandles::deleteVAlignSnapItem ( )
private

Definition at line 1154 of file qgscomposermousehandles.cpp.

References mVAlignSnapItem.

Referenced by deleteAlignItems(), and snapPoint().

void QgsComposerMouseHandles::dragMouseMove ( const QPointF &  currentPosition,
bool  lockMovement,
bool  preventSnap 
)
private

Handles dragging of items during mouse move.

Definition at line 780 of file qgscomposermousehandles.cpp.

References deleteAlignItems(), Item, mBeginHandlePos, mBeginMouseEventPos, mComposition, QgsComposition::setStatusMessage(), snapPoint(), and tr.

Referenced by mouseMoveEvent().

void QgsComposerMouseHandles::drawHandles ( QPainter *  painter,
double  rectHandlerSize 
)
private

Draws the handles.

Definition at line 100 of file qgscomposermousehandles.cpp.

Referenced by paint().

void QgsComposerMouseHandles::drawSelectedItemBounds ( QPainter *  painter)
private
QGraphicsView * QgsComposerMouseHandles::graphicsView ( )
private
QGraphicsLineItem * QgsComposerMouseHandles::hAlignSnapItem ( )
private

Return horizontal align snap item.

Creates a new graphics line if 0

Definition at line 1120 of file qgscomposermousehandles.cpp.

References mHAlignSnapItem.

Referenced by snapPoint().

void QgsComposerMouseHandles::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protected

Definition at line 542 of file qgscomposermousehandles.cpp.

References setViewportCursor().

void QgsComposerMouseHandles::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)
protected

Definition at line 537 of file qgscomposermousehandles.cpp.

References cursorForPosition(), and setViewportCursor().

bool QgsComposerMouseHandles::isDragging ( )
inline

Returns true is user is currently dragging the handles.

Definition at line 83 of file qgscomposermousehandles.h.

Referenced by QgsComposerView::mouseReleaseEvent().

bool QgsComposerMouseHandles::isResizing ( )
inline

Returns true is user is currently resizing with the handles.

Definition at line 86 of file qgscomposermousehandles.h.

Referenced by QgsComposerView::mouseReleaseEvent().

QgsComposerMouseHandles::MouseAction QgsComposerMouseHandles::mouseActionForPosition ( const QPointF &  itemCoordPos)
private

Finds out which mouse move action to choose depending on the cursor position inside the widget.

Definition at line 437 of file qgscomposermousehandles.cpp.

References mComposition, MoveItem, rectHandlerBorderTolerance(), ResizeDown, ResizeLeft, ResizeLeftDown, ResizeLeftUp, ResizeRight, ResizeRightDown, ResizeRightUp, ResizeUp, QgsComposerItem::selected(), and SelectItem.

Referenced by cursorForPosition(), mouseActionForScenePos(), and mousePressEvent().

QgsComposerMouseHandles::MouseAction QgsComposerMouseHandles::mouseActionForScenePos ( const QPointF &  sceneCoordPos)

Finds out which mouse move action to choose depending on the scene cursor position.

Definition at line 530 of file qgscomposermousehandles.cpp.

References mouseActionForPosition().

Referenced by QgsComposerView::mousePressEvent().

void QgsComposerMouseHandles::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent *  event)
protected

Definition at line 735 of file qgscomposermousehandles.cpp.

void QgsComposerMouseHandles::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
protected
void QgsComposerMouseHandles::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protected
void QgsComposerMouseHandles::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
protected
bool QgsComposerMouseHandles::nearestItem ( const QMap< double, const QgsComposerItem * > &  coords,
double  value,
double &  nearestValue 
) const
private

Definition at line 1330 of file qgscomposermousehandles.cpp.

Referenced by alignPos(), and checkNearestItem().

void QgsComposerMouseHandles::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  itemStyle,
QWidget *  pWidget 
)
double QgsComposerMouseHandles::rectHandlerBorderTolerance ( )
private

Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the item border for resizing.

Definition at line 324 of file qgscomposermousehandles.cpp.

References graphicsView().

Referenced by mouseActionForPosition(), and paint().

void QgsComposerMouseHandles::resetStatusBar ( )
private
void QgsComposerMouseHandles::resizeMouseMove ( const QPointF &  currentPosition,
bool  lockAspect,
bool  fromCenter 
)
private
void QgsComposerMouseHandles::selectedItemRotationChanged ( )
slot

Redraws handles when selected item rotation changes.

Definition at line 232 of file qgscomposermousehandles.cpp.

References mIsDragging, mIsResizing, and updateHandles().

Referenced by selectionChanged().

void QgsComposerMouseHandles::selectedItemSizeChanged ( )
slot

Redraws handles when selected item size changes.

Definition at line 223 of file qgscomposermousehandles.cpp.

References mIsDragging, mIsResizing, and updateHandles().

Referenced by selectionChanged().

QRectF QgsComposerMouseHandles::selectionBounds ( ) const
private

Returns the mouse handle bounds of current selection.

Definition at line 282 of file qgscomposermousehandles.cpp.

References mComposition, and QgsComposition::selectedComposerItems().

Referenced by updateHandles().

void QgsComposerMouseHandles::selectionChanged ( )
slot

Sets up listeners to sizeChanged signal for all selected items.

Definition at line 194 of file qgscomposermousehandles.cpp.

References composition(), resetStatusBar(), QgsComposerItem::selected(), selectedItemRotationChanged(), selectedItemSizeChanged(), and updateHandles().

Referenced by QgsComposerMouseHandles().

bool QgsComposerMouseHandles::selectionRotation ( double &  rotation) const
private

Returns true if all selected items have same rotation, and if so, updates passed rotation variable.

Definition at line 300 of file qgscomposermousehandles.cpp.

References mComposition, and QgsComposition::selectedComposerItems().

Referenced by updateHandles().

void QgsComposerMouseHandles::setComposition ( QgsComposition c)
inline

Definition at line 74 of file qgscomposermousehandles.h.

void QgsComposerMouseHandles::setViewportCursor ( Qt::CursorShape  cursor)
private
QPointF QgsComposerMouseHandles::snapPoint ( const QPointF &  originalPoint,
QgsComposerMouseHandles::SnapGuideMode  mode 
)
private
void QgsComposerMouseHandles::updateHandles ( )
private

Redraws or hides the handles based on the current selection.

Definition at line 241 of file qgscomposermousehandles.cpp.

References mComposition, QgsComposition::selectedComposerItems(), selectionBounds(), and selectionRotation().

Referenced by mouseReleaseEvent(), selectedItemRotationChanged(), selectedItemSizeChanged(), and selectionChanged().

QGraphicsLineItem * QgsComposerMouseHandles::vAlignSnapItem ( )
private

Return vertical align snap item.

Creates a new graphics line if 0

Definition at line 1132 of file qgscomposermousehandles.cpp.

References mVAlignSnapItem.

Referenced by snapPoint().

Member Data Documentation

double QgsComposerMouseHandles::mBeginHandleHeight
private
QPointF QgsComposerMouseHandles::mBeginHandlePos
private

Position of composer handles at beginning of move/resize (in scene coordinates)

Definition at line 121 of file qgscomposermousehandles.h.

Referenced by dragMouseMove(), mousePressEvent(), and mouseReleaseEvent().

double QgsComposerMouseHandles::mBeginHandleWidth
private

Width and height of composer handles at beginning of resize.

Definition at line 123 of file qgscomposermousehandles.h.

Referenced by drawSelectedItemBounds(), mousePressEvent(), mouseReleaseEvent(), and resizeMouseMove().

QPointF QgsComposerMouseHandles::mBeginMouseEventPos
private

Position of the mouse at beginning of move/resize (in scene coordinates)

Definition at line 119 of file qgscomposermousehandles.h.

Referenced by dragMouseMove(), mousePressEvent(), and resizeMouseMove().

QgsComposition* QgsComposerMouseHandles::mComposition
private
QgsComposerMouseHandles::MouseAction QgsComposerMouseHandles::mCurrentMouseMoveAction
private
QSizeF QgsComposerMouseHandles::mCursorOffset
private

Definition at line 139 of file qgscomposermousehandles.h.

Referenced by mousePressEvent(), and resizeMouseMove().

QGraphicsView* QgsComposerMouseHandles::mGraphicsView
private

Definition at line 111 of file qgscomposermousehandles.h.

Referenced by graphicsView().

QGraphicsLineItem* QgsComposerMouseHandles::mHAlignSnapItem
private

Align snap lines.

Definition at line 136 of file qgscomposermousehandles.h.

Referenced by deleteHAlignSnapItem(), and hAlignSnapItem().

bool QgsComposerMouseHandles::mIsDragging
private
bool QgsComposerMouseHandles::mIsResizing
private
QPointF QgsComposerMouseHandles::mLastMouseEventPos
private

Position of the last mouse move event (in scene coordinates)

Definition at line 117 of file qgscomposermousehandles.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

QPointF QgsComposerMouseHandles::mMouseMoveStartPos
private

Start point of the last mouse move action (in scene coordinates)

Definition at line 115 of file qgscomposermousehandles.h.

Referenced by mousePressEvent(), and mouseReleaseEvent().

double QgsComposerMouseHandles::mResizeMoveX
private
double QgsComposerMouseHandles::mResizeMoveY
private
QRectF QgsComposerMouseHandles::mResizeRect
private
QGraphicsLineItem* QgsComposerMouseHandles::mVAlignSnapItem
private

Definition at line 137 of file qgscomposermousehandles.h.

Referenced by deleteVAlignSnapItem(), and vAlignSnapItem().


The documentation for this class was generated from the following files: