Skip to content

Commit

Permalink
Port preview modes from composer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent b04c101 commit 88a7f02
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 1 deletion.
31 changes: 31 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ class QgsLayoutView: QGraphicsView
You don't have to call it manually, QgsLayoutViewTool takes care of it.
%End

void setPreviewModeEnabled( bool enabled );
%Docstring
Sets whether a preview effect should be used to alter the view's appearance.
\param enabled Set to true to enable the preview effect on the view.
.. seealso:: setPreviewMode()
%End

bool previewModeEnabled() const;
%Docstring
Returns true if a preview effect is being used to alter the view's appearance.
.. seealso:: setPreviewModeEnabled()
:rtype: bool
%End

void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
%Docstring
Sets the preview ``mode`` which should be used to modify the view's appearance. Preview modes are only used
if previewModeEnabled() is true.
.. seealso:: setPreviewModeEnabled()
.. seealso:: previewMode()
%End

QgsPreviewEffect::PreviewMode previewMode() const;
%Docstring
Returns the preview mode which may be used to modify the view's appearance. Preview modes are only used
if previewModeEnabled() is true.
.. seealso:: setPreviewMode()
.. seealso:: previewModeEnabled()
:rtype: QgsPreviewEffect.PreviewMode
%End

void scaleSafe( double scale );
%Docstring
Scales the view in a safe way, by limiting the acceptable range
Expand Down
32 changes: 32 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
QShortcut *backSpace = new QShortcut( QKeySequence( QStringLiteral( "Backspace" ) ), this );
connect( backSpace, &QShortcut::activated, mActionDeleteSelection, &QAction::trigger );

mActionPreviewModeOff->setChecked( true );
connect( mActionPreviewModeOff, &QAction::triggered, this, [ = ]
{
mView->setPreviewModeEnabled( false );
} );
connect( mActionPreviewModeGrayscale, &QAction::triggered, this, [ = ]
{
mView->setPreviewMode( QgsPreviewEffect::PreviewGrayscale );
mView->setPreviewModeEnabled( true );
} );
connect( mActionPreviewModeMono, &QAction::triggered, this, [ = ]
{
mView->setPreviewMode( QgsPreviewEffect::PreviewMono );
mView->setPreviewModeEnabled( true );
} );
connect( mActionPreviewProtanope, &QAction::triggered, this, [ = ]
{
mView->setPreviewMode( QgsPreviewEffect::PreviewProtanope );
mView->setPreviewModeEnabled( true );
} );
connect( mActionPreviewDeuteranope, &QAction::triggered, this, [ = ]
{
mView->setPreviewMode( QgsPreviewEffect::PreviewDeuteranope );
mView->setPreviewModeEnabled( true );
} );
QActionGroup *previewGroup = new QActionGroup( this );
previewGroup->setExclusive( true );
mActionPreviewModeOff->setActionGroup( previewGroup );
mActionPreviewModeGrayscale->setActionGroup( previewGroup );
mActionPreviewModeMono->setActionGroup( previewGroup );
mActionPreviewProtanope->setActionGroup( previewGroup );
mActionPreviewDeuteranope->setActionGroup( previewGroup );

connect( mActionZoomIn, &QAction::triggered, mView, &QgsLayoutView::zoomIn );
connect( mActionZoomOut, &QAction::triggered, mView, &QgsLayoutView::zoomOut );
Expand Down
23 changes: 23 additions & 0 deletions src/gui/layout/qgslayoutview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );

mPreviewEffect = new QgsPreviewEffect( this );
viewport()->setGraphicsEffect( mPreviewEffect );
}

QgsLayout *QgsLayoutView::currentLayout()
Expand Down Expand Up @@ -146,6 +149,26 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool )
}
}

void QgsLayoutView::setPreviewModeEnabled( bool enabled )
{
mPreviewEffect->setEnabled( enabled );
}

bool QgsLayoutView::previewModeEnabled() const
{
return mPreviewEffect->isEnabled();
}

void QgsLayoutView::setPreviewMode( QgsPreviewEffect::PreviewMode mode )
{
mPreviewEffect->setMode( mode );
}

QgsPreviewEffect::PreviewMode QgsLayoutView::previewMode() const
{
return mPreviewEffect->mode();
}

void QgsLayoutView::scaleSafe( double scale )
{
double currentScale = transform().m11();
Expand Down
31 changes: 31 additions & 0 deletions src/gui/layout/qgslayoutview.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void unsetTool( QgsLayoutViewTool *tool );

/**
* Sets whether a preview effect should be used to alter the view's appearance.
* \param enabled Set to true to enable the preview effect on the view.
* \see setPreviewMode()
*/
void setPreviewModeEnabled( bool enabled );

/**
* Returns true if a preview effect is being used to alter the view's appearance.
* \see setPreviewModeEnabled()
*/
bool previewModeEnabled() const;

/**
* Sets the preview \a mode which should be used to modify the view's appearance. Preview modes are only used
* if previewModeEnabled() is true.
* \see setPreviewModeEnabled()
* \see previewMode()
*/
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );

/**
* Returns the preview mode which may be used to modify the view's appearance. Preview modes are only used
* if previewModeEnabled() is true.
* \see setPreviewMode()
* \see previewModeEnabled()
*/
QgsPreviewEffect::PreviewMode previewMode() const;

/**
* Scales the view in a safe way, by limiting the acceptable range
* of the scale applied. The \a scale parameter specifies the zoom factor to scale the view by.
Expand Down Expand Up @@ -428,6 +457,8 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView

int mCurrentPage = 0;

QgsPreviewEffect *mPreviewEffect = nullptr;

friend class TestQgsLayoutView;
friend class QgsLayoutMouseHandles;

Expand Down
58 changes: 57 additions & 1 deletion src/ui/layout/qgslayoutdesignerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<x>0</x>
<y>0</y>
<width>1083</width>
<height>42</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="mLayoutMenu">
Expand Down Expand Up @@ -116,6 +116,18 @@
<string>&amp;Panels</string>
</property>
</widget>
<widget class="QMenu" name="menuPreview">
<property name="title">
<string>&amp;Preview</string>
</property>
<addaction name="mActionPreviewModeOff"/>
<addaction name="mActionPreviewModeGrayscale"/>
<addaction name="mActionPreviewModeMono"/>
<addaction name="mActionPreviewProtanope"/>
<addaction name="mActionPreviewDeuteranope"/>
</widget>
<addaction name="menuPreview"/>
<addaction name="separator"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActual"/>
Expand Down Expand Up @@ -925,6 +937,49 @@
<string>Resizes items to squares</string>
</property>
</action>
<action name="mActionPreviewModeOff">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Normal</string>
</property>
<property name="toolTip">
<string>Normal</string>
</property>
</action>
<action name="mActionPreviewModeGrayscale">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate Photocopy (&amp;Grayscale)</string>
</property>
</action>
<action name="mActionPreviewModeMono">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate Fax (&amp;Mono)</string>
</property>
</action>
<action name="mActionPreviewProtanope">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate Color Blindness (&amp;Protanope)</string>
</property>
</action>
<action name="mActionPreviewDeuteranope">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate Color Blindness (&amp;Deuteranope)</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down Expand Up @@ -953,6 +1008,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 88a7f02

Please sign in to comment.