Skip to content

Commit

Permalink
Flip QgsColorEffect from transparency to opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 59cc09b commit a6d6364
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 47 deletions.
5 changes: 5 additions & 0 deletions doc/api_break.dox
Expand Up @@ -580,6 +580,11 @@ QgsColorButton {#qgis_api_break_3_0_QgsColorButton}

- Behaviour enum and its corresponding setter/getter have been renamed to Behavior <!--#spellok-->

QgsColorEffect {#qgis_api_break_3_0_QgsColorEffect}
-------------

- setTransparency and transparency were removed. Use setOpacity and opacity instead.


QgsColorRampShader {#qgis_api_break_3_0_QgsColorRampShader}
------------------
Expand Down
20 changes: 10 additions & 10 deletions python/core/effects/qgscoloreffect.sip
Expand Up @@ -171,20 +171,20 @@ class QgsColorEffect : QgsPaintEffect
:rtype: int
%End

void setTransparency( const double transparency );
void setOpacity( const double opacity );
%Docstring
Sets the transparency for the effect
\param transparency double between 0 and 1 inclusive, where 0 is fully opaque
and 1 is fully transparent
.. seealso:: transparency
Sets the ``opacity`` for the effect.
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: opacity()
%End

double transparency() const;
double opacity() const;
%Docstring
Returns the transparency for the effect
:return: transparency value between 0 and 1 inclusive, where 0 is fully opaque
and 1 is fully transparent
.. seealso:: setTransparency
Returns the opacity for the effect.
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque.
.. seealso:: setOpacity()
:rtype: float
%End

Expand Down
22 changes: 16 additions & 6 deletions src/core/effects/qgscoloreffect.cpp
Expand Up @@ -28,7 +28,6 @@ QgsPaintEffect *QgsColorEffect::create( const QgsStringMap &map )

QgsColorEffect::QgsColorEffect()
: QgsPaintEffect()
, mTransparency( 0.0 )
, mBlendMode( QPainter::CompositionMode_SourceOver )
, mBrightness( 0 )
, mContrast( 0 )
Expand Down Expand Up @@ -58,7 +57,7 @@ void QgsColorEffect::draw( QgsRenderContext &context )
}
QgsImageOperation::adjustHueSaturation( image, mSaturation, mColorizeOn ? mColorizeColor : QColor(), mColorizeStrength / 100.0 );

QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );
QgsImageOperation::multiplyOpacity( image, mOpacity );
painter->save();
painter->setCompositionMode( mBlendMode );
painter->drawImage( imageOffset( context ), image );
Expand All @@ -72,7 +71,7 @@ QgsStringMap QgsColorEffect::properties() const
props.insert( QStringLiteral( "enabled" ), mEnabled ? "1" : "0" );
props.insert( QStringLiteral( "draw_mode" ), QString::number( int( mDrawMode ) ) );
props.insert( QStringLiteral( "blend_mode" ), QString::number( int( mBlendMode ) ) );
props.insert( QStringLiteral( "transparency" ), QString::number( mTransparency ) );
props.insert( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
props.insert( QStringLiteral( "brightness" ), QString::number( mBrightness ) );
props.insert( QStringLiteral( "contrast" ), QString::number( mContrast ) );
props.insert( QStringLiteral( "saturation" ), QString::number( mSaturation ) );
Expand All @@ -92,10 +91,21 @@ void QgsColorEffect::readProperties( const QgsStringMap &props )
{
mBlendMode = mode;
}
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
if ( ok )
if ( props.contains( QStringLiteral( "transparency" ) ) )
{
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
if ( ok )
{
mOpacity = 1.0 - transparency;
}
}
else
{
mTransparency = transparency;
double opacity = props.value( QStringLiteral( "opacity" ) ).toDouble( &ok );
if ( ok )
{
mOpacity = opacity;
}
}
mEnabled = props.value( QStringLiteral( "enabled" ), QStringLiteral( "1" ) ).toInt();
mDrawMode = static_cast< QgsPaintEffect::DrawMode >( props.value( QStringLiteral( "draw_mode" ), QStringLiteral( "2" ) ).toInt() );
Expand Down
22 changes: 11 additions & 11 deletions src/core/effects/qgscoloreffect.h
Expand Up @@ -161,19 +161,19 @@ class CORE_EXPORT QgsColorEffect : public QgsPaintEffect
*/
int colorizeStrength() const { return mColorizeStrength; }

/** Sets the transparency for the effect
* \param transparency double between 0 and 1 inclusive, where 0 is fully opaque
* and 1 is fully transparent
* \see transparency
/** Sets the \a opacity for the effect.
* \param opacity double between 0 and 1 inclusive, where 0 is fully transparent
* and 1 is fully opaque
* \see opacity()
*/
void setTransparency( const double transparency ) { mTransparency = transparency; }
void setOpacity( const double opacity ) { mOpacity = opacity; }

/** Returns the transparency for the effect
* \returns transparency value between 0 and 1 inclusive, where 0 is fully opaque
* and 1 is fully transparent
* \see setTransparency
/** Returns the opacity for the effect.
* \returns opacity value between 0 and 1 inclusive, where 0 is fully transparent
* and 1 is fully opaque.
* \see setOpacity()
*/
double transparency() const { return mTransparency; }
double opacity() const { return mOpacity; }

/** Sets the blend mode for the effect
* \param mode blend mode used for drawing the effect on to a destination
Expand All @@ -195,7 +195,7 @@ class CORE_EXPORT QgsColorEffect : public QgsPaintEffect

private:

double mTransparency;
double mOpacity = 1.0;
QPainter::CompositionMode mBlendMode;
int mBrightness;
int mContrast;
Expand Down
23 changes: 12 additions & 11 deletions src/gui/effects/qgspainteffectwidget.cpp
Expand Up @@ -793,6 +793,7 @@ QgsColorEffectWidget::QgsColorEffectWidget( QWidget *parent )
mBrightnessSpinBox->setClearValue( 0 );
mContrastSpinBox->setClearValue( 0 );
mSaturationSpinBox->setClearValue( 0 );
mOpacitySpnBx->setClearValue( 100.0 );
mColorizeColorButton->setAllowAlpha( false );

mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
Expand Down Expand Up @@ -829,8 +830,8 @@ void QgsColorEffectWidget::initGui()
mColorizeColorButton->setColor( mEffect->colorizeColor() );
int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
mOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
mOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
mBlendCmbBx->setBlendMode( mEffect->blendMode() );
mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
enableColorizeControls( mEffect->colorizeOn() );
Expand All @@ -847,8 +848,8 @@ void QgsColorEffectWidget::blockSignals( const bool block )
mColorizeCheck->blockSignals( block );
mColorizeColorButton->blockSignals( block );
mGrayscaleCombo->blockSignals( block );
mTranspSpnBx->blockSignals( block );
mTranspSlider->blockSignals( block );
mOpacitySpnBx->blockSignals( block );
mOpacitySlider->blockSignals( block );
mBlendCmbBx->blockSignals( block );
mDrawModeComboBox->blockSignals( block );
}
Expand All @@ -860,16 +861,16 @@ void QgsColorEffectWidget::enableColorizeControls( const bool enable )
mColorizeColorButton->setEnabled( enable );
}

void QgsColorEffectWidget::on_mTranspSpnBx_valueChanged( double value )
void QgsColorEffectWidget::on_mOpacitySpnBx_valueChanged( double value )
{
if ( !mEffect )
return;

mTranspSlider->blockSignals( true );
mTranspSlider->setValue( value * 10.0 );
mTranspSlider->blockSignals( false );
mOpacitySlider->blockSignals( true );
mOpacitySlider->setValue( value * 10.0 );
mOpacitySlider->blockSignals( false );

mEffect->setTransparency( value / 100.0 );
mEffect->setOpacity( value / 100.0 );
emit changed();
}

Expand All @@ -895,9 +896,9 @@ void QgsColorEffectWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
emit changed();
}

void QgsColorEffectWidget::on_mTranspSlider_valueChanged( int value )
void QgsColorEffectWidget::on_mOpacitySlider_valueChanged( int value )
{
mTranspSpnBx->setValue( value / 10.0 );
mOpacitySpnBx->setValue( value / 10.0 );
}

void QgsColorEffectWidget::on_mBrightnessSpinBox_valueChanged( int value )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/effects/qgspainteffectwidget.h
Expand Up @@ -264,10 +264,10 @@ class GUI_EXPORT QgsColorEffectWidget : public QgsPaintEffectWidget, private Ui:

private slots:

void on_mTranspSpnBx_valueChanged( double value );
void on_mOpacitySpnBx_valueChanged( double value );
void on_mBlendCmbBx_currentIndexChanged( int index );
void on_mDrawModeComboBox_currentIndexChanged( int index );
void on_mTranspSlider_valueChanged( int value );
void on_mOpacitySlider_valueChanged( int value );
void on_mBrightnessSpinBox_valueChanged( int value );
void on_mContrastSpinBox_valueChanged( int value );
void on_mSaturationSpinBox_valueChanged( int value );
Expand Down
23 changes: 16 additions & 7 deletions src/ui/effects/widget_coloreffects.ui
Expand Up @@ -55,7 +55,7 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QSlider" name="mTranspSlider">
<widget class="QSlider" name="mOpacitySlider">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -80,6 +80,9 @@
<property name="pageStep">
<number>100</number>
</property>
<property name="value">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -220,7 +223,7 @@
<item row="6" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Transparency</string>
<string>Opacity</string>
</property>
</widget>
</item>
Expand All @@ -245,12 +248,15 @@
</widget>
</item>
<item row="6" column="2">
<widget class="QgsDoubleSpinBox" name="mTranspSpnBx">
<widget class="QgsDoubleSpinBox" name="mOpacitySpnBx">
<property name="enabled">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="suffix">
<string> %</string>
Expand All @@ -261,6 +267,9 @@
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
Expand Down Expand Up @@ -362,8 +371,8 @@
<tabstop>mColorizeStrengthSpinBox</tabstop>
<tabstop>mColorizeColorButton</tabstop>
<tabstop>mGrayscaleCombo</tabstop>
<tabstop>mTranspSlider</tabstop>
<tabstop>mTranspSpnBx</tabstop>
<tabstop>mOpacitySlider</tabstop>
<tabstop>mOpacitySpnBx</tabstop>
<tabstop>mBlendCmbBx</tabstop>
<tabstop>mDrawModeComboBox</tabstop>
</tabstops>
Expand Down

0 comments on commit a6d6364

Please sign in to comment.