mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Move mouse handles to select tool
This commit is contained in:
parent
bfa9c1d661
commit
e0089fb84c
@ -127,8 +127,6 @@ class QgsLayoutView: QGraphicsView
|
|||||||
:rtype: list of int
|
:rtype: list of int
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void zoomFull();
|
void zoomFull();
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QgsLayoutViewToolSelect : QgsLayoutViewTool
|
class QgsLayoutViewToolSelect : QgsLayoutViewTool
|
||||||
{
|
{
|
||||||
%Docstring
|
%Docstring
|
||||||
@ -31,9 +32,17 @@ class QgsLayoutViewToolSelect : QgsLayoutViewTool
|
|||||||
|
|
||||||
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
|
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
|
||||||
|
|
||||||
|
virtual void wheelEvent( QWheelEvent *event );
|
||||||
|
|
||||||
|
virtual void keyPressEvent( QKeyEvent *event );
|
||||||
|
|
||||||
virtual void deactivate();
|
virtual void deactivate();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setLayout( QgsLayout *layout );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -352,6 +352,8 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
|
|||||||
connect( mActionRedo, &QAction::triggered, mLayout->undoStack()->stack(), &QUndoStack::redo );
|
connect( mActionRedo, &QAction::triggered, mLayout->undoStack()->stack(), &QUndoStack::redo );
|
||||||
mUndoView->setStack( mLayout->undoStack()->stack() );
|
mUndoView->setStack( mLayout->undoStack()->stack() );
|
||||||
|
|
||||||
|
mSelectTool->setLayout( layout );
|
||||||
|
|
||||||
createLayoutPropertiesWidget();
|
createLayoutPropertiesWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +442,7 @@ void QgsLayoutDesignerDialog::showGrid( bool visible )
|
|||||||
void QgsLayoutDesignerDialog::showBoxes( bool visible )
|
void QgsLayoutDesignerDialog::showBoxes( bool visible )
|
||||||
{
|
{
|
||||||
mLayout->context().setBoundingBoxesVisible( visible );
|
mLayout->context().setBoundingBoxesVisible( visible );
|
||||||
mView->mouseHandles()->update();
|
mSelectTool->mouseHandles()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
|
void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
|
||||||
|
@ -89,12 +89,6 @@ void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
|
|||||||
connect( &layout->guides(), &QAbstractItemModel::modelReset, mVerticalRuler, [ = ] { mVerticalRuler->update(); } );
|
connect( &layout->guides(), &QAbstractItemModel::modelReset, mVerticalRuler, [ = ] { mVerticalRuler->update(); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
//add mouse selection handles to layout, and initially hide
|
|
||||||
mMouseHandles = new QgsLayoutMouseHandles( layout, this );
|
|
||||||
mMouseHandles->hide();
|
|
||||||
mMouseHandles->setZValue( QgsLayout::ZMouseHandles );
|
|
||||||
layout->addItem( mMouseHandles );
|
|
||||||
|
|
||||||
//emit layoutSet, so that designer dialogs can update for the new layout
|
//emit layoutSet, so that designer dialogs can update for the new layout
|
||||||
emit layoutSet( layout );
|
emit layoutSet( layout );
|
||||||
}
|
}
|
||||||
@ -220,13 +214,6 @@ QList<int> QgsLayoutView::visiblePageNumbers() const
|
|||||||
return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
|
return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
|
||||||
}
|
}
|
||||||
|
|
||||||
///@cond PRIVATE
|
|
||||||
QgsLayoutMouseHandles *QgsLayoutView::mouseHandles()
|
|
||||||
{
|
|
||||||
return mMouseHandles;
|
|
||||||
}
|
|
||||||
///@endcond
|
|
||||||
|
|
||||||
void QgsLayoutView::zoomFull()
|
void QgsLayoutView::zoomFull()
|
||||||
{
|
{
|
||||||
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
||||||
@ -280,17 +267,6 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
|
|||||||
{
|
{
|
||||||
mSnapMarker->setVisible( false );
|
mSnapMarker->setVisible( false );
|
||||||
|
|
||||||
if ( mMouseHandles->shouldBlockEvent( event ) )
|
|
||||||
{
|
|
||||||
//ignore clicks while dragging/resizing items
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ( mMouseHandles->isVisible() )
|
|
||||||
{
|
|
||||||
QGraphicsView::mousePressEvent( event );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
||||||
@ -324,13 +300,6 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
|
|||||||
|
|
||||||
void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
|
void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
|
||||||
{
|
{
|
||||||
if ( event->button() != Qt::LeftButton &&
|
|
||||||
mMouseHandles->shouldBlockEvent( event ) )
|
|
||||||
{
|
|
||||||
//ignore clicks while dragging/resizing items
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
||||||
@ -388,12 +357,6 @@ void QgsLayoutView::mouseDoubleClickEvent( QMouseEvent *event )
|
|||||||
|
|
||||||
void QgsLayoutView::wheelEvent( QWheelEvent *event )
|
void QgsLayoutView::wheelEvent( QWheelEvent *event )
|
||||||
{
|
{
|
||||||
if ( mMouseHandles->shouldBlockEvent( event ) )
|
|
||||||
{
|
|
||||||
//ignore wheel events while dragging/resizing items
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
mTool->wheelEvent( event );
|
mTool->wheelEvent( event );
|
||||||
@ -408,11 +371,6 @@ void QgsLayoutView::wheelEvent( QWheelEvent *event )
|
|||||||
|
|
||||||
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
|
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
|
||||||
{
|
{
|
||||||
if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
mTool->keyPressEvent( event );
|
mTool->keyPressEvent( event );
|
||||||
|
@ -35,7 +35,6 @@ class QgsLayoutViewToolTemporaryMousePan;
|
|||||||
class QgsLayoutRuler;
|
class QgsLayoutRuler;
|
||||||
class QgsLayoutViewMenuProvider;
|
class QgsLayoutViewMenuProvider;
|
||||||
class QgsLayoutViewSnapMarker;
|
class QgsLayoutViewSnapMarker;
|
||||||
class QgsLayoutMouseHandles;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup gui
|
* \ingroup gui
|
||||||
@ -158,15 +157,6 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
|
|||||||
*/
|
*/
|
||||||
QList< int > visiblePageNumbers() const;
|
QList< int > visiblePageNumbers() const;
|
||||||
|
|
||||||
///@cond PRIVATE
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the view's mouse handles.
|
|
||||||
* \note Not available in Python bindings.
|
|
||||||
*/
|
|
||||||
SIP_SKIP QgsLayoutMouseHandles *mouseHandles();
|
|
||||||
///@endcond
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,8 +300,6 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
|
|||||||
|
|
||||||
std::unique_ptr< QgsLayoutViewSnapMarker > mSnapMarker;
|
std::unique_ptr< QgsLayoutViewSnapMarker > mSnapMarker;
|
||||||
|
|
||||||
QgsLayoutMouseHandles *mMouseHandles = nullptr; //owned by scene
|
|
||||||
|
|
||||||
int mCurrentPage = 0;
|
int mCurrentPage = 0;
|
||||||
|
|
||||||
friend class TestQgsLayoutView;
|
friend class TestQgsLayoutView;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "qgslayoutview.h"
|
#include "qgslayoutview.h"
|
||||||
#include "qgslayout.h"
|
#include "qgslayout.h"
|
||||||
#include "qgslayoutitempage.h"
|
#include "qgslayoutitempage.h"
|
||||||
|
#include "qgslayoutmousehandles.h"
|
||||||
|
|
||||||
QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
|
QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
|
||||||
: QgsLayoutViewTool( view, tr( "Select" ) )
|
: QgsLayoutViewTool( view, tr( "Select" ) )
|
||||||
@ -31,15 +32,102 @@ QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
|
|||||||
|
|
||||||
void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
|
void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
|
||||||
{
|
{
|
||||||
|
if ( mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//swallow clicks while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mMouseHandles->isVisible() )
|
||||||
|
{
|
||||||
|
//selection handles are being shown, get mouse action for current cursor position
|
||||||
|
QgsLayoutMouseHandles::MouseAction mouseAction = mMouseHandles->mouseActionForScenePos( event->layoutPoint() );
|
||||||
|
|
||||||
|
if ( mouseAction != QgsLayoutMouseHandles::MoveItem
|
||||||
|
&& mouseAction != QgsLayoutMouseHandles::NoAction
|
||||||
|
&& mouseAction != QgsLayoutMouseHandles::SelectItem )
|
||||||
|
{
|
||||||
|
//mouse is over a resize handle, so propagate event onward
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( event->button() != Qt::LeftButton )
|
if ( event->button() != Qt::LeftButton )
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsSelecting = true;
|
QgsLayoutItem *selectedItem = nullptr;
|
||||||
mMousePressStartPos = event->pos();
|
QgsLayoutItem *previousSelectedItem = nullptr;
|
||||||
mRubberBand->start( event->layoutPoint(), 0 );
|
|
||||||
|
if ( event->modifiers() & Qt::ControlModifier )
|
||||||
|
{
|
||||||
|
//CTRL modifier, so we are trying to select the next item below the current one
|
||||||
|
//first, find currently selected item
|
||||||
|
QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
|
||||||
|
if ( !selectedItems.isEmpty() )
|
||||||
|
{
|
||||||
|
previousSelectedItem = selectedItems.at( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( previousSelectedItem )
|
||||||
|
{
|
||||||
|
//select highest item just below previously selected item at position of event
|
||||||
|
selectedItem = layout()->layoutItemAt( event->layoutPoint(), previousSelectedItem, true );
|
||||||
|
|
||||||
|
//if we didn't find a lower item we'll use the top-most as fall-back
|
||||||
|
//this duplicates mapinfo/illustrator/etc behavior where ctrl-clicks are "cyclic"
|
||||||
|
if ( !selectedItem )
|
||||||
|
{
|
||||||
|
selectedItem = layout()->layoutItemAt( event->layoutPoint(), true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//select topmost item at position of event
|
||||||
|
selectedItem = layout()->layoutItemAt( event->layoutPoint(), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !selectedItem )
|
||||||
|
{
|
||||||
|
//not clicking over an item, so start marquee selection
|
||||||
|
mIsSelecting = true;
|
||||||
|
mMousePressStartPos = event->pos();
|
||||||
|
mRubberBand->start( event->layoutPoint(), 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( !selectedItem->isSelected() ) && //keep selection if an already selected item pressed
|
||||||
|
!( event->modifiers() & Qt::ShiftModifier ) ) //keep selection if shift key pressed
|
||||||
|
{
|
||||||
|
layout()->deselectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( event->modifiers() & Qt::ShiftModifier ) && ( selectedItem->isSelected() ) )
|
||||||
|
{
|
||||||
|
//SHIFT-clicking a selected item deselects it
|
||||||
|
selectedItem->setSelected( false );
|
||||||
|
|
||||||
|
//Check if we have any remaining selected items, and if so, update the item panel
|
||||||
|
QList<QgsLayoutItem *> selectedItems = layout()->selectedLayoutItems();
|
||||||
|
if ( !selectedItems.isEmpty() )
|
||||||
|
{
|
||||||
|
#if 0 //TODO
|
||||||
|
emit selectedItemChanged( selectedItems.at( 0 ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectedItem->setSelected( true );
|
||||||
|
event->ignore();
|
||||||
|
#if 0 //TODO
|
||||||
|
emit selectedItemChanged( selectedItem );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
|
void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
|
||||||
@ -56,6 +144,12 @@ void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
|
|||||||
|
|
||||||
void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
|
void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
|
||||||
{
|
{
|
||||||
|
if ( event->button() != Qt::LeftButton && mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//swallow clicks while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !mIsSelecting || event->button() != Qt::LeftButton )
|
if ( !mIsSelecting || event->button() != Qt::LeftButton )
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
@ -132,6 +226,31 @@ void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsLayoutViewToolSelect::wheelEvent( QWheelEvent *event )
|
||||||
|
{
|
||||||
|
if ( mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//ignore wheel events while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsLayoutViewToolSelect::keyPressEvent( QKeyEvent *event )
|
||||||
|
{
|
||||||
|
if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLayoutViewToolSelect::deactivate()
|
void QgsLayoutViewToolSelect::deactivate()
|
||||||
{
|
{
|
||||||
if ( mIsSelecting )
|
if ( mIsSelecting )
|
||||||
@ -141,3 +260,21 @@ void QgsLayoutViewToolSelect::deactivate()
|
|||||||
}
|
}
|
||||||
QgsLayoutViewTool::deactivate();
|
QgsLayoutViewTool::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///@cond PRIVATE
|
||||||
|
QgsLayoutMouseHandles *QgsLayoutViewToolSelect::mouseHandles()
|
||||||
|
{
|
||||||
|
return mMouseHandles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsLayoutViewToolSelect::setLayout( QgsLayout *layout )
|
||||||
|
{
|
||||||
|
// existing handles are owned by previous layout
|
||||||
|
|
||||||
|
//add mouse selection handles to layout, and initially hide
|
||||||
|
mMouseHandles = new QgsLayoutMouseHandles( layout, view() );
|
||||||
|
mMouseHandles->hide();
|
||||||
|
mMouseHandles->setZValue( QgsLayout::ZMouseHandles );
|
||||||
|
layout->addItem( mMouseHandles );
|
||||||
|
}
|
||||||
|
///@endcond
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "qgslayoutviewrubberband.h"
|
#include "qgslayoutviewrubberband.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class QgsLayoutMouseHandles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup gui
|
* \ingroup gui
|
||||||
* Layout view tool for selecting items in the layout.
|
* Layout view tool for selecting items in the layout.
|
||||||
@ -42,8 +44,21 @@ class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool
|
|||||||
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
|
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
|
||||||
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
|
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
|
||||||
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
|
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
|
||||||
|
void wheelEvent( QWheelEvent *event ) override;
|
||||||
|
void keyPressEvent( QKeyEvent *event ) override;
|
||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
|
|
||||||
|
///@cond PRIVATE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the view's mouse handles.
|
||||||
|
* \note Not available in Python bindings.
|
||||||
|
*/
|
||||||
|
SIP_SKIP QgsLayoutMouseHandles *mouseHandles();
|
||||||
|
///@endcond
|
||||||
|
|
||||||
|
void setLayout( QgsLayout *layout );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool mIsSelecting = false;
|
bool mIsSelecting = false;
|
||||||
@ -57,6 +72,7 @@ class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool
|
|||||||
//! Start of rubber band creation
|
//! Start of rubber band creation
|
||||||
QPointF mRubberBandStartPos;
|
QPointF mRubberBandStartPos;
|
||||||
|
|
||||||
|
QgsLayoutMouseHandles *mMouseHandles = nullptr; //owned by scene
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSLAYOUTVIEWTOOLSELECT_H
|
#endif // QGSLAYOUTVIEWTOOLSELECT_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user