Skip to content

Commit

Permalink
Flip QgsGlowEffect 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 a6d6364 commit 89c2e85
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 56 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,12 @@ QgsGeometrySimplifier {#qgis_api_break_3_0_QgsGeometrySimplifier}
- simplifyGeometry() has been removed and simplify() must be used instead .


QgsGlowEffect {#qgis_api_break_3_0_QgsGlowEffect}
-------------

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


QgsGradientColorRampDialog {#qgis_api_break_3_0_QgsGradientColorRampDialog}
---------

Expand Down
20 changes: 10 additions & 10 deletions python/core/effects/qgsgloweffect.sip
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ class QgsGlowEffect : 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
28 changes: 19 additions & 9 deletions src/core/effects/qgsgloweffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ QgsGlowEffect::QgsGlowEffect()
, mSpreadUnit( QgsUnitTypes::RenderMillimeters )
, mRamp( nullptr )
, mBlurLevel( 3 )
, mTransparency( 0.5 )
, mColor( Qt::white )
, mBlendMode( QPainter::CompositionMode_SourceOver )
, mColorType( SingleColor )
Expand All @@ -42,7 +41,7 @@ QgsGlowEffect::QgsGlowEffect( const QgsGlowEffect &other )
, mSpreadMapUnitScale( other.spreadMapUnitScale() )
, mRamp( nullptr )
, mBlurLevel( other.blurLevel() )
, mTransparency( other.transparency() )
, mOpacity( other.opacity() )
, mColor( other.color() )
, mBlendMode( other.blendMode() )
, mColorType( other.colorType() )
Expand Down Expand Up @@ -92,7 +91,7 @@ void QgsGlowEffect::draw( QgsRenderContext &context )
QgsImageOperation::stackBlur( im, mBlurLevel );
}

QgsImageOperation::multiplyOpacity( im, 1.0 - mTransparency );
QgsImageOperation::multiplyOpacity( im, mOpacity );

if ( !shadeExterior() )
{
Expand All @@ -117,7 +116,7 @@ QgsStringMap QgsGlowEffect::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( "blur_level" ), QString::number( mBlurLevel ) );
props.insert( QStringLiteral( "spread" ), QString::number( mSpread ) );
props.insert( QStringLiteral( "spread_unit" ), QgsUnitTypes::encodeUnit( mSpreadUnit ) );
Expand All @@ -141,10 +140,21 @@ void QgsGlowEffect::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 All @@ -170,7 +180,7 @@ void QgsGlowEffect::readProperties( const QgsStringMap &props )
mColor = QgsSymbolLayerUtils::decodeColor( props.value( QStringLiteral( "single_color" ) ) );
}

//attempt to create color ramp from props
//attempt to create color ramp from props
delete mRamp;
if ( props.contains( QStringLiteral( "rampType" ) ) && props[QStringLiteral( "rampType" )] == QStringLiteral( "cpt-city" ) )
{
Expand Down Expand Up @@ -198,7 +208,7 @@ QgsGlowEffect &QgsGlowEffect::operator=( const QgsGlowEffect &rhs )
mSpread = rhs.spread();
mRamp = rhs.ramp() ? rhs.ramp()->clone() : nullptr;
mBlurLevel = rhs.blurLevel();
mTransparency = rhs.transparency();
mOpacity = rhs.opacity();
mColor = rhs.color();
mBlendMode = rhs.blendMode();
mColorType = rhs.colorType();
Expand Down
22 changes: 11 additions & 11 deletions src/core/effects/qgsgloweffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
*/
int blurLevel() const { return mBlurLevel; }

/** 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 color for the glow. This only applies if the colorType()
* is set to SingleColor. The glow will fade between the specified color and
Expand Down Expand Up @@ -216,7 +216,7 @@ class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
QgsMapUnitScale mSpreadMapUnitScale;
QgsColorRamp *mRamp = nullptr;
int mBlurLevel;
double mTransparency;
double mOpacity = 0.5;
QColor mColor;
QPainter::CompositionMode mBlendMode;
GlowColorType mColorType;
Expand Down
23 changes: 12 additions & 11 deletions src/gui/effects/qgspainteffectwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ QgsGlowWidget::QgsGlowWidget( QWidget *parent )
mColorBtn->setAllowAlpha( false );
mColorBtn->setColorDialogTitle( tr( "Select glow color" ) );
mColorBtn->setContext( QStringLiteral( "symbology" ) );
mOpacitySpnBx->setClearValue( 100.0 );

mSpreadUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
Expand Down Expand Up @@ -455,8 +456,8 @@ void QgsGlowWidget::initGui()
mSpreadUnitWidget->setUnit( mEffect->spreadUnit() );
mSpreadUnitWidget->setMapUnitScale( mEffect->spreadMapUnitScale() );
mBlurRadiusSpnBx->setValue( mEffect->blurLevel() );
mTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
mTranspSlider->setValue( mEffect->transparency() * 1000.0 );
mOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
mOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
mColorBtn->setColor( mEffect->color() );
mBlendCmbBx->setBlendMode( mEffect->blendMode() );

Expand All @@ -479,8 +480,8 @@ void QgsGlowWidget::blockSignals( const bool block )
mSpreadSpnBx->blockSignals( block );
mSpreadUnitWidget->blockSignals( block );
mBlurRadiusSpnBx->blockSignals( block );
mTranspSpnBx->blockSignals( block );
mTranspSlider->blockSignals( block );
mOpacitySpnBx->blockSignals( block );
mOpacitySlider->blockSignals( block );
mColorBtn->blockSignals( block );
mBlendCmbBx->blockSignals( block );
btnColorRamp->blockSignals( block );
Expand Down Expand Up @@ -529,16 +530,16 @@ void QgsGlowWidget::on_mSpreadUnitWidget_changed()
emit changed();
}

void QgsGlowWidget::on_mTranspSpnBx_valueChanged( double value )
void QgsGlowWidget::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 @@ -560,9 +561,9 @@ void QgsGlowWidget::on_mBlurRadiusSpnBx_valueChanged( int value )
emit changed();
}

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

void QgsGlowWidget::on_mBlendCmbBx_currentIndexChanged( int index )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/effects/qgspainteffectwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ class GUI_EXPORT QgsGlowWidget : public QgsPaintEffectWidget, private Ui::Widget
void colorModeChanged();
void on_mSpreadSpnBx_valueChanged( double value );
void on_mSpreadUnitWidget_changed();
void on_mTranspSpnBx_valueChanged( double value );
void on_mOpacitySpnBx_valueChanged( double value );
void on_mColorBtn_colorChanged( const QColor &color );
void on_mBlendCmbBx_currentIndexChanged( int index );
void on_mDrawModeComboBox_currentIndexChanged( int index );
void on_mBlurRadiusSpnBx_valueChanged( int value );
void on_mTranspSlider_valueChanged( int value );
void on_mOpacitySlider_valueChanged( int value );
void applyColorRamp();

};
Expand Down
25 changes: 17 additions & 8 deletions src/ui/effects/widget_glow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Transparency</string>
<string>Opacity</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -154,15 +154,15 @@
<height>16777215</height>
</size>
</property>
</widget>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QgsBlendModeComboBox" name="mBlendCmbBx"/>
</item>
<item row="2" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<widget class="QSlider" name="mTranspSlider">
<widget class="QSlider" name="mOpacitySlider">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -187,18 +187,24 @@
<property name="pageStep">
<number>100</number>
</property>
<property name="value">
<number>1000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<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 @@ -209,6 +215,9 @@
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -287,8 +296,8 @@
<tabstop>mSpreadSpnBx</tabstop>
<tabstop>mSpreadUnitWidget</tabstop>
<tabstop>mBlurRadiusSpnBx</tabstop>
<tabstop>mTranspSlider</tabstop>
<tabstop>mTranspSpnBx</tabstop>
<tabstop>mOpacitySlider</tabstop>
<tabstop>mOpacitySpnBx</tabstop>
<tabstop>radioSingleColor</tabstop>
<tabstop>mColorBtn</tabstop>
<tabstop>radioColorRamp</tabstop>
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgspainteffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ void TestQgsPaintEffect::glow()
QVERIFY( effect );
effect->setBlendMode( QPainter::CompositionMode_ColorBurn );
QCOMPARE( effect->blendMode(), QPainter::CompositionMode_ColorBurn );
effect->setTransparency( 0.5 );
QCOMPARE( effect->transparency(), 0.5 );
effect->setOpacity( 0.5 );
QCOMPARE( effect->opacity(), 0.5 );
effect->setEnabled( false );
QCOMPARE( effect->enabled(), false );
effect->setBlurLevel( 6 );
Expand All @@ -555,7 +555,7 @@ void TestQgsPaintEffect::glow()
QgsOuterGlowEffect *copy = new QgsOuterGlowEffect( *effect );
QVERIFY( copy );
QCOMPARE( copy->blendMode(), effect->blendMode() );
QCOMPARE( copy->transparency(), effect->transparency() );
QCOMPARE( copy->opacity(), effect->opacity() );
QCOMPARE( copy->enabled(), effect->enabled() );
QCOMPARE( copy->blurLevel(), effect->blurLevel() );
QCOMPARE( copy->spread(), effect->spread() );
Expand All @@ -573,7 +573,7 @@ void TestQgsPaintEffect::glow()
QgsOuterGlowEffect *cloneCast = dynamic_cast<QgsOuterGlowEffect * >( clone );
QVERIFY( cloneCast );
QCOMPARE( cloneCast->blendMode(), effect->blendMode() );
QCOMPARE( cloneCast->transparency(), effect->transparency() );
QCOMPARE( cloneCast->opacity(), effect->opacity() );
QCOMPARE( cloneCast->enabled(), effect->enabled() );
QCOMPARE( cloneCast->blurLevel(), effect->blurLevel() );
QCOMPARE( cloneCast->spread(), effect->spread() );
Expand All @@ -592,7 +592,7 @@ void TestQgsPaintEffect::glow()
QgsOuterGlowEffect *readCast = dynamic_cast<QgsOuterGlowEffect * >( readEffect );
QVERIFY( readCast );
QCOMPARE( readCast->blendMode(), effect->blendMode() );
QCOMPARE( readCast->transparency(), effect->transparency() );
QCOMPARE( readCast->opacity(), effect->opacity() );
QCOMPARE( readCast->enabled(), effect->enabled() );
QCOMPARE( readCast->blurLevel(), effect->blurLevel() );
QCOMPARE( readCast->spread(), effect->spread() );
Expand Down

0 comments on commit 89c2e85

Please sign in to comment.