Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add increase/decrease gamma buttons to the raster toolbar
  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent 8054469 commit ccae627
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
2 changes: 2 additions & 0 deletions images/images.qrc
Expand Up @@ -274,6 +274,7 @@
<file>themes/default/mActionCustomProjection.svg</file>
<file>themes/default/mActionDecreaseBrightness.svg</file>
<file>themes/default/mActionDecreaseContrast.svg</file>
<file>themes/default/mActionDecreaseGamma.svg</file>
<file>themes/default/mActionDeleteAttribute.svg</file>
<file>themes/default/mActionDeletePart.svg</file>
<file>themes/default/mActionDeleteRing.svg</file>
Expand Down Expand Up @@ -318,6 +319,7 @@
<file>themes/default/mActionIdentify.svg</file>
<file>themes/default/mActionIncreaseBrightness.svg</file>
<file>themes/default/mActionIncreaseContrast.svg</file>
<file>themes/default/mActionIncreaseGamma.svg</file>
<file>themes/default/mActionInOverview.svg</file>
<file>themes/default/mActionInvertSelection.svg</file>
<file>themes/default/mActionKeyboardShortcuts.svg</file>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionDecreaseGamma.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/themes/default/mActionIncreaseGamma.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -315,6 +315,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsrasterlayerproperties.h"
#include "qgsrasternuller.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgsgammacorrectionfilter.h"
#include "qgsrasterrenderer.h"
#include "qgsrasterlayersaveasdialog.h"
#include "qgsrasterprojector.h"
Expand Down Expand Up @@ -2785,6 +2786,8 @@ void QgisApp::createActions()
connect( mActionDecreaseBrightness, &QAction::triggered, this, &QgisApp::decreaseBrightness );
connect( mActionIncreaseContrast, &QAction::triggered, this, &QgisApp::increaseContrast );
connect( mActionDecreaseContrast, &QAction::triggered, this, &QgisApp::decreaseContrast );
connect( mActionIncreaseGamma, &QAction::triggered, this, &QgisApp::increaseGamma );
connect( mActionDecreaseGamma, &QAction::triggered, this, &QgisApp::decreaseGamma );

#ifdef HAVE_GEOREFERENCER
connect( mActionShowGeoreferencer, &QAction::triggered, this, &QgisApp::showGeoreferencer );
Expand Down Expand Up @@ -3940,6 +3943,8 @@ void QgisApp::setTheme( const QString &themeName )
mActionDecreaseBrightness->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDecreaseBrightness.svg" ) ) );
mActionIncreaseContrast->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionIncreaseContrast.svg" ) ) );
mActionDecreaseContrast->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDecreaseContrast.svg" ) ) );
mActionIncreaseGamma->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionIncreaseGamma.svg" ) ) );
mActionDecreaseGamma->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDecreaseGamma.svg" ) ) );
mActionZoomActualSize->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomNative.png" ) ) );
mActionQgisHomePage->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionQgisHomePage.png" ) ) );
mActionAbout->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionHelpAbout.svg" ) ) );
Expand Down Expand Up @@ -12210,6 +12215,54 @@ void QgisApp::adjustBrightnessContrast( int delta, bool updateBrightness )
}
}

void QgisApp::increaseGamma()
{
double step = 0.1;
if ( QgsApplication::keyboardModifiers() == Qt::ShiftModifier )
{
step = 1.0;
}
adjustGamma( step );
}

void QgisApp::decreaseGamma()
{
double step = -0.1;
if ( QgsApplication::keyboardModifiers() == Qt::ShiftModifier )
{
step = -1.0;
}
adjustGamma( step );
}

void QgisApp::adjustGamma( double delta )
{
const auto constSelectedLayers = mLayerTreeView->selectedLayers();
for ( QgsMapLayer *layer : constSelectedLayers )
{
if ( !layer )
{
visibleMessageBar()->pushMessage( tr( "No Layer Selected" ),
tr( "To change gamma, you need to have a raster layer selected." ),
Qgis::Info, messageTimeout() );
return;
}

QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
if ( !rasterLayer )
{
visibleMessageBar()->pushMessage( tr( "No Layer Selected" ),
tr( "To change gamma, you need to have a raster layer selected." ),
Qgis::Info, messageTimeout() );
return;
}

QgsGammaCorrectionFilter *gammaFilter = rasterLayer->gammaCorrectionFilter();
gammaFilter->setGamma( gammaFilter->gamma() + delta );

rasterLayer->triggerRepaint();
}
}

void QgisApp::helpContents()
{
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1297,6 +1297,22 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
* Decrease raster contrast
* Valid for non wms raster layers only. */
void decreaseContrast();

/**
* Increase raster gamma
* Valid for non wms raster layers only.
* \since QGIS 3.16
*/
void increaseGamma();

/**
* Decrease raster gamma
* Valid for non wms raster layers only.
* \since QGIS 3.16
*/
void decreaseGamma();


//! plugin manager
void showPluginManager();
//! load Python support if possible
Expand Down Expand Up @@ -2107,6 +2123,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Apply raster brightness
void adjustBrightnessContrast( int delta, bool updateBrightness = true );

/**
* Apply raster gamma
* \since QGIS 3.16
*/
void adjustGamma( double delta );

//! Copy a vector style from a layer to another one, if they have the same geometry type
void duplicateVectorStyle( QgsVectorLayer *srcLayer, QgsVectorLayer *destLayer );

Expand Down
28 changes: 27 additions & 1 deletion src/ui/qgisapp.ui
Expand Up @@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1064</width>
<height>24</height>
<height>20</height>
</rect>
</property>
<property name="toolTip">
Expand Down Expand Up @@ -604,6 +604,8 @@
<addaction name="mActionDecreaseBrightness"/>
<addaction name="mActionIncreaseContrast"/>
<addaction name="mActionDecreaseContrast"/>
<addaction name="mActionIncreaseGamma"/>
<addaction name="mActionDecreaseGamma"/>
</widget>
<widget class="QToolBar" name="mLabelToolBar">
<property name="windowTitle">
Expand Down Expand Up @@ -3337,6 +3339,30 @@ Shows placeholders for labels which could not be placed, e.g. due to overlaps wi
<string>Georeferencer…</string>
</property>
</action>
<action name="mActionDecreaseGamma">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDecreaseGamma.svg</normaloff>:/images/themes/default/mActionDecreaseGamma.svg</iconset>
</property>
<property name="text">
<string>Decrease Gamma</string>
</property>
<property name="toolTip">
<string>Decrease Gamma</string>
</property>
</action>
<action name="mActionIncreaseGamma">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionIncreaseGamma.svg</normaloff>:/images/themes/default/mActionIncreaseGamma.svg</iconset>
</property>
<property name="text">
<string>Increase Gamma</string>
</property>
<property name="toolTip">
<string>Increase Gamma</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit ccae627

Please sign in to comment.