Skip to content

Commit

Permalink
add gamma controls to the styling dock
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent f37ac2e commit 4b79917
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 255 deletions.
26 changes: 26 additions & 0 deletions src/gui/raster/qgsrendererrasterpropertieswidget.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsmapcanvas.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgshuesaturationfilter.h"
#include "qgsgammacorrectionfilter.h"
#include "qgsrastercontourrendererwidget.h"
#include "qgsrasterlayer.h"
#include "qgsrasterrendererwidget.h"
Expand Down Expand Up @@ -74,6 +75,9 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLaye
connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
connect( mContrastSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );

connect( mSliderGamma, &QAbstractSlider::valueChanged, this, &QgsRendererRasterPropertiesWidget::updateGammaSpinBox );
connect( mGammaSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRendererRasterPropertiesWidget::updateGammaSlider );

// Connect saturation slider and spin box
connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
connect( spinBoxSaturation, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
Expand All @@ -91,6 +95,7 @@ QgsRendererRasterPropertiesWidget::QgsRendererRasterPropertiesWidget( QgsMapLaye
// Just connect the spin boxes because the sliders update the spinners
connect( mBrightnessSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mContrastSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mGammaSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( spinBoxSaturation, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( spinColorizeStrength, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( btnColorizeColor, &QgsColorButton::colorChanged, this, &QgsPanelWidget::widgetChanged );
Expand Down Expand Up @@ -128,6 +133,11 @@ void QgsRendererRasterPropertiesWidget::apply()
brightnessFilter->setContrast( mSliderContrast->value() );
}

if ( QgsGammaCorrectionFilter *gammaFilter = mRasterLayer->gammaCorrectionFilter() )
{
gammaFilter->setGamma( mGammaSpinBox->value() );
}

if ( QgsRasterRendererWidget *rendererWidget = dynamic_cast<QgsRasterRendererWidget *>( stackedWidget->currentWidget() ) )
{
rendererWidget->doComputations();
Expand Down Expand Up @@ -190,6 +200,11 @@ void QgsRendererRasterPropertiesWidget::syncToLayer( QgsRasterLayer *layer )
mSliderContrast->setValue( brightnessFilter->contrast() );
}

if ( QgsGammaCorrectionFilter *gammaFilter = mRasterLayer->gammaCorrectionFilter() )
{
mGammaSpinBox->setValue( gammaFilter->gamma() );
}

btnColorizeColor->setColorDialogTitle( tr( "Select Color" ) );
btnColorizeColor->setContext( QStringLiteral( "symbology" ) );

Expand Down Expand Up @@ -222,6 +237,7 @@ void QgsRendererRasterPropertiesWidget::mResetColorRenderingBtn_clicked()
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
mSliderBrightness->setValue( 0 );
mSliderContrast->setValue( 0 );
mGammaSpinBox->setValue( 1.0 );
sliderSaturation->setValue( 0 );
comboGrayscale->setCurrentIndex( ( int ) QgsHueSaturationFilter::GrayscaleOff );
mColorizeCheck->setChecked( false );
Expand Down Expand Up @@ -367,3 +383,13 @@ void QgsRendererRasterPropertiesWidget::refreshAfterStyleChanged()
}
}
}

void QgsRendererRasterPropertiesWidget::updateGammaSpinBox( int value )
{
mGammaSpinBox->setValue( value / 100.0 );
}

void QgsRendererRasterPropertiesWidget::updateGammaSlider( double value )
{
mSliderGamma->setValue( value * 100 );
}
12 changes: 12 additions & 0 deletions src/gui/raster/qgsrendererrasterpropertieswidget.h
Expand Up @@ -85,6 +85,18 @@ class GUI_EXPORT QgsRendererRasterPropertiesWidget : public QgsMapLayerConfigWid

void refreshAfterStyleChanged();

/**
* updates gamma spinbox on slider changes
* \since QGIS 3.16
*/
void updateGammaSpinBox( int value );

/**
* updates gamma slider on spinbox changes
* \since QGIS 3.16
*/
void updateGammaSlider( double value );

private:
void setRendererWidget( const QString &rendererName );

Expand Down

0 comments on commit 4b79917

Please sign in to comment.