Skip to content
Permalink
Browse files

add increase/decrease gamma buttons to the raster toolbar

  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent 8054469 commit ccae627afe2113b2f081c5251a5033ec615884bb
@@ -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>
@@ -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>
@@ -0,0 +1 @@
<svg height="24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="m15.29989 4.213459q0 1.4192708-1.731771 4.752604-1.302083 2.330729-2.617187 4.661458.481771 2.981771.481771 5.091146 0 1.901042-1.015625 1.901042-1.0677085 0-1.0677085-1.992188 0-2.278646.8854165-5.104166-.5729165-2.65625-1.4453123-4.9348961-1.3932292-3.6458333-2.7473958-3.6458333-.9895833 0-1.1458333 2.0182291h-.4557292v-.1822916q0-3.5546874 1.9010416-3.5546874 1.6796875 0 3.0078125 3.9973957.234375.7161458 1.3802085 5.5078126 1.914062-3.997396 2.265625-6.6276043.169271-1.2630208.325521-1.7317707.351562-1.1458333 1.067708-1.1458333.911458 0 .911458.9895833z" fill="#505050"/><rect fill="#4e9a06" height="11" opacity=".9" rx="2.01149" width="11" x="13" y="13"/><path d="m15.5 15.500001 3 6 3-6z" fill="#fff" opacity=".9" stroke="#fff" stroke-linecap="round" stroke-linejoin="round"/><path d="m14 19.000001 9-.0096s0 0 0-2c0-2.9904-1-2.9904-4.5-2.9904s-4.5 0-4.5 3z" fill="#fcffff" fill-rule="evenodd" opacity=".3"/></svg>
@@ -0,0 +1 @@
<svg height="24" width="24" xmlns="http://www.w3.org/2000/svg"><rect fill="#4e9a06" height="11" opacity=".9" rx="2.01149" width="11" x="13" y="13"/><path d="m15.5 21.5 3-6 3 6z" fill="#fff" opacity=".9" stroke="#fff" stroke-linecap="round" stroke-linejoin="round"/><path d="m14 19 9-.0096s0 0 0-2c0-2.9904-1-2.9904-4.5-2.9904s-4.5 0-4.5 3z" fill="#fcffff" fill-rule="evenodd" opacity=".3"/><path d="m15.29989 4.213459q0 1.4192708-1.731771 4.752604-1.302083 2.330729-2.617187 4.661458.481771 2.981771.481771 5.091146 0 1.901042-1.015625 1.901042-1.0677085 0-1.0677085-1.992188 0-2.278646.8854165-5.104166-.5729165-2.65625-1.4453123-4.9348961-1.3932292-3.6458333-2.7473958-3.6458333-.9895833 0-1.1458333 2.0182291h-.4557292v-.1822916q0-3.5546874 1.9010416-3.5546874 1.6796875 0 3.0078125 3.9973957.234375.7161458 1.3802085 5.5078126 1.914062-3.997396 2.265625-6.6276043.169271-1.2630208.325521-1.7317707.351562-1.1458333 1.067708-1.1458333.911458 0 .911458.9895833z" fill="#505050"/></svg>
@@ -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"
@@ -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 );
@@ -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" ) ) );
@@ -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()
{
@@ -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
@@ -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 );

@@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1064</width>
<height>24</height>
<height>20</height>
</rect>
</property>
<property name="toolTip">
@@ -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">
@@ -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"/>

0 comments on commit ccae627

Please sign in to comment.
You can’t perform that action at this time.