QGIS API Documentation  2.2.0-Valmiera
 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>

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.
void selectedItemSizeChanged ()
 Redraws handles when selected item size changes.
void selectedItemRotationChanged ()
 Redraws handles when selected item rotation changes.

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.
bool isDragging ()
 Returns true is user is currently dragging the handles.
bool isResizing ()
 Returns true is user is currently resizing with the handles.

Protected Member Functions

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

Private Member Functions

QRectF selectionBounds () const
 Returns the mouse handle bounds of current selection.
bool selectionRotation (double &rotation) const
 Returns true if all selected items have same rotation, and if so, updates passed rotation variable.
void updateHandles ()
 Redraws or hides the handles based on the current selection.
void drawHandles (QPainter *painter, double rectHandlerSize)
 Draws the handles.
void drawSelectedItemBounds (QPainter *painter)
 Draw outlines for selected items.
double rectHandlerBorderTolerance ()
 Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the item border for resizing.
Qt::CursorShape cursorForPosition (const QPointF &itemCoordPos)
 Finds out the appropriate cursor for the current mouse position in the widget (e.g.
QgsComposerMouseHandles::MouseAction mouseActionForPosition (const QPointF &itemCoordPos)
 Finds out which mouse move action to choose depending on the cursor position inside the widget.
void dragMouseMove (const QPointF &currentPosition, bool lockMovement, bool preventSnap)
 Handles dragging of items during mouse move.
QSizeF calcCursorEdgeOffset (const QPointF &cursorPos)
 Calculates the distance of the mouse cursor from thed edge of the mouse handles.
void resizeMouseMove (const QPointF &currentPosition, bool lockAspect, bool fromCenter)
 Handles resizing of items during mouse move.
QGraphicsLineItem * hAlignSnapItem ()
 Return horizontal align snap item.
void deleteHAlignSnapItem ()
QGraphicsLineItem * vAlignSnapItem ()
 Return vertical align snap item.
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.
QPointF alignItem (double &alignX, double &alignY, double unalignedX, double unalignedY)
 Snaps an item originating at unalignedX, unalignedY to the grid or align rulers.
QPointF alignPos (const QPointF &pos, double &alignX, double &alignY)
 Snaps a point to to the grid or align rulers.
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) const
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)
QPointF mLastMouseEventPos
 Position of the last mouse move event (in scene coordinates)
QPointF mBeginMouseEventPos
 Position of the mouse at beginning of move/resize (in scene coordinates)
QPointF mBeginHandlePos
 Position of composer handles at beginning of move/resize (in scene coordinates)
double mBeginHandleWidth
 Width and height of composer handles at beginning of resize.
double mBeginHandleHeight
QRectF mResizeRect
double mResizeMoveX
double mResizeMoveY
bool mIsDragging
 True if user is currently dragging items.
bool mIsResizing
 True is user is currently resizing items.
QGraphicsLineItem * mHAlignSnapItem
 Align snap lines.
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 29 of file qgscomposermousehandles.cpp.

References mComposition, and selectionChanged().

QgsComposerMouseHandles::~QgsComposerMouseHandles ( )
virtual

Definition at line 49 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 1158 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 1196 of file qgscomposermousehandles.cpp.

References QgsComposition::alignmentSnapTolerance(), collectAlignCoordinates(), mComposition, and nearestItem().

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 728 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 
) const
private

Definition at line 1292 of file qgscomposermousehandles.cpp.

References nearestItem().

Referenced by alignItem().

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 341 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 1132 of file qgscomposermousehandles.cpp.

References mHAlignSnapItem.

Referenced by deleteAlignItems(), and snapPoint().

void QgsComposerMouseHandles::deleteVAlignSnapItem ( )
private

Definition at line 1142 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 768 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 96 of file qgscomposermousehandles.cpp.

Referenced by paint().

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

Definition at line 54 of file qgscomposermousehandles.cpp.

References mGraphicsView.

Referenced by rectHandlerBorderTolerance(), and setViewportCursor().

QGraphicsLineItem * QgsComposerMouseHandles::hAlignSnapItem ( )
private

Return horizontal align snap item.

Creates a new graphics line if 0

Definition at line 1108 of file qgscomposermousehandles.cpp.

References mHAlignSnapItem.

Referenced by snapPoint().

void QgsComposerMouseHandles::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protected

Definition at line 527 of file qgscomposermousehandles.cpp.

References setViewportCursor().

void QgsComposerMouseHandles::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)
protected

Definition at line 522 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 433 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 515 of file qgscomposermousehandles.cpp.

References mouseActionForPosition().

Referenced by QgsComposerView::mousePressEvent().

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 1309 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 320 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 228 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 219 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 278 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 190 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 296 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 237 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 1120 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 120 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 122 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 118 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 138 of file qgscomposermousehandles.h.

Referenced by mousePressEvent(), and resizeMouseMove().

QGraphicsView* QgsComposerMouseHandles::mGraphicsView
private

Definition at line 110 of file qgscomposermousehandles.h.

Referenced by graphicsView().

QGraphicsLineItem* QgsComposerMouseHandles::mHAlignSnapItem
private

Align snap lines.

Definition at line 135 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 116 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 114 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 136 of file qgscomposermousehandles.h.

Referenced by deleteVAlignSnapItem(), and vAlignSnapItem().


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