Skip to content
Permalink
Browse files

Flip QgsColorEffect from transparency to opacity

  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 59cc09b commit a6d636447dbe4e485047c9eed6b26185bb409106
@@ -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}
------------------
@@ -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

@@ -28,7 +28,6 @@ QgsPaintEffect *QgsColorEffect::create( const QgsStringMap &map )

QgsColorEffect::QgsColorEffect()
: QgsPaintEffect()
, mTransparency( 0.0 )
, mBlendMode( QPainter::CompositionMode_SourceOver )
, mBrightness( 0 )
, mContrast( 0 )
@@ -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 );
@@ -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 ) );
@@ -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() );
@@ -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
@@ -195,7 +195,7 @@ class CORE_EXPORT QgsColorEffect : public QgsPaintEffect

private:

double mTransparency;
double mOpacity = 1.0;
QPainter::CompositionMode mBlendMode;
int mBrightness;
int mContrast;
@@ -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 );
@@ -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() );
@@ -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 );
}
@@ -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();
}

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

0 comments on commit a6d6364

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