Skip to content
Permalink
Browse files
[FEATURE] Add option to use colour preview modes (grayscale, colour b…
…lindess) in map canvas (fix #9886)
  • Loading branch information
nyalldawson committed May 21, 2014
1 parent 9551349 commit af7af6c26a493192af4ee673928974c091aa1894
Showing with 241 additions and 0 deletions.
  1. +30 −0 python/gui/qgsmapcanvas.sip
  2. +46 −0 src/app/qgisapp.cpp
  3. +17 −0 src/app/qgisapp.h
  4. +44 −0 src/gui/qgsmapcanvas.cpp
  5. +34 −0 src/gui/qgsmapcanvas.h
  6. +70 −0 src/ui/qgisapp.ui
@@ -263,6 +263,36 @@ class QgsMapCanvas : QGraphicsView

//! returns last position of mouse cursor
QPoint mouseLastXY();

/** Enables a preview mode for the map canvas
* @param previewEnabled set to true to enable a preview mode
* @see setPreviewMode
* @note added in 2.3 */
void setPreviewModeEnabled( bool previewEnabled );

/** Returns whether a preview mode is enabled for the map canvas
* @returns true if a preview mode is currently enabled
* @see setPreviewModeEnabled
* @see previewMode
* @note added in 2.3 */
bool previewModeEnabled() const;

/** Sets a preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* @param mode preview mode for the canvas
* @see previewMode
* @see setPreviewModeEnabled
* @see previewModeEnabled
* @note added in 2.3 */
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );

/** Returns the current preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* @returns preview mode for map canvas
* @see setPreviewMode
* @see previewModeEnabled
* @note added in 2.3 */
QgsPreviewEffect::PreviewMode previewMode() const;

public slots:

@@ -1287,6 +1287,16 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionMoveLabel );
mMapToolGroup->addAction( mActionRotateLabel );
mMapToolGroup->addAction( mActionChangeLabelProperties );

//
// Preview Modes Group
QActionGroup* mPreviewGroup = new QActionGroup( this );
mPreviewGroup->setExclusive( true );
mActionPreviewModeOff->setActionGroup( mPreviewGroup );
mActionPreviewModeGrayscale->setActionGroup( mPreviewGroup );
mActionPreviewModeMono->setActionGroup( mPreviewGroup );
mActionPreviewProtanope->setActionGroup( mPreviewGroup );
mActionPreviewDeuteranope->setActionGroup( mPreviewGroup );
}

void QgisApp::setAppStyleSheet( const QString& stylesheet )
@@ -1960,6 +1970,13 @@ void QgisApp::setupConnections()
connect( this, SIGNAL( projectRead() ),
this, SLOT( fileOpenedOKAfterLaunch() ) );

// connect preview modes actions
connect( mActionPreviewModeOff, SIGNAL( triggered() ), this, SLOT( disablePreviewMode() ) );
connect( mActionPreviewModeGrayscale, SIGNAL( triggered() ), this, SLOT( activateGrayscalePreview() ) );
connect( mActionPreviewModeMono, SIGNAL( triggered() ), this, SLOT( activateMonoPreview() ) );
connect( mActionPreviewProtanope, SIGNAL( triggered() ), this, SLOT( activateProtanopePreview() ) );
connect( mActionPreviewDeuteranope, SIGNAL( triggered() ), this, SLOT( activateDeuteranopePreview() ) );

// handle deprecated labels in project for QGIS 2.0
connect( this, SIGNAL( newProject() ),
this, SLOT( checkForDeprecatedLabelsInProject() ) );
@@ -3959,6 +3976,35 @@ void QgisApp::deleteComposerManager()
mComposerManager = 0;
}

void QgisApp::disablePreviewMode()
{
mMapCanvas->setPreviewModeEnabled( false );
}

void QgisApp::activateGrayscalePreview()
{
mMapCanvas->setPreviewModeEnabled( true );
mMapCanvas->setPreviewMode( QgsPreviewEffect::PreviewGrayscale );
}

void QgisApp::activateMonoPreview()
{
mMapCanvas->setPreviewModeEnabled( true );
mMapCanvas->setPreviewMode( QgsPreviewEffect::PreviewMono );
}

void QgisApp::activateProtanopePreview()
{
mMapCanvas->setPreviewModeEnabled( true );
mMapCanvas->setPreviewMode( QgsPreviewEffect::PreviewProtanope );
}

void QgisApp::activateDeuteranopePreview()
{
mMapCanvas->setPreviewModeEnabled( true );
mMapCanvas->setPreviewMode( QgsPreviewEffect::PreviewDeuteranope );
}

void QgisApp::saveMapAsImage()
{
QPair< QString, QString> myFileNameAndFilter = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
17 src/app/qgisapp.h 100644 → 100755
@@ -1189,6 +1189,22 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Deletes the active QgsComposerManager instance
void deleteComposerManager();

/** Disable any preview modes shown on the map canvas
* @note added in 2.3 */
void disablePreviewMode();
/** Enable a grayscale preview mode on the map canvas
* @note added in 2.3 */
void activateGrayscalePreview();
/** Enable a monochrome preview mode on the map canvas
* @note added in 2.3 */
void activateMonoPreview();
/** Enable a color blindness (protanope) preview mode on the map canvas
* @note added in 2.3 */
void activateProtanopePreview();
/** Enable a color blindness (deuteranope) preview mode on the map canvas
* @note added in 2.3 */
void activateDeuteranopePreview();

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -1343,6 +1359,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

// action groups ----------------------------------
QActionGroup *mMapToolGroup;
QActionGroup *mPreviewGroup;

// menus ------------------------------------------

44 src/gui/qgsmapcanvas.cpp 100644 → 100755
@@ -163,6 +163,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
, mUseParallelRendering( false )
, mDrawRenderingStats( false )
, mCache( 0 )
, mPreviewEffect( 0 )
{
setObjectName( name );
mScene = new QGraphicsScene();
@@ -227,6 +228,9 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
#endif

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

refresh();

} // QgsMapCanvas ctor
@@ -1606,6 +1610,46 @@ QPoint QgsMapCanvas::mouseLastXY()
return mCanvasProperties->mouseLastXY;
}

void QgsMapCanvas::setPreviewModeEnabled( bool previewEnabled )
{
if ( !mPreviewEffect )
{
return;
}

mPreviewEffect->setEnabled( previewEnabled );
}

bool QgsMapCanvas::previewModeEnabled() const
{
if ( !mPreviewEffect )
{
return false;
}

return mPreviewEffect->isEnabled();
}

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

mPreviewEffect->setMode( mode );
}

QgsPreviewEffect::PreviewMode QgsMapCanvas::previewMode() const
{
if ( !mPreviewEffect )
{
return QgsPreviewEffect::PreviewGrayscale;
}

return mPreviewEffect->mode();
}

void QgsMapCanvas::readProject( const QDomDocument & doc )
{
QDomNodeList nodes = doc.elementsByTagName( "mapcanvas" );
34 src/gui/qgsmapcanvas.h 100644 → 100755
@@ -33,6 +33,7 @@
#include <QtCore>

#include "qgsmapsettings.h" // TEMPORARY
#include "qgsprevieweffect.h" //for QgsPreviewEffect::PreviewMode

#ifdef HAVE_TOUCH
#include <QGestureEvent>
@@ -330,6 +331,36 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! returns last position of mouse cursor
QPoint mouseLastXY();

/** Enables a preview mode for the map canvas
* @param previewEnabled set to true to enable a preview mode
* @see setPreviewMode
* @note added in 2.3 */
void setPreviewModeEnabled( bool previewEnabled );

/** Returns whether a preview mode is enabled for the map canvas
* @returns true if a preview mode is currently enabled
* @see setPreviewModeEnabled
* @see previewMode
* @note added in 2.3 */
bool previewModeEnabled() const;

/** Sets a preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* @param mode preview mode for the canvas
* @see previewMode
* @see setPreviewModeEnabled
* @see previewModeEnabled
* @note added in 2.3 */
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );

/** Returns the current preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* @returns preview mode for map canvas
* @see setPreviewMode
* @see previewModeEnabled
* @note added in 2.3 */
QgsPreviewEffect::PreviewMode previewMode() const;

public slots:

/**Repaints the canvas map*/
@@ -590,6 +621,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView


QTimer *mResizeTimer;

QgsPreviewEffect* mPreviewEffect;

}; // class QgsMapCanvas


70 src/ui/qgisapp.ui 100644 → 100755
@@ -88,6 +88,16 @@
<addaction name="mActionDecorationNorthArrow"/>
<addaction name="mActionDecorationCopyright"/>
</widget>
<widget class="QMenu" name="menuPreview_Mode">
<property name="title">
<string>Preview Mode</string>
</property>
<addaction name="mActionPreviewModeOff"/>
<addaction name="mActionPreviewModeGrayscale"/>
<addaction name="mActionPreviewModeMono"/>
<addaction name="mActionPreviewProtanope"/>
<addaction name="mActionPreviewDeuteranope"/>
</widget>
<addaction name="mActionPan"/>
<addaction name="mActionPanToSelected"/>
<addaction name="mActionZoomIn"/>
@@ -105,10 +115,12 @@
<addaction name="mActionZoomActualSize"/>
<addaction name="separator"/>
<addaction name="menuDecorations"/>
<addaction name="menuPreview_Mode"/>
<addaction name="mActionMapTips"/>
<addaction name="mActionNewBookmark"/>
<addaction name="mActionShowBookmarks"/>
<addaction name="mActionDraw"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="mLayerMenu">
<property name="title">
@@ -2168,6 +2180,64 @@ Acts on currently active editable layer</string>
<string>Save As Layer Definition File...</string>
</property>
</action>
<action name="mActionPreviewModeOff">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Normal</string>
</property>
<property name="toolTip">
<string>Normal preview mode</string>
</property>
</action>
<action name="mActionPreviewModeGrayscale">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate photocopy (grayscale)</string>
</property>
<property name="toolTip">
<string>Simulate Photocopy (Grayscale)</string>
</property>
</action>
<action name="mActionPreviewModeMono">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate fax (mono)</string>
</property>
<property name="toolTip">
<string>Simulate Fax (Mono)</string>
</property>
</action>
<action name="mActionPreviewProtanope">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate color blindness (Protanope)</string>
</property>
<property name="toolTip">
<string>Simulate Color Blindness (Protanope)</string>
</property>
</action>
<action name="mActionPreviewDeuteranope">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Simulate color blindness (Deuteranope)</string>
</property>
<property name="toolTip">
<string>Simulate Color Blindness (Deuteranope)</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit af7af6c

Please sign in to comment.