Skip to content

Commit

Permalink
[FEATURE] Ctrl+space temporarily switches composer to marquee zoom mo…
Browse files Browse the repository at this point in the history
…de, Ctrl+Shift+Space temporarily switches to zoom out mode
  • Loading branch information
nyalldawson committed Oct 26, 2013
1 parent a3b2629 commit ab1766c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
82 changes: 76 additions & 6 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -50,6 +50,7 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
, mMoveContentItem( 0 )
, mMarqueeSelect( false )
, mMarqueeZoom( false )
, mTemporaryZoomStatus( QgsComposerView::Inactive )
, mPaintingEnabled( true )
, mHorizontalRuler( 0 )
, mVerticalRuler( 0 )
Expand Down Expand Up @@ -558,6 +559,14 @@ void QgsComposerView::endMarqueeZoom( QMouseEvent* e )
removeRubberBand();
//zoom view to fit desired bounds
fitInView( boundsRect, Qt::KeepAspectRatio );

if ( mTemporaryZoomStatus == QgsComposerView::ActiveUntilMouseRelease )
{
//user was using the temporary keyboard activated zoom tool
//and the control or space key was released before mouse button, so end temporary zoom
mTemporaryZoomStatus = QgsComposerView::Inactive;
setCurrentTool( mPreviousTool );
}
}

void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
Expand Down Expand Up @@ -1013,11 +1022,43 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
if ( mPanning )
return;

if ( e->key() == Qt::Key_Space )
if ( mTemporaryZoomStatus != QgsComposerView::Inactive )
{
// Pan composer with space bar
if ( ! e->isAutoRepeat() )
//temporary keyboard based zoom is active
if ( e->isAutoRepeat() )
{
return;
}

//respond to changes in ctrl key status
if ( !( e->modifiers() & Qt::ControlModifier ) && !mMarqueeZoom )
{
//space pressed, but control key was released, end of temporary zoom tool
mTemporaryZoomStatus = QgsComposerView::Inactive;
setCurrentTool( mPreviousTool );
}
else if ( !( e->modifiers() & Qt::ControlModifier ) && mMarqueeZoom )
{
//control key released, but user is mid-way through a marquee zoom
//so end temporary zoom when user releases the mouse button
mTemporaryZoomStatus = QgsComposerView::ActiveUntilMouseRelease;
}
else
{
//both control and space pressed
//set cursor to zoom in/out depending on shift key status
QPixmap myZoomQPixmap = QPixmap(( const char ** )( e->modifiers() & Qt::ShiftModifier ? zoom_out : zoom_in ) );
QCursor zoomCursor = QCursor( myZoomQPixmap, 7, 7 );
viewport()->setCursor( zoomCursor );
}
return;
}

if ( e->key() == Qt::Key_Space && ! e->isAutoRepeat() )
{
if ( !( e->modifiers() & Qt::ControlModifier ) )
{
// Pan composer with space bar
mPanning = true;
mMouseLastXY = mMouseCurrentXY;
if ( composition() )
Expand All @@ -1026,12 +1067,25 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
composition()->setPreventCursorChange( true );
}
viewport()->setCursor( Qt::ClosedHandCursor );
return;
}
else
{
//ctrl+space pressed, so switch to temporary keyboard based zoom tool
mTemporaryZoomStatus = QgsComposerView::Active;
mPreviousTool = mCurrentTool;
setCurrentTool( Zoom );
//set cursor to zoom in/out depending on shift key status
QPixmap myZoomQPixmap = QPixmap(( const char ** )( e->modifiers() & Qt::ShiftModifier ? zoom_out : zoom_in ) );
QCursor zoomCursor = QCursor( myZoomQPixmap, 7, 7 );
viewport()->setCursor( zoomCursor );
return;
}
return;
}

if ( mCurrentTool == QgsComposerView::Zoom )
{
//using the zoom tool, respond to changes in shift key status and update mouse cursor accordingly
if ( ! e->isAutoRepeat() )
{
QPixmap myZoomQPixmap = QPixmap(( const char ** )( e->modifiers() & Qt::ShiftModifier ? zoom_out : zoom_in ) );
Expand Down Expand Up @@ -1113,9 +1167,25 @@ void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
}
return;
}

if ( mCurrentTool == QgsComposerView::Zoom )
else if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mTemporaryZoomStatus != QgsComposerView::Inactive )
{
//temporary keyboard-based zoom tool is active and space key has been released
if ( mMarqueeZoom )
{
//currently in the middle of a marquee operation, so don't switch tool back immediately
//instead, wait until mouse button has been released before switching tool back
mTemporaryZoomStatus = QgsComposerView::ActiveUntilMouseRelease;
}
else
{
//switch tool back
mTemporaryZoomStatus = QgsComposerView::Inactive;
setCurrentTool( mPreviousTool );
}
}
else if ( mCurrentTool == QgsComposerView::Zoom )
{
//if zoom tool is active, respond to changes in the shift key status and update cursor accordingly
if ( ! e->isAutoRepeat() )
{
QPixmap myZoomQPixmap = QPixmap(( const char ** )( e->modifiers() & Qt::ShiftModifier ? zoom_out : zoom_in ) );
Expand Down
12 changes: 12 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -83,6 +83,13 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
PasteModeInPlace
};

enum ToolStatus
{
Inactive,
Active,
ActiveUntilMouseRelease
};

QgsComposerView( QWidget* parent = 0, const char* name = 0, Qt::WFlags f = 0 );

/**Add an item group containing the selected items*/
Expand Down Expand Up @@ -151,6 +158,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
private:
/**Current composer tool*/
QgsComposerView::Tool mCurrentTool;
/**Previous composer tool*/
QgsComposerView::Tool mPreviousTool;

/**Rubber band item*/
QGraphicsRectItem* mRubberBandItem;
/**Rubber band item for arrows*/
Expand All @@ -166,6 +176,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
bool mMarqueeSelect;
/**True if user is currently zooming by marquee*/
bool mMarqueeZoom;
/**True if user is currently temporarily activating the zoom tool by holding control+space*/
QgsComposerView::ToolStatus mTemporaryZoomStatus;

bool mPaintingEnabled;

Expand Down

0 comments on commit ab1766c

Please sign in to comment.