Skip to content

Commit

Permalink
Respect events which has been set to ignore in QgsLayoutViewTools
Browse files Browse the repository at this point in the history
If ignored, default handling occurs
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent dc0425a commit 4b89f5e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
29 changes: 22 additions & 7 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -80,8 +80,10 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
mTool->layoutPressEvent( me.get() );
event->setAccepted( me->isAccepted() );
}
else

if ( !mTool || !event->isAccepted() )
QGraphicsView::mousePressEvent( event );
}

Expand All @@ -91,8 +93,10 @@ void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
mTool->layoutReleaseEvent( me.get() );
event->setAccepted( me->isAccepted() );
}
else

if ( !mTool || !event->isAccepted() )
QGraphicsView::mouseReleaseEvent( event );
}

Expand All @@ -102,8 +106,10 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
mTool->layoutMoveEvent( me.get() );
event->setAccepted( me->isAccepted() );
}
else

if ( !mTool || !event->isAccepted() )
QGraphicsView::mouseMoveEvent( event );
}

Expand All @@ -113,8 +119,10 @@ void QgsLayoutView::mouseDoubleClickEvent( QMouseEvent *event )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
mTool->layoutDoubleClickEvent( me.get() );
event->setAccepted( me->isAccepted() );
}
else

if ( !mTool || !event->isAccepted() )
QGraphicsView::mouseDoubleClickEvent( event );
}

Expand All @@ -124,22 +132,29 @@ void QgsLayoutView::wheelEvent( QWheelEvent *event )
{
mTool->wheelEvent( event );
}
else

if ( !mTool || !event->isAccepted() )
QGraphicsView::wheelEvent( event );
}

void QgsLayoutView::keyPressEvent( QKeyEvent *event )
{
if ( mTool )
{
mTool->keyPressEvent( event );
else
}

if ( !mTool || !event->isAccepted() )
QGraphicsView::keyPressEvent( event );
}

void QgsLayoutView::keyReleaseEvent( QKeyEvent *event )
{
if ( mTool )
{
mTool->keyReleaseEvent( event );
else
}

if ( !mTool || !event->isAccepted() )
QGraphicsView::keyReleaseEvent( event );
}
6 changes: 6 additions & 0 deletions src/gui/layout/qgslayoutviewtooladditem.cpp
Expand Up @@ -43,6 +43,7 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
{
if ( event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

Expand All @@ -61,12 +62,17 @@ void QgsLayoutViewToolAddItem::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
mRubberBand->update( event->layoutPoint(), event->modifiers() );
}
else
{
event->ignore();
}
}

void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() != Qt::LeftButton || !mDrawing )
{
event->ignore();
return;
}
mDrawing = false;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutviewtoolpan.cpp
Expand Up @@ -28,6 +28,7 @@ void QgsLayoutViewToolPan::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

Expand All @@ -39,7 +40,10 @@ void QgsLayoutViewToolPan::layoutPressEvent( QgsLayoutViewMouseEvent *event )
void QgsLayoutViewToolPan::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mIsPanning )
{
event->ignore();
return;
}

view()->horizontalScrollBar()->setValue( view()->horizontalScrollBar()->value() - ( event->x() - mLastMousePos.x() ) );
view()->verticalScrollBar()->setValue( view()->verticalScrollBar()->value() - ( event->y() - mLastMousePos.y() ) );
Expand All @@ -50,6 +54,7 @@ void QgsLayoutViewToolPan::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mIsPanning || event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/gui/layout/qgslayoutviewtoolzoom.cpp
Expand Up @@ -36,6 +36,7 @@ void QgsLayoutViewToolZoom::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

Expand Down Expand Up @@ -64,7 +65,10 @@ void QgsLayoutViewToolZoom::layoutPressEvent( QgsLayoutViewMouseEvent *event )
void QgsLayoutViewToolZoom::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mMarqueeZoom )
{
event->ignore();
return;
}

mRubberBand->update( event->layoutPoint(), 0 );
}
Expand All @@ -73,6 +77,7 @@ void QgsLayoutViewToolZoom::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mMarqueeZoom || event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

Expand All @@ -99,7 +104,7 @@ void QgsLayoutViewToolZoom::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
void QgsLayoutViewToolZoom::keyPressEvent( QKeyEvent *event )
{
//respond to changes in the alt key status and update cursor accordingly
if ( ! event->isAutoRepeat() )
if ( !event->isAutoRepeat() )
{
QPixmap zoomQPixmap = QPixmap( ( const char ** )( ( event->modifiers() & Qt::AltModifier ) ? zoom_out : zoom_in ) );
QCursor zoomCursor = QCursor( zoomQPixmap, 7, 7 );
Expand Down

0 comments on commit 4b89f5e

Please sign in to comment.