Skip to content

Commit

Permalink
Merge pull request #480 from nyalldawson/hue_saturation
Browse files Browse the repository at this point in the history
Add hue and saturation controls for raster layers
  • Loading branch information
NathanW2 committed Mar 28, 2013
2 parents 1b663bb + 0f7e90b commit 93ade1f
Show file tree
Hide file tree
Showing 10 changed files with 663 additions and 4 deletions.
68 changes: 68 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -45,6 +45,7 @@
#include "qgsrastertransparency.h"
#include "qgssinglebandgrayrendererwidget.h"
#include "qgssinglebandpseudocolorrendererwidget.h"
#include "qgshuesaturationfilter.h"

#include <QTableWidgetItem>
#include <QHeaderView>
Expand Down Expand Up @@ -89,6 +90,20 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
connect( mSliderContrast, SIGNAL( valueChanged( int ) ), mContrastSpinBox, SLOT( setValue( int ) ) );
connect( mContrastSpinBox, SIGNAL( valueChanged( int ) ), mSliderContrast, SLOT( setValue( int ) ) );

// Connect saturation slider and spin box
connect( sliderSaturation, SIGNAL( valueChanged( int ) ), spinBoxSaturation, SLOT( setValue( int ) ) );
connect( spinBoxSaturation, SIGNAL( valueChanged( int ) ), sliderSaturation, SLOT( setValue( int ) ) );

// Connect colorize strength slider and spin box
connect( sliderColorizeStrength, SIGNAL( valueChanged( int ) ), spinColorizeStrength, SLOT( setValue( int ) ) );
connect( spinColorizeStrength, SIGNAL( valueChanged( int ) ), sliderColorizeStrength, SLOT( setValue( int ) ) );

// enable or disable saturation slider and spin box depending on grayscale combo choice
connect( comboGrayscale, SIGNAL( currentIndexChanged( int ) ), this, SLOT( toggleSaturationControls( int ) ) );

// enable or disable colorize colorbutton with colorize checkbox
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), this, SLOT( toggleColorizeControls( bool ) ) );

// enable or disable Build Pyramids button depending on selection in pyramid list
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );

Expand Down Expand Up @@ -250,6 +265,25 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
}

// Hue and saturation color control
mHueSaturationGroupBox->setSaveCheckedState( true );
const QgsHueSaturationFilter* hueSaturationFilter = mRasterLayer->hueSaturationFilter();
//set hue and saturation controls to current values
if ( hueSaturationFilter )
{
sliderSaturation->setValue( hueSaturationFilter->saturation() );
comboGrayscale->setCurrentIndex(( int ) hueSaturationFilter->grayscaleMode() );

// Set initial state of saturation controls based on grayscale mode choice
toggleSaturationControls(( int )hueSaturationFilter->grayscaleMode() );

// Set initial state of colorize controls
mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
toggleColorizeControls( hueSaturationFilter->colorizeOn() );
sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
}

//blend mode
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );

Expand Down Expand Up @@ -824,6 +858,17 @@ void QgsRasterLayerProperties::apply()
resampleFilter->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
}

// Hue and saturation controls
QgsHueSaturationFilter* hueSaturationFilter = mRasterLayer->hueSaturationFilter();
if ( hueSaturationFilter )
{
hueSaturationFilter->setSaturation( sliderSaturation->value() );
hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
}

//set the blend mode for the layer
mRasterLayer->setBlendMode(( QgsMapRenderer::BlendMode ) mBlendModeComboBox->blendMode() );

Expand Down Expand Up @@ -1457,6 +1502,29 @@ void QgsRasterLayerProperties::sliderTransparency_valueChanged( int theValue )
lblTransparencyPercent->setText( QString::number( myInt ) + "%" );
}//sliderTransparency_valueChanged

void QgsRasterLayerProperties::toggleSaturationControls( int grayscaleMode )
{
// Enable or disable saturation controls based on choice of grayscale mode
if ( grayscaleMode == 0 )
{
sliderSaturation->setEnabled( true );
spinBoxSaturation->setEnabled( true );
}
else
{
sliderSaturation->setEnabled( false );
spinBoxSaturation->setEnabled( false );
}
}

void QgsRasterLayerProperties::toggleColorizeControls( bool colorizeEnabled )
{
// Enable or disable colorize controls based on checkbox
btnColorizeColor->setEnabled( colorizeEnabled );
sliderColorizeStrength->setEnabled( colorizeEnabled );
spinColorizeStrength->setEnabled( colorizeEnabled );
}


QLinearGradient QgsRasterLayerProperties::redGradient()
{
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -103,6 +103,12 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/**Enable or disable Build pyramids button depending on selection in pyramids list*/
void toggleBuildPyramidsButton();

/**Enable or disable saturation controls depending on choice of grayscale mode */
void toggleSaturationControls( int grayscaleMode );

/**Enable or disable colorize controls depending on checkbox */
void toggleColorizeControls( bool colorizeEnabled );

/** Update items in pipe list */
void pipeItemClicked( QTreeWidgetItem * item, int column );

Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -211,6 +211,7 @@ SET(QGIS_CORE_SRCS
raster/qgssinglebandgrayrenderer.cpp
raster/qgssinglebandpseudocolorrenderer.cpp
raster/qgsbrightnesscontrastfilter.cpp
raster/qgshuesaturationfilter.cpp

renderer/qgscontinuouscolorrenderer.cpp
renderer/qgsgraduatedsymbolrenderer.cpp
Expand Down

0 comments on commit 93ade1f

Please sign in to comment.