Skip to content
Permalink
Browse files

Port zoom actions from composer to layout designer

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent cf488d3 commit ac83093570e331be6173b4dabaebd2b5957ea830
@@ -73,6 +73,45 @@ class QgsLayoutView: QGraphicsView
of the scale applied. The ``scale`` parameter specifies the zoom factor to scale the view by.
%End

void setZoomLevel( double level );
%Docstring
Sets the zoom ``level`` for the view, where a zoom level of 1.0 corresponds to 100%.
%End

public slots:

void zoomFull();
%Docstring
Zooms the view to the full extent of the layout.
.. seealso:: zoomIn()
.. seealso:: zoomOut()
.. seealso:: zoomActual()
%End

void zoomIn();
%Docstring
Zooms in to the view by a preset amount.
.. seealso:: zoomFull()
.. seealso:: zoomOut()
.. seealso:: zoomActual()
%End

void zoomOut();
%Docstring
Zooms out of the view by a preset amount.
.. seealso:: zoomFull()
.. seealso:: zoomIn()
.. seealso:: zoomActual()
%End

void zoomActual();
%Docstring
Zooms to the actual size of the layout.
.. seealso:: zoomFull()
.. seealso:: zoomIn()
.. seealso:: zoomOut()
%End

signals:

void layoutSet( QgsLayout *layout );
@@ -28,6 +28,7 @@
#include "qgslayoutviewtoolselect.h"
#include "qgsgui.h"
#include "qgslayoutitemguiregistry.h"
#include <QShortcut>

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
@@ -112,6 +113,15 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mToolsActionGroup->addAction( mActionSelectMoveItem );
connect( mActionSelectMoveItem, &QAction::triggered, mSelectTool, [ = ] { mView->setTool( mSelectTool ); } );

//Ctrl+= should also trigger zoom in
QShortcut *ctrlEquals = new QShortcut( QKeySequence( QStringLiteral( "Ctrl+=" ) ), this );
connect( ctrlEquals, &QShortcut::activated, mActionZoomIn, &QAction::trigger );

connect( mActionZoomIn, &QAction::triggered, mView, &QgsLayoutView::zoomIn );
connect( mActionZoomOut, &QAction::triggered, mView, &QgsLayoutView::zoomOut );
connect( mActionZoomAll, &QAction::triggered, mView, &QgsLayoutView::zoomFull );
connect( mActionZoomActual, &QAction::triggered, mView, &QgsLayoutView::zoomActual );

mView->setTool( mSelectTool );
mView->setFocus();

@@ -24,7 +24,9 @@
#include "qgslayoutviewtooltemporarymousepan.h"
#include "qgssettings.h"
#include "qgsrectangle.h"
#include "qgsapplication.h"
#include <memory>
#include <QDesktopWidget>

#define MIN_VIEW_SCALE 0.05
#define MAX_VIEW_SCALE 1000.0
@@ -95,6 +97,38 @@ void QgsLayoutView::scaleSafe( double scale )
setTransform( QTransform::fromScale( scale, scale ) );
}

void QgsLayoutView::setZoomLevel( double level )
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if ( ( dpi < 60 ) || ( dpi > 1200 ) )
dpi = 72;

//desired pixel width for 1mm on screen
double scale = qBound( MIN_VIEW_SCALE, level * dpi / 25.4, MAX_VIEW_SCALE );
setTransform( QTransform::fromScale( scale, scale ) );
}

void QgsLayoutView::zoomFull()
{
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
}

void QgsLayoutView::zoomIn()
{
scaleSafe( 2 );
}

void QgsLayoutView::zoomOut()
{
scaleSafe( 0.5 );
}

void QgsLayoutView::zoomActual()
{
setZoomLevel( 1.0 );
}

void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
if ( mTool )
@@ -94,6 +94,45 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void scaleSafe( double scale );

/**
* Sets the zoom \a level for the view, where a zoom level of 1.0 corresponds to 100%.
*/
void setZoomLevel( double level );

public slots:

/**
* Zooms the view to the full extent of the layout.
* \see zoomIn()
* \see zoomOut()
* \see zoomActual()
*/
void zoomFull();

/**
* Zooms in to the view by a preset amount.
* \see zoomFull()
* \see zoomOut()
* \see zoomActual()
*/
void zoomIn();

/**
* Zooms out of the view by a preset amount.
* \see zoomFull()
* \see zoomIn()
* \see zoomActual()
*/
void zoomOut();

/**
* Zooms to the actual size of the layout.
* \see zoomFull()
* \see zoomIn()
* \see zoomOut()
*/
void zoomActual();

signals:

/**
@@ -83,7 +83,7 @@
<x>0</x>
<y>0</y>
<width>1083</width>
<height>42</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="mLayoutMenu">
@@ -97,9 +97,34 @@
<string>&amp;Items</string>
</property>
</widget>
<widget class="QMenu" name="mMenuView">
<property name="title">
<string>View</string>
</property>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActual"/>
<addaction name="mActionZoomAll"/>
</widget>
<addaction name="mLayoutMenu"/>
<addaction name="mMenuView"/>
<addaction name="mItemMenu"/>
</widget>
<widget class="QToolBar" name="mNavigationToolbar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActual"/>
<addaction name="mActionZoomAll"/>
</widget>
<action name="mActionClose">
<property name="text">
<string>&amp;Close</string>
@@ -162,6 +187,66 @@
<string>V</string>
</property>
</action>
<action name="mActionZoomAll">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomFullExtent.svg</normaloff>:/images/themes/default/mActionZoomFullExtent.svg</iconset>
</property>
<property name="text">
<string>Zoom &amp;Full</string>
</property>
<property name="toolTip">
<string>Zoom full</string>
</property>
<property name="shortcut">
<string>Ctrl+0</string>
</property>
</action>
<action name="mActionZoomIn">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomIn.svg</normaloff>:/images/themes/default/mActionZoomIn.svg</iconset>
</property>
<property name="text">
<string>Zoom &amp;In</string>
</property>
<property name="toolTip">
<string>Zoom in</string>
</property>
<property name="shortcut">
<string>Ctrl++</string>
</property>
</action>
<action name="mActionZoomOut">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomOut.svg</normaloff>:/images/themes/default/mActionZoomOut.svg</iconset>
</property>
<property name="text">
<string>Zoom &amp;Out</string>
</property>
<property name="toolTip">
<string>Zoom out</string>
</property>
<property name="shortcut">
<string>Ctrl+-</string>
</property>
</action>
<action name="mActionZoomActual">
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomActual.svg</normaloff>:/images/themes/default/mActionZoomActual.svg</iconset>
</property>
<property name="text">
<string>Zoom to &amp;100%</string>
</property>
<property name="toolTip">
<string>Zoom to 100%</string>
</property>
<property name="shortcut">
<string>Ctrl+1</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
@@ -189,6 +274,7 @@
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit ac83093

Please sign in to comment.
You can’t perform that action at this time.