Skip to content
Permalink
Browse files

add gamma controls to the styling dock

  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent f37ac2e commit 4b799171bd15f7cb33e090eb2e8df54a80984521
@@ -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"
@@ -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 );
@@ -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 );
@@ -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();
@@ -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" ) );

@@ -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 );
@@ -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 );
}
@@ -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 );

0 comments on commit 4b79917

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