Skip to content

Commit 88a7f02

Browse files
committedOct 6, 2017
Port preview modes from composer
1 parent b04c101 commit 88a7f02

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed
 

‎python/gui/layout/qgslayoutview.sip

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ class QgsLayoutView: QGraphicsView
6868
You don't have to call it manually, QgsLayoutViewTool takes care of it.
6969
%End
7070

71+
void setPreviewModeEnabled( bool enabled );
72+
%Docstring
73+
Sets whether a preview effect should be used to alter the view's appearance.
74+
\param enabled Set to true to enable the preview effect on the view.
75+
.. seealso:: setPreviewMode()
76+
%End
77+
78+
bool previewModeEnabled() const;
79+
%Docstring
80+
Returns true if a preview effect is being used to alter the view's appearance.
81+
.. seealso:: setPreviewModeEnabled()
82+
:rtype: bool
83+
%End
84+
85+
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
86+
%Docstring
87+
Sets the preview ``mode`` which should be used to modify the view's appearance. Preview modes are only used
88+
if previewModeEnabled() is true.
89+
.. seealso:: setPreviewModeEnabled()
90+
.. seealso:: previewMode()
91+
%End
92+
93+
QgsPreviewEffect::PreviewMode previewMode() const;
94+
%Docstring
95+
Returns the preview mode which may be used to modify the view's appearance. Preview modes are only used
96+
if previewModeEnabled() is true.
97+
.. seealso:: setPreviewMode()
98+
.. seealso:: previewModeEnabled()
99+
:rtype: QgsPreviewEffect.PreviewMode
100+
%End
101+
71102
void scaleSafe( double scale );
72103
%Docstring
73104
Scales the view in a safe way, by limiting the acceptable range

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,38 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
242242
QShortcut *backSpace = new QShortcut( QKeySequence( QStringLiteral( "Backspace" ) ), this );
243243
connect( backSpace, &QShortcut::activated, mActionDeleteSelection, &QAction::trigger );
244244

245+
mActionPreviewModeOff->setChecked( true );
246+
connect( mActionPreviewModeOff, &QAction::triggered, this, [ = ]
247+
{
248+
mView->setPreviewModeEnabled( false );
249+
} );
250+
connect( mActionPreviewModeGrayscale, &QAction::triggered, this, [ = ]
251+
{
252+
mView->setPreviewMode( QgsPreviewEffect::PreviewGrayscale );
253+
mView->setPreviewModeEnabled( true );
254+
} );
255+
connect( mActionPreviewModeMono, &QAction::triggered, this, [ = ]
256+
{
257+
mView->setPreviewMode( QgsPreviewEffect::PreviewMono );
258+
mView->setPreviewModeEnabled( true );
259+
} );
260+
connect( mActionPreviewProtanope, &QAction::triggered, this, [ = ]
261+
{
262+
mView->setPreviewMode( QgsPreviewEffect::PreviewProtanope );
263+
mView->setPreviewModeEnabled( true );
264+
} );
265+
connect( mActionPreviewDeuteranope, &QAction::triggered, this, [ = ]
266+
{
267+
mView->setPreviewMode( QgsPreviewEffect::PreviewDeuteranope );
268+
mView->setPreviewModeEnabled( true );
269+
} );
270+
QActionGroup *previewGroup = new QActionGroup( this );
271+
previewGroup->setExclusive( true );
272+
mActionPreviewModeOff->setActionGroup( previewGroup );
273+
mActionPreviewModeGrayscale->setActionGroup( previewGroup );
274+
mActionPreviewModeMono->setActionGroup( previewGroup );
275+
mActionPreviewProtanope->setActionGroup( previewGroup );
276+
mActionPreviewDeuteranope->setActionGroup( previewGroup );
245277

246278
connect( mActionZoomIn, &QAction::triggered, mView, &QgsLayoutView::zoomIn );
247279
connect( mActionZoomOut, &QAction::triggered, mView, &QgsLayoutView::zoomOut );

‎src/gui/layout/qgslayoutview.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
5454
mMidMouseButtonPanTool = new QgsLayoutViewToolTemporaryMousePan( this );
5555
mSpaceZoomTool = new QgsLayoutViewToolTemporaryKeyZoom( this );
5656
mSnapMarker.reset( new QgsLayoutViewSnapMarker() );
57+
58+
mPreviewEffect = new QgsPreviewEffect( this );
59+
viewport()->setGraphicsEffect( mPreviewEffect );
5760
}
5861

5962
QgsLayout *QgsLayoutView::currentLayout()
@@ -146,6 +149,26 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool )
146149
}
147150
}
148151

152+
void QgsLayoutView::setPreviewModeEnabled( bool enabled )
153+
{
154+
mPreviewEffect->setEnabled( enabled );
155+
}
156+
157+
bool QgsLayoutView::previewModeEnabled() const
158+
{
159+
return mPreviewEffect->isEnabled();
160+
}
161+
162+
void QgsLayoutView::setPreviewMode( QgsPreviewEffect::PreviewMode mode )
163+
{
164+
mPreviewEffect->setMode( mode );
165+
}
166+
167+
QgsPreviewEffect::PreviewMode QgsLayoutView::previewMode() const
168+
{
169+
return mPreviewEffect->mode();
170+
}
171+
149172
void QgsLayoutView::scaleSafe( double scale )
150173
{
151174
double currentScale = transform().m11();

‎src/gui/layout/qgslayoutview.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
103103
*/
104104
void unsetTool( QgsLayoutViewTool *tool );
105105

106+
/**
107+
* Sets whether a preview effect should be used to alter the view's appearance.
108+
* \param enabled Set to true to enable the preview effect on the view.
109+
* \see setPreviewMode()
110+
*/
111+
void setPreviewModeEnabled( bool enabled );
112+
113+
/**
114+
* Returns true if a preview effect is being used to alter the view's appearance.
115+
* \see setPreviewModeEnabled()
116+
*/
117+
bool previewModeEnabled() const;
118+
119+
/**
120+
* Sets the preview \a mode which should be used to modify the view's appearance. Preview modes are only used
121+
* if previewModeEnabled() is true.
122+
* \see setPreviewModeEnabled()
123+
* \see previewMode()
124+
*/
125+
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
126+
127+
/**
128+
* Returns the preview mode which may be used to modify the view's appearance. Preview modes are only used
129+
* if previewModeEnabled() is true.
130+
* \see setPreviewMode()
131+
* \see previewModeEnabled()
132+
*/
133+
QgsPreviewEffect::PreviewMode previewMode() const;
134+
106135
/**
107136
* Scales the view in a safe way, by limiting the acceptable range
108137
* of the scale applied. The \a scale parameter specifies the zoom factor to scale the view by.
@@ -428,6 +457,8 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
428457

429458
int mCurrentPage = 0;
430459

460+
QgsPreviewEffect *mPreviewEffect = nullptr;
461+
431462
friend class TestQgsLayoutView;
432463
friend class QgsLayoutMouseHandles;
433464

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<x>0</x>
8686
<y>0</y>
8787
<width>1083</width>
88-
<height>42</height>
88+
<height>25</height>
8989
</rect>
9090
</property>
9191
<widget class="QMenu" name="mLayoutMenu">
@@ -116,6 +116,18 @@
116116
<string>&amp;Panels</string>
117117
</property>
118118
</widget>
119+
<widget class="QMenu" name="menuPreview">
120+
<property name="title">
121+
<string>&amp;Preview</string>
122+
</property>
123+
<addaction name="mActionPreviewModeOff"/>
124+
<addaction name="mActionPreviewModeGrayscale"/>
125+
<addaction name="mActionPreviewModeMono"/>
126+
<addaction name="mActionPreviewProtanope"/>
127+
<addaction name="mActionPreviewDeuteranope"/>
128+
</widget>
129+
<addaction name="menuPreview"/>
130+
<addaction name="separator"/>
119131
<addaction name="mActionZoomIn"/>
120132
<addaction name="mActionZoomOut"/>
121133
<addaction name="mActionZoomActual"/>
@@ -925,6 +937,49 @@
925937
<string>Resizes items to squares</string>
926938
</property>
927939
</action>
940+
<action name="mActionPreviewModeOff">
941+
<property name="checkable">
942+
<bool>true</bool>
943+
</property>
944+
<property name="text">
945+
<string>&amp;Normal</string>
946+
</property>
947+
<property name="toolTip">
948+
<string>Normal</string>
949+
</property>
950+
</action>
951+
<action name="mActionPreviewModeGrayscale">
952+
<property name="checkable">
953+
<bool>true</bool>
954+
</property>
955+
<property name="text">
956+
<string>Simulate Photocopy (&amp;Grayscale)</string>
957+
</property>
958+
</action>
959+
<action name="mActionPreviewModeMono">
960+
<property name="checkable">
961+
<bool>true</bool>
962+
</property>
963+
<property name="text">
964+
<string>Simulate Fax (&amp;Mono)</string>
965+
</property>
966+
</action>
967+
<action name="mActionPreviewProtanope">
968+
<property name="checkable">
969+
<bool>true</bool>
970+
</property>
971+
<property name="text">
972+
<string>Simulate Color Blindness (&amp;Protanope)</string>
973+
</property>
974+
</action>
975+
<action name="mActionPreviewDeuteranope">
976+
<property name="checkable">
977+
<bool>true</bool>
978+
</property>
979+
<property name="text">
980+
<string>Simulate Color Blindness (&amp;Deuteranope)</string>
981+
</property>
982+
</action>
928983
</widget>
929984
<resources>
930985
<include location="../../../images/images.qrc"/>
@@ -953,6 +1008,7 @@
9531008
<include location="../../../images/images.qrc"/>
9541009
<include location="../../../images/images.qrc"/>
9551010
<include location="../../../images/images.qrc"/>
1011+
<include location="../../../images/images.qrc"/>
9561012
</resources>
9571013
<connections/>
9581014
</ui>

0 commit comments

Comments
 (0)