From 4065a7ff676f37eb89a99d096e0a581bb75cc6f4 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 5 Jul 2017 18:47:53 +1000 Subject: [PATCH] Add shell for non-functional layout select tool --- python/gui/gui_auto.sip | 1 + python/gui/layout/qgslayoutviewtoolselect.sip | 45 +++++++++++ src/app/layout/qgslayoutdesignerdialog.cpp | 5 ++ src/app/layout/qgslayoutdesignerdialog.h | 3 +- src/gui/CMakeLists.txt | 2 + src/gui/layout/qgslayoutviewtoolselect.cpp | 76 +++++++++++++++++++ src/gui/layout/qgslayoutviewtoolselect.h | 62 +++++++++++++++ src/ui/layout/qgslayoutdesignerbase.ui | 19 +++++ 8 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 python/gui/layout/qgslayoutviewtoolselect.sip create mode 100644 src/gui/layout/qgslayoutviewtoolselect.cpp create mode 100644 src/gui/layout/qgslayoutviewtoolselect.h diff --git a/python/gui/gui_auto.sip b/python/gui/gui_auto.sip index 3cf57ef3593..590b0d5906d 100644 --- a/python/gui/gui_auto.sip +++ b/python/gui/gui_auto.sip @@ -282,6 +282,7 @@ %Include layout/qgslayoutviewtool.sip %Include layout/qgslayoutviewtooladditem.sip %Include layout/qgslayoutviewtoolpan.sip +%Include layout/qgslayoutviewtoolselect.sip %Include layout/qgslayoutviewtoolzoom.sip %Include locator/qgslocator.sip %Include locator/qgslocatorfilter.sip diff --git a/python/gui/layout/qgslayoutviewtoolselect.sip b/python/gui/layout/qgslayoutviewtoolselect.sip new file mode 100644 index 00000000000..d2dda218ace --- /dev/null +++ b/python/gui/layout/qgslayoutviewtoolselect.sip @@ -0,0 +1,45 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/layout/qgslayoutviewtoolselect.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + +class QgsLayoutViewToolSelect : QgsLayoutViewTool +{ +%Docstring + Layout view tool for selecting items in the layout. +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgslayoutviewtoolselect.h" +%End + public: + + QgsLayoutViewToolSelect( QgsLayoutView *view ); +%Docstring + Constructor for QgsLayoutViewToolSelect. +%End + + virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event ); + + virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event ); + + virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ); + + virtual void deactivate(); + + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/layout/qgslayoutviewtoolselect.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index f2b71d9b1fb..962521a22dd 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -25,6 +25,7 @@ #include "qgslayoutviewtooladditem.h" #include "qgslayoutviewtoolpan.h" #include "qgslayoutviewtoolzoom.h" +#include "qgslayoutviewtoolselect.h" QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog ) : QgsLayoutDesignerInterface( dialog ) @@ -106,6 +107,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla mZoomTool->setAction( mActionZoomTool ); mToolsActionGroup->addAction( mActionZoomTool ); connect( mActionZoomTool, &QAction::triggered, mZoomTool, [ = ] { mView->setTool( mZoomTool ); } ); + mSelectTool = new QgsLayoutViewToolSelect( mView ); + mSelectTool->setAction( mActionSelectMoveItem ); + mToolsActionGroup->addAction( mActionSelectMoveItem ); + connect( mActionSelectMoveItem, &QAction::triggered, mSelectTool, [ = ] { mView->setTool( mSelectTool ); } ); restoreWindowState(); diff --git a/src/app/layout/qgslayoutdesignerdialog.h b/src/app/layout/qgslayoutdesignerdialog.h index e0f01d24a5a..f5c739f028b 100644 --- a/src/app/layout/qgslayoutdesignerdialog.h +++ b/src/app/layout/qgslayoutdesignerdialog.h @@ -25,6 +25,7 @@ class QgsLayoutView; class QgsLayoutViewToolAddItem; class QgsLayoutViewToolPan; class QgsLayoutViewToolZoom; +class QgsLayoutViewToolSelect; class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface { @@ -129,7 +130,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner QgsLayoutViewToolAddItem *mAddItemTool = nullptr; QgsLayoutViewToolPan *mPanTool = nullptr; QgsLayoutViewToolZoom *mZoomTool = nullptr; - + QgsLayoutViewToolSelect *mSelectTool = nullptr; //! Save window state void saveWindowState(); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index f066dea94cb..f5a25f9a8cd 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -165,6 +165,7 @@ SET(QGIS_GUI_SRCS layout/qgslayoutviewtool.cpp layout/qgslayoutviewtooladditem.cpp layout/qgslayoutviewtoolpan.cpp + layout/qgslayoutviewtoolselect.cpp layout/qgslayoutviewtoolzoom.cpp locator/qgslocator.cpp @@ -633,6 +634,7 @@ SET(QGIS_GUI_MOC_HDRS layout/qgslayoutviewtool.h layout/qgslayoutviewtooladditem.h layout/qgslayoutviewtoolpan.h + layout/qgslayoutviewtoolselect.h layout/qgslayoutviewtoolzoom.h locator/qgslocator.h diff --git a/src/gui/layout/qgslayoutviewtoolselect.cpp b/src/gui/layout/qgslayoutviewtoolselect.cpp new file mode 100644 index 00000000000..e5f88168b0b --- /dev/null +++ b/src/gui/layout/qgslayoutviewtoolselect.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + qgslayoutviewtoolselect.cpp + --------------------------- + Date : July 2017 + Copyright : (C) 2017 Nyall Dawson + Email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgslayoutviewtoolselect.h" +#include "qgslayoutviewmouseevent.h" +#include "qgslayoutview.h" + +QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view ) + : QgsLayoutViewTool( view, tr( "Select" ) ) +{ + setCursor( Qt::ArrowCursor ); + + mRubberBand.reset( new QgsLayoutViewRectangularRubberBand( view ) ); + mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) ); + mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) ); +} + +void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event ) +{ + if ( event->button() != Qt::LeftButton ) + { + event->ignore(); + return; + } + + mIsSelecting = true; + mMousePressStartPos = event->pos(); + mRubberBand->start( event->layoutPoint(), 0 ); +} + +void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event ) +{ + if ( mIsSelecting ) + { + mRubberBand->update( event->layoutPoint(), 0 ); + } + else + { + event->ignore(); + } +} + +void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) +{ + if ( !mIsSelecting || event->button() != Qt::LeftButton ) + { + event->ignore(); + return; + } + + mIsSelecting = false; + QRectF rect = mRubberBand->finish( event->layoutPoint(), event->modifiers() ); + Q_UNUSED( rect ); +} + +void QgsLayoutViewToolSelect::deactivate() +{ + if ( mIsSelecting ) + { + mRubberBand->finish(); + mIsSelecting = false; + } + QgsLayoutViewTool::deactivate(); +} diff --git a/src/gui/layout/qgslayoutviewtoolselect.h b/src/gui/layout/qgslayoutviewtoolselect.h new file mode 100644 index 00000000000..1957d8876bd --- /dev/null +++ b/src/gui/layout/qgslayoutviewtoolselect.h @@ -0,0 +1,62 @@ +/*************************************************************************** + qgslayoutviewtoolselect.h + ------------------------- + Date : July 2017 + Copyright : (C) 2017 Nyall Dawson + Email : nyall dot dawson at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSLAYOUTVIEWTOOLSELECT_H +#define QGSLAYOUTVIEWTOOLSELECT_H + +#include "qgis.h" +#include "qgis_gui.h" +#include "qgslayoutviewtool.h" +#include "qgslayoutviewrubberband.h" +#include + +/** + * \ingroup gui + * Layout view tool for selecting items in the layout. + * \since QGIS 3.0 + */ +class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool +{ + + Q_OBJECT + + public: + + /** + * Constructor for QgsLayoutViewToolSelect. + */ + QgsLayoutViewToolSelect( QgsLayoutView *view ); + + void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override; + void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override; + void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override; + void deactivate() override; + + private: + + bool mIsSelecting = false; + + //! Rubber band item + std::unique_ptr< QgsLayoutViewRubberBand > mRubberBand; + + //! Start position for mouse press + QPoint mMousePressStartPos; + + //! Start of rubber band creation + QPointF mRubberBandStartPos; + +}; + +#endif // QGSLAYOUTVIEWTOOLSELECT_H diff --git a/src/ui/layout/qgslayoutdesignerbase.ui b/src/ui/layout/qgslayoutdesignerbase.ui index 7cc92a8f7d7..34eb498c93b 100644 --- a/src/ui/layout/qgslayoutdesignerbase.ui +++ b/src/ui/layout/qgslayoutdesignerbase.ui @@ -75,6 +75,7 @@ + @@ -143,6 +144,24 @@ Z + + + true + + + + :/images/themes/default/mActionSelect.svg:/images/themes/default/mActionSelect.svg + + + Move &Item + + + Select/Move item + + + V + +