Skip to content
Permalink
Browse files

Flip QgsShadowEffect from transparency to opacity

  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 6f4c549 commit ac3932073b7166776c8742780511360cebb2a6d0
@@ -1985,6 +1985,13 @@ QgsServer {#qgis_api_break_3_0_QgsServer}
- QgsServer::handleRequest( const QString &urlstr ) has been removed in favour of the new
- QgsServer::handleRequest( QgsServerRequest &request, QgsServerResponse &response ) has been added


QgsShadowEffect {#qgis_api_break_3_0_QgsShadowEffect}
---------------

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


QgsShortcutsManager {#qgis_api_break_3_0_QgsShortcutsManager}
-------------------

@@ -314,14 +314,14 @@ class QgsDrawSourceEffect : QgsPaintEffect
void setOpacity( const double opacity );
%Docstring
Sets the ``opacity`` for the effect.
\param transparency double between 0 and 1 inclusive, where 0 is fully transparent
\param opacity double between 0 and 1 inclusive, where 0 is fully transparent
and 1 is fully opaque
.. seealso:: opacity()
%End

double opacity() const;
%Docstring
Returns the transparency for the effect
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()
@@ -133,20 +133,20 @@ class QgsShadowEffect : QgsPaintEffect
:rtype: QColor
%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

@@ -313,13 +313,13 @@ class CORE_EXPORT QgsDrawSourceEffect : public QgsPaintEffect
virtual void readProperties( const QgsStringMap &props ) override;

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

/** Returns the transparency for the effect
/** 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()
@@ -26,7 +26,6 @@ QgsShadowEffect::QgsShadowEffect()
, mOffsetAngle( 135 )
, mOffsetDist( 2.0 )
, mOffsetUnit( QgsUnitTypes::RenderMillimeters )
, mTransparency( 0.0 )
, mColor( Qt::black )
, mBlendMode( QPainter::CompositionMode_Multiply )
{
@@ -61,7 +60,7 @@ void QgsShadowEffect::draw( QgsRenderContext &context )
-offsetDist * sin( angleRad + M_PI / 2 ) );

//transparency, scale
QgsImageOperation::multiplyOpacity( colorisedIm, 1.0 - mTransparency );
QgsImageOperation::multiplyOpacity( colorisedIm, mOpacity );

if ( !exteriorShadow() )
{
@@ -93,7 +92,7 @@ QgsStringMap QgsShadowEffect::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( "offset_angle" ), QString::number( mOffsetAngle ) );
props.insert( QStringLiteral( "offset_distance" ), QString::number( mOffsetDist ) );
@@ -111,10 +110,21 @@ void QgsShadowEffect::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() );
@@ -128,19 +128,19 @@ class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
*/
QColor color() const { return mColor; }

/** 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
@@ -173,7 +173,7 @@ class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
double mOffsetDist;
QgsUnitTypes::RenderUnit mOffsetUnit;
QgsMapUnitScale mOffsetMapUnitScale;
double mTransparency;
double mOpacity = 1.0;
QColor mColor;
QPainter::CompositionMode mBlendMode;

@@ -256,6 +256,7 @@ QgsShadowEffectWidget::QgsShadowEffectWidget( QWidget *parent )
mShadowColorBtn->setAllowAlpha( false );
mShadowColorBtn->setColorDialogTitle( tr( "Select shadow color" ) );
mShadowColorBtn->setContext( QStringLiteral( "symbology" ) );
mShadowOpacitySpnBx->setClearValue( 100.0 );

mOffsetUnitWidget->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPixels << QgsUnitTypes::RenderMapUnits
<< QgsUnitTypes::RenderPoints << QgsUnitTypes::RenderInches );
@@ -287,8 +288,8 @@ void QgsShadowEffectWidget::initGui()
mOffsetUnitWidget->setUnit( mEffect->offsetUnit() );
mOffsetUnitWidget->setMapUnitScale( mEffect->offsetMapUnitScale() );
mShadowRadiuSpnBx->setValue( mEffect->blurLevel() );
mShadowTranspSpnBx->setValue( mEffect->transparency() * 100.0 );
mShadowTranspSlider->setValue( mEffect->transparency() * 1000.0 );
mShadowOpacitySpnBx->setValue( mEffect->opacity() * 100.0 );
mShadowOpacitySlider->setValue( mEffect->opacity() * 1000.0 );
mShadowColorBtn->setColor( mEffect->color() );
mShadowBlendCmbBx->setBlendMode( mEffect->blendMode() );
mDrawModeComboBox->setDrawMode( mEffect->drawMode() );
@@ -303,10 +304,10 @@ void QgsShadowEffectWidget::blockSignals( const bool block )
mShadowOffsetSpnBx->blockSignals( block );
mOffsetUnitWidget->blockSignals( block );
mShadowRadiuSpnBx->blockSignals( block );
mShadowTranspSpnBx->blockSignals( block );
mShadowOpacitySpnBx->blockSignals( block );
mShadowColorBtn->blockSignals( block );
mShadowBlendCmbBx->blockSignals( block );
mShadowTranspSlider->blockSignals( block );
mShadowOpacitySlider->blockSignals( block );
mDrawModeComboBox->blockSignals( block );
}

@@ -349,16 +350,16 @@ void QgsShadowEffectWidget::on_mOffsetUnitWidget_changed()
emit changed();
}

void QgsShadowEffectWidget::on_mShadowTranspSpnBx_valueChanged( double value )
void QgsShadowEffectWidget::on_mShadowOpacitySpnBx_valueChanged( double value )
{
if ( !mEffect )
return;

mShadowTranspSlider->blockSignals( true );
mShadowTranspSlider->setValue( value * 10.0 );
mShadowTranspSlider->blockSignals( false );
mShadowOpacitySlider->blockSignals( true );
mShadowOpacitySlider->setValue( value * 10.0 );
mShadowOpacitySlider->blockSignals( false );

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

@@ -380,9 +381,9 @@ void QgsShadowEffectWidget::on_mShadowRadiuSpnBx_valueChanged( int value )
emit changed();
}

void QgsShadowEffectWidget::on_mShadowTranspSlider_valueChanged( int value )
void QgsShadowEffectWidget::on_mShadowOpacitySlider_valueChanged( int value )
{
mShadowTranspSpnBx->setValue( value / 10.0 );
mShadowOpacitySpnBx->setValue( value / 10.0 );
}

void QgsShadowEffectWidget::on_mDrawModeComboBox_currentIndexChanged( int index )
@@ -155,12 +155,12 @@ class GUI_EXPORT QgsShadowEffectWidget : public QgsPaintEffectWidget, private Ui
void on_mShadowOffsetAngleDial_valueChanged( int value );
void on_mShadowOffsetSpnBx_valueChanged( double value );
void on_mOffsetUnitWidget_changed();
void on_mShadowTranspSpnBx_valueChanged( double value );
void on_mShadowOpacitySpnBx_valueChanged( double value );
void on_mShadowColorBtn_colorChanged( const QColor &color );
void on_mDrawModeComboBox_currentIndexChanged( int index );
void on_mShadowBlendCmbBx_currentIndexChanged( int index );
void on_mShadowRadiuSpnBx_valueChanged( int value );
void on_mShadowTranspSlider_valueChanged( int value );
void on_mShadowOpacitySlider_valueChanged( int value );
};


@@ -101,7 +101,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Transparency</string>
<string>Opacity</string>
</property>
</widget>
</item>
@@ -142,7 +142,7 @@
<item row="3" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<widget class="QSlider" name="mShadowTranspSlider">
<widget class="QSlider" name="mShadowOpacitySlider">
<property name="enabled">
<bool>true</bool>
</property>
@@ -167,18 +167,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="mShadowTranspSpnBx">
<widget class="QgsDoubleSpinBox" name="mShadowOpacitySpnBx">
<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>
@@ -189,6 +195,9 @@
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
@@ -314,8 +323,8 @@
<tabstop>mShadowOffsetSpnBx</tabstop>
<tabstop>mOffsetUnitWidget</tabstop>
<tabstop>mShadowRadiuSpnBx</tabstop>
<tabstop>mShadowTranspSlider</tabstop>
<tabstop>mShadowTranspSpnBx</tabstop>
<tabstop>mShadowOpacitySlider</tabstop>
<tabstop>mShadowOpacitySpnBx</tabstop>
<tabstop>mShadowColorBtn</tabstop>
<tabstop>mShadowBlendCmbBx</tabstop>
<tabstop>mDrawModeComboBox</tabstop>
@@ -431,8 +431,8 @@ void TestQgsPaintEffect::dropShadow()
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 );
@@ -455,7 +455,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *copy = new QgsDropShadowEffect( *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->offsetAngle(), effect->offsetAngle() );
@@ -472,7 +472,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *cloneCast = dynamic_cast<QgsDropShadowEffect * >( 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->offsetAngle(), effect->offsetAngle() );
@@ -490,7 +490,7 @@ void TestQgsPaintEffect::dropShadow()
QgsDropShadowEffect *readCast = dynamic_cast<QgsDropShadowEffect * >( 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->offsetAngle(), effect->offsetAngle() );

0 comments on commit ac39320

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