Skip to content
Permalink
Browse files
[FEATURE][composer] Add preview modes for composer, allows for previe…
…wing composition in grayscale, monochrome and color blindness simulation modes prior to printing (refs #9886)
  • Loading branch information
nyalldawson committed May 18, 2014
1 parent 2ce7416 commit 1b49a473a93f6e371cb97f6c05543343cc6a7939
@@ -109,6 +109,20 @@ class QgsComposerView : QGraphicsView
/**Set zoom level, where a zoom level of 1.0 corresponds to 100%*/
void setZoomLevel( double zoomLevel );

/**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
* @note added in 2.3
* @see setPreviewMode
*/
void setPreviewModeEnabled( bool enabled );
/**Sets the preview mode which should be used to modify the view's appearance. Preview modes are only used
* if setPreviewMode is set to true.
* @param mode PreviewMode to be used to draw the view
* @note added in 2.3
* @see setPreviewModeEnabled
*/
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );

protected:
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
@@ -0,0 +1,39 @@
/** \ingroup gui
* A graphics effect which can be applied to a widget to simulate various printing and
* color blindness modes.
*/
class QgsPreviewEffect : QGraphicsEffect
{
%TypeHeaderCode
#include "qgsgraphicseffect.h"
%End

public:
enum PreviewMode
{
PreviewGrayscale,
PreviewMono,
PreviewProtanope,
PreviewDeuteranope
};

QgsPreviewEffect( QObject* parent );
~QgsPreviewEffect();

/**Sets the mode for the preview effect, which controls how the effect modifies a widgets appearance.
* @param mode PreviewMode to use to draw the widget
* @note added in 2.3
* @see mode
*/
void setMode( PreviewMode mode );

/**Returns the mode used for the preview effect.
* @returns PreviewMode currently used by the effect
* @note added in 2.3
* @see setMode
*/
PreviewMode mode() const;

protected:
virtual void draw( QPainter *painter );
};
@@ -57,6 +57,7 @@
#include "qgsgeometry.h"
#include "qgspaperitem.h"
#include "qgsmaplayerregistry.h"
#include "qgsprevieweffect.h"
#include "ui_qgssvgexportoptions.h"

#include <QCloseEvent>
@@ -260,10 +261,49 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
editMenu->addAction( mActionSelectNextBelow );
editMenu->addAction( mActionSelectNextAbove );

mActionPreviewModeOff = new QAction( tr( "Normal" ), this );
mActionPreviewModeOff->setStatusTip( tr( "Normal" ) );
mActionPreviewModeOff->setCheckable( true );
mActionPreviewModeOff->setChecked( true );
connect( mActionPreviewModeOff, SIGNAL( triggered() ), this, SLOT( disablePreviewMode() ) );
mActionPreviewModeGrayscale = new QAction( tr( "Simulate photocopy (grayscale)" ), this );
mActionPreviewModeGrayscale->setStatusTip( tr( "Simulate photocopy (grayscale)" ) );
mActionPreviewModeGrayscale->setCheckable( true );
connect( mActionPreviewModeGrayscale, SIGNAL( triggered() ), this, SLOT( activateGrayscalePreview() ) );
mActionPreviewModeMono = new QAction( tr( "Simulate fax (mono)" ), this );
mActionPreviewModeMono->setStatusTip( tr( "Simulate fax (mono)" ) );
mActionPreviewModeMono->setCheckable( true );
connect( mActionPreviewModeMono, SIGNAL( triggered() ), this, SLOT( activateMonoPreview() ) );
mActionPreviewProtanope = new QAction( tr( "Simulate color blindness (Protanope)" ), this );
mActionPreviewProtanope->setStatusTip( tr( "Simulate color blindness (Protanope)" ) );
mActionPreviewProtanope->setCheckable( true );
connect( mActionPreviewProtanope, SIGNAL( triggered() ), this, SLOT( activateProtanopePreview() ) );
mActionPreviewDeuteranope = new QAction( tr( "Simulate color blindness (Deuteranope)" ), this );
mActionPreviewDeuteranope->setStatusTip( tr( "Simulate color blindness (Deuteranope)" ) );
mActionPreviewDeuteranope->setCheckable( true );
connect( mActionPreviewDeuteranope, SIGNAL( triggered() ), this, SLOT( activateDeuteranopePreview() ) );

QActionGroup* mPreviewGroup = new QActionGroup( this );
mPreviewGroup->setExclusive( true );
mActionPreviewModeOff->setActionGroup( mPreviewGroup );
mActionPreviewModeGrayscale->setActionGroup( mPreviewGroup );
mActionPreviewModeMono->setActionGroup( mPreviewGroup );
mActionPreviewProtanope->setActionGroup( mPreviewGroup );
mActionPreviewDeuteranope->setActionGroup( mPreviewGroup );

QMenu *viewMenu = menuBar()->addMenu( tr( "View" ) );
//Ctrl+= should also trigger zoom in
QShortcut* ctrlEquals = new QShortcut( QKeySequence( "Ctrl+=" ), this );
connect( ctrlEquals, SIGNAL( activated() ), mActionZoomIn, SLOT( trigger() ) );

QMenu *previewMenu = viewMenu->addMenu( "Preview" );
previewMenu->addAction( mActionPreviewModeOff );
previewMenu->addAction( mActionPreviewModeGrayscale );
previewMenu->addAction( mActionPreviewModeMono );
previewMenu->addAction( mActionPreviewProtanope );
previewMenu->addAction( mActionPreviewDeuteranope );

viewMenu->addSeparator();
viewMenu->addAction( mActionZoomIn );
viewMenu->addAction( mActionZoomOut );
viewMenu->addAction( mActionZoomAll );
@@ -1101,6 +1141,60 @@ void QgsComposer::on_mActionAtlasSettings_triggered()
mAtlasDock->raise();
}

void QgsComposer::disablePreviewMode()
{
if ( !mView )
{
return;
}

mView->setPreviewModeEnabled( false );
}

void QgsComposer::activateGrayscalePreview()
{
if ( !mView )
{
return;
}

mView->setPreviewMode( QgsPreviewEffect::PreviewGrayscale );
mView->setPreviewModeEnabled( true );
}

void QgsComposer::activateMonoPreview()
{
if ( !mView )
{
return;
}

mView->setPreviewMode( QgsPreviewEffect::PreviewMono );
mView->setPreviewModeEnabled( true );
}

void QgsComposer::activateProtanopePreview()
{
if ( !mView )
{
return;
}

mView->setPreviewMode( QgsPreviewEffect::PreviewProtanope );
mView->setPreviewModeEnabled( true );
}

void QgsComposer::activateDeuteranopePreview()
{
if ( !mView )
{
return;
}

mView->setPreviewMode( QgsPreviewEffect::PreviewDeuteranope );
mView->setPreviewModeEnabled( true );
}

void QgsComposer::on_mActionExportAtlasAsPDF_triggered()
{
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
@@ -537,6 +537,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

QUndoView* mUndoView;

//! Preview mode actions
QAction *mActionPreviewModeOff;
QAction *mActionPreviewModeGrayscale;
QAction *mActionPreviewModeMono;
QAction *mActionPreviewProtanope;
QAction *mActionPreviewDeuteranope;

//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
QMap< QgsComposerMap*, int > mMapsToRestore;

@@ -602,6 +609,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Sets the printer page orientation when the page orientation changes
void setPrinterPageOrientation( QString orientation );

void disablePreviewMode();
void activateGrayscalePreview();
void activateMonoPreview();
void activateProtanopePreview();
void activateDeuteranopePreview();

};

#endif
@@ -72,6 +72,7 @@ qgscolorbutton.cpp
qgscolordialog.cpp
qgscomposerruler.cpp
qgscomposerview.cpp
qgsprevieweffect.cpp
qgscredentialdialog.cpp
qgscursors.cpp
qgsdatadefinedbutton.cpp
@@ -220,6 +221,7 @@ qgsbusyindicatordialog.h
qgscharacterselectdialog.h
qgscollapsiblegroupbox.h
qgscolordialog.h
qgsprevieweffect.h
qgscomposerruler.h
qgscomposerview.h
qgscredentialdialog.h
@@ -61,6 +61,7 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WindowF
, mMousePanning( false )
, mKeyPanning( false )
, mMovingItemContent( false )
, mPreviewEffect( 0 )
{
Q_UNUSED( f );
Q_UNUSED( name );
@@ -69,6 +70,9 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WindowF
setMouseTracking( true );
viewport()->setMouseTracking( true );
setFrameShape( QFrame::NoFrame );

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

void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
@@ -1501,6 +1505,26 @@ void QgsComposerView::setZoomLevel( double zoomLevel )
emit zoomLevelChanged();
}

void QgsComposerView::setPreviewModeEnabled( bool enabled )
{
if ( !mPreviewEffect )
{
return;
}

mPreviewEffect->setEnabled( enabled );
}

void QgsComposerView::setPreviewMode( QgsPreviewEffect::PreviewMode mode )
{
if ( !mPreviewEffect )
{
return;
}

mPreviewEffect->setMode( mode );
}

void QgsComposerView::paintEvent( QPaintEvent* event )
{
if ( mPaintingEnabled )
@@ -19,6 +19,7 @@

#include <QGraphicsView>
#include "qgsaddremoveitemcommand.h"
#include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode

class QDomDocument;
class QDomElement;
@@ -139,6 +140,20 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Set zoom level, where a zoom level of 1.0 corresponds to 100%*/
void setZoomLevel( double zoomLevel );

/**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
* @note added in 2.3
* @see setPreviewMode
*/
void setPreviewModeEnabled( bool enabled );
/**Sets the preview mode which should be used to modify the view's appearance. Preview modes are only used
* if setPreviewMode is set to true.
* @param mode PreviewMode to be used to draw the view
* @note added in 2.3
* @see setPreviewModeEnabled
*/
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );

protected:
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
@@ -204,6 +219,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
QPoint mMouseCurrentXY;
QPoint mMousePressStartPos;

QgsPreviewEffect* mPreviewEffect;

/**Returns the default mouse cursor for a tool*/
QCursor defaultCursorForTool( Tool currentTool );

0 comments on commit 1b49a47

Please sign in to comment.