Skip to content

Commit a6d6364

Browse files
committed
Flip QgsColorEffect from transparency to opacity
1 parent 59cc09b commit a6d6364

7 files changed

Lines changed: 72 additions & 47 deletions

File tree

‎doc/api_break.dox‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ QgsColorButton {#qgis_api_break_3_0_QgsColorButton}
580580

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

583+
QgsColorEffect {#qgis_api_break_3_0_QgsColorEffect}
584+
-------------
585+
586+
- setTransparency and transparency were removed. Use setOpacity and opacity instead.
587+
583588

584589
QgsColorRampShader {#qgis_api_break_3_0_QgsColorRampShader}
585590
------------------

‎python/core/effects/qgscoloreffect.sip‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,20 @@ class QgsColorEffect : QgsPaintEffect
171171
:rtype: int
172172
%End
173173

174-
void setTransparency( const double transparency );
174+
void setOpacity( const double opacity );
175175
%Docstring
176-
Sets the transparency for the effect
177-
\param transparency double between 0 and 1 inclusive, where 0 is fully opaque
178-
and 1 is fully transparent
179-
.. seealso:: transparency
176+
Sets the ``opacity`` for the effect.
177+
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
178+
and 1 is fully opaque
179+
.. seealso:: opacity()
180180
%End
181181

182-
double transparency() const;
182+
double opacity() const;
183183
%Docstring
184-
Returns the transparency for the effect
185-
:return: transparency value between 0 and 1 inclusive, where 0 is fully opaque
186-
and 1 is fully transparent
187-
.. seealso:: setTransparency
184+
Returns the opacity for the effect.
185+
:return: opacity value between 0 and 1 inclusive, where 0 is fully transparent
186+
and 1 is fully opaque.
187+
.. seealso:: setOpacity()
188188
:rtype: float
189189
%End
190190

‎src/core/effects/qgscoloreffect.cpp‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ QgsPaintEffect *QgsColorEffect::create( const QgsStringMap &map )
2828

2929
QgsColorEffect::QgsColorEffect()
3030
: QgsPaintEffect()
31-
, mTransparency( 0.0 )
3231
, mBlendMode( QPainter::CompositionMode_SourceOver )
3332
, mBrightness( 0 )
3433
, mContrast( 0 )
@@ -58,7 +57,7 @@ void QgsColorEffect::draw( QgsRenderContext &context )
5857
}
5958
QgsImageOperation::adjustHueSaturation( image, mSaturation, mColorizeOn ? mColorizeColor : QColor(), mColorizeStrength / 100.0 );
6059

61-
QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );
60+
QgsImageOperation::multiplyOpacity( image, mOpacity );
6261
painter->save();
6362
painter->setCompositionMode( mBlendMode );
6463
painter->drawImage( imageOffset( context ), image );
@@ -72,7 +71,7 @@ QgsStringMap QgsColorEffect::properties() const
7271
props.insert( QStringLiteral( "enabled" ), mEnabled ? "1" : "0" );
7372
props.insert( QStringLiteral( "draw_mode" ), QString::number( int( mDrawMode ) ) );
7473
props.insert( QStringLiteral( "blend_mode" ), QString::number( int( mBlendMode ) ) );
75-
props.insert( QStringLiteral( "transparency" ), QString::number( mTransparency ) );
74+
props.insert( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
7675
props.insert( QStringLiteral( "brightness" ), QString::number( mBrightness ) );
7776
props.insert( QStringLiteral( "contrast" ), QString::number( mContrast ) );
7877
props.insert( QStringLiteral( "saturation" ), QString::number( mSaturation ) );
@@ -92,10 +91,21 @@ void QgsColorEffect::readProperties( const QgsStringMap &props )
9291
{
9392
mBlendMode = mode;
9493
}
95-
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
96-
if ( ok )
94+
if ( props.contains( QStringLiteral( "transparency" ) ) )
95+
{
96+
double transparency = props.value( QStringLiteral( "transparency" ) ).toDouble( &ok );
97+
if ( ok )
98+
{
99+
mOpacity = 1.0 - transparency;
100+
}
101+
}
102+
else
97103
{
98-
mTransparency = transparency;
104+
double opacity = props.value( QStringLiteral( "opacity" ) ).toDouble( &ok );
105+
if ( ok )
106+
{
107+
mOpacity = opacity;
108+
}
99109
}
100110
mEnabled = props.value( QStringLiteral( "enabled" ), QStringLiteral( "1" ) ).toInt();
101111
mDrawMode = static_cast< QgsPaintEffect::DrawMode >( props.value( QStringLiteral( "draw_mode" ), QStringLiteral( "2" ) ).toInt() );

‎src/core/effects/qgscoloreffect.h‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ class CORE_EXPORT QgsColorEffect : public QgsPaintEffect
161161
*/
162162
int colorizeStrength() const { return mColorizeStrength; }
163163

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

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

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

196196
private:
197197

198-
double mTransparency;
198+
double mOpacity = 1.0;
199199
QPainter::CompositionMode mBlendMode;
200200
int mBrightness;
201201
int mContrast;

‎src/gui/effects/qgspainteffectwidget.cpp‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ QgsColorEffectWidget::QgsColorEffectWidget( QWidget *parent )
793793
mBrightnessSpinBox->setClearValue( 0 );
794794
mContrastSpinBox->setClearValue( 0 );
795795
mSaturationSpinBox->setClearValue( 0 );
796+
mOpacitySpnBx->setClearValue( 100.0 );
796797
mColorizeColorButton->setAllowAlpha( false );
797798

798799
mGrayscaleCombo->addItem( tr( "Off" ), QgsImageOperation::GrayscaleOff );
@@ -829,8 +830,8 @@ void QgsColorEffectWidget::initGui()
829830
mColorizeColorButton->setColor( mEffect->colorizeColor() );
830831
int grayscaleIdx = mGrayscaleCombo->findData( QVariant( ( int ) mEffect->grayscaleMode() ) );
831832
mGrayscaleCombo->setCurrentIndex( grayscaleIdx == -1 ? 0 : grayscaleIdx );
832-
mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
833-
mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
833+
mOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
834+
mOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
834835
mBlendCmbBx->setBlendMode( mEffect->blendMode() );
835836
mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
836837
enableColorizeControls( mEffect->colorizeOn() );
@@ -847,8 +848,8 @@ void QgsColorEffectWidget::blockSignals( const bool block )
847848
mColorizeCheck->blockSignals( block );
848849
mColorizeColorButton->blockSignals( block );
849850
mGrayscaleCombo->blockSignals( block );
850-
mTranspSpnBx->blockSignals( block );
851-
mTranspSlider->blockSignals( block );
851+
mOpacitySpnBx->blockSignals( block );
852+
mOpacitySlider->blockSignals( block );
852853
mBlendCmbBx->blockSignals( block );
853854
mDrawModeComboBox->blockSignals( block );
854855
}
@@ -860,16 +861,16 @@ void QgsColorEffectWidget::enableColorizeControls( const bool enable )
860861
mColorizeColorButton->setEnabled( enable );
861862
}
862863

863-
void QgsColorEffectWidget::on_mTranspSpnBx_valueChanged( double value )
864+
void QgsColorEffectWidget::on_mOpacitySpnBx_valueChanged( double value )
864865
{
865866
if ( !mEffect )
866867
return;
867868

868-
mTranspSlider->blockSignals( true );
869-
mTranspSlider->setValue( value * 10.0 );
870-
mTranspSlider->blockSignals( false );
869+
mOpacitySlider->blockSignals( true );
870+
mOpacitySlider->setValue( value * 10.0 );
871+
mOpacitySlider->blockSignals( false );
871872

872-
mEffect->setTransparency( value / 100.0 );
873+
mEffect->setOpacity( value / 100.0 );
873874
emit changed();
874875
}
875876

@@ -895,9 +896,9 @@ void QgsColorEffectWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
895896
emit changed();
896897
}
897898

898-
void QgsColorEffectWidget::on_mTranspSlider_valueChanged( int value )
899+
void QgsColorEffectWidget::on_mOpacitySlider_valueChanged( int value )
899900
{
900-
mTranspSpnBx->setValue( value / 10.0 );
901+
mOpacitySpnBx->setValue( value / 10.0 );
901902
}
902903

903904
void QgsColorEffectWidget::on_mBrightnessSpinBox_valueChanged( int value )

‎src/gui/effects/qgspainteffectwidget.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ class GUI_EXPORT QgsColorEffectWidget : public QgsPaintEffectWidget, private Ui:
264264

265265
private slots:
266266

267-
void on_mTranspSpnBx_valueChanged( double value );
267+
void on_mOpacitySpnBx_valueChanged( double value );
268268
void on_mBlendCmbBx_currentIndexChanged( int index );
269269
void on_mDrawModeComboBox_currentIndexChanged( int index );
270-
void on_mTranspSlider_valueChanged( int value );
270+
void on_mOpacitySlider_valueChanged( int value );
271271
void on_mBrightnessSpinBox_valueChanged( int value );
272272
void on_mContrastSpinBox_valueChanged( int value );
273273
void on_mSaturationSpinBox_valueChanged( int value );

‎src/ui/effects/widget_coloreffects.ui‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</widget>
5656
</item>
5757
<item row="6" column="1">
58-
<widget class="QSlider" name="mTranspSlider">
58+
<widget class="QSlider" name="mOpacitySlider">
5959
<property name="enabled">
6060
<bool>true</bool>
6161
</property>
@@ -80,6 +80,9 @@
8080
<property name="pageStep">
8181
<number>100</number>
8282
</property>
83+
<property name="value">
84+
<number>1000</number>
85+
</property>
8386
<property name="orientation">
8487
<enum>Qt::Horizontal</enum>
8588
</property>
@@ -220,7 +223,7 @@
220223
<item row="6" column="0">
221224
<widget class="QLabel" name="label_28">
222225
<property name="text">
223-
<string>Transparency</string>
226+
<string>Opacity</string>
224227
</property>
225228
</widget>
226229
</item>
@@ -245,12 +248,15 @@
245248
</widget>
246249
</item>
247250
<item row="6" column="2">
248-
<widget class="QgsDoubleSpinBox" name="mTranspSpnBx">
251+
<widget class="QgsDoubleSpinBox" name="mOpacitySpnBx">
249252
<property name="enabled">
250253
<bool>true</bool>
251254
</property>
252-
<property name="alignment">
253-
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
255+
<property name="minimumSize">
256+
<size>
257+
<width>100</width>
258+
<height>0</height>
259+
</size>
254260
</property>
255261
<property name="suffix">
256262
<string> %</string>
@@ -261,6 +267,9 @@
261267
<property name="maximum">
262268
<double>100.000000000000000</double>
263269
</property>
270+
<property name="value">
271+
<double>100.000000000000000</double>
272+
</property>
264273
</widget>
265274
</item>
266275
<item row="0" column="2">
@@ -362,8 +371,8 @@
362371
<tabstop>mColorizeStrengthSpinBox</tabstop>
363372
<tabstop>mColorizeColorButton</tabstop>
364373
<tabstop>mGrayscaleCombo</tabstop>
365-
<tabstop>mTranspSlider</tabstop>
366-
<tabstop>mTranspSpnBx</tabstop>
374+
<tabstop>mOpacitySlider</tabstop>
375+
<tabstop>mOpacitySpnBx</tabstop>
367376
<tabstop>mBlendCmbBx</tabstop>
368377
<tabstop>mDrawModeComboBox</tabstop>
369378
</tabstops>

0 commit comments

Comments
 (0)