Skip to content

Commit

Permalink
Change QgsBlurEffect to use opacity instead of transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 3914651 commit 59cc09b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 53 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Expand Up @@ -528,6 +528,12 @@ QgsAuthMethod {#qgis_api_break_3_0_QgsAuthMethod}
- DataSourceURI has been renamed to DataSourceUri
- GenericDataSourceURI has been renamed to GenericDataSourceUri

QgsBlurEffect {#qgis_api_break_3_0_QgsBlurEffect}
-------------

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


QgsBrowserModel {#qgis_api_break_3_0_QgsBrowserModel}
---------------

Expand Down
20 changes: 10 additions & 10 deletions python/core/effects/qgsblureffect.sip
Expand Up @@ -78,20 +78,20 @@ class QgsBlurEffect : QgsPaintEffect
:rtype: BlurMethod
%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
2 changes: 2 additions & 0 deletions src/app/composer/qgscomposeritemwidget.cpp
Expand Up @@ -165,6 +165,8 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget *parent, QgsComposerItem *

initializeDataDefinedButtons();

mOpacitySpnBx->setClearValue( 100.0 );

setValuesForGuiElements();
connect( mItem->composition(), &QgsComposition::paperSizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements );
connect( mItem, &QgsComposerItem::sizeChanged, this, &QgsComposerItemWidget::setValuesForGuiPositionElements );
Expand Down
25 changes: 18 additions & 7 deletions src/core/effects/qgsblureffect.cpp
Expand Up @@ -30,7 +30,6 @@ QgsBlurEffect::QgsBlurEffect()
: QgsPaintEffect()
, mBlurLevel( 10 )
, mBlurMethod( StackBlur )
, mTransparency( 0.0 )
, mBlendMode( QPainter::CompositionMode_SourceOver )
{

Expand Down Expand Up @@ -68,8 +67,8 @@ void QgsBlurEffect::drawGaussianBlur( QgsRenderContext &context )

void QgsBlurEffect::drawBlurredImage( QgsRenderContext &context, QImage &image )
{
//transparency
QgsImageOperation::multiplyOpacity( image, 1.0 - mTransparency );
//opacity
QgsImageOperation::multiplyOpacity( image, mOpacity );

QPainter *painter = context.painter();
painter->save();
Expand All @@ -84,7 +83,7 @@ QgsStringMap QgsBlurEffect::properties() const
props.insert( QStringLiteral( "enabled" ), mEnabled ? "1" : "0" );
props.insert( QStringLiteral( "draw_mode" ), QString::number( static_cast< int >( mDrawMode ) ) );
props.insert( QStringLiteral( "blend_mode" ), QString::number( static_cast< 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( "blur_method" ), QString::number( static_cast< int >( mBlurMethod ) ) );
return props;
Expand All @@ -98,11 +97,23 @@ void QgsBlurEffect::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() );
int level = props.value( QStringLiteral( "blur_level" ) ).toInt( &ok );
Expand Down
22 changes: 11 additions & 11 deletions src/core/effects/qgsblureffect.h
Expand Up @@ -83,19 +83,19 @@ class CORE_EXPORT QgsBlurEffect : public QgsPaintEffect
*/
BlurMethod blurMethod() const { return mBlurMethod; }

/** 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 @@ -120,7 +120,7 @@ class CORE_EXPORT QgsBlurEffect : public QgsPaintEffect

int mBlurLevel;
BlurMethod mBlurMethod;
double mTransparency;
double mOpacity = 1.0;
QPainter::CompositionMode mBlendMode;

void drawStackBlur( QgsRenderContext &context );
Expand Down
23 changes: 12 additions & 11 deletions src/gui/effects/qgspainteffectwidget.cpp
Expand Up @@ -126,6 +126,7 @@ QgsBlurWidget::QgsBlurWidget( QWidget *parent )

mBlurTypeCombo->addItem( tr( "Stack blur (fast)" ), QgsBlurEffect::StackBlur );
mBlurTypeCombo->addItem( tr( "Gaussian blur (quality)" ), QgsBlurEffect::GaussianBlur );
mOpacitySpnBx->setClearValue( 100.0 );

initGui();
}
Expand All @@ -151,8 +152,8 @@ void QgsBlurWidget::initGui()

mBlurTypeCombo->setCurrentIndex( mBlurTypeCombo->findData( mEffect->blurMethod() ) );
mBlurStrengthSpnBx->setValue( mEffect->blurLevel() );
mTransparencySpnBx->setValue( mEffect->transparency() * 100.0 );
mTransparencySlider->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() );

Expand All @@ -163,8 +164,8 @@ void QgsBlurWidget::blockSignals( const bool block )
{
mBlurTypeCombo->blockSignals( block );
mBlurStrengthSpnBx->blockSignals( block );
mTransparencySlider->blockSignals( block );
mTransparencySpnBx->blockSignals( block );
mOpacitySpnBx->blockSignals( block );
mOpacitySlider->blockSignals( block );
mBlendCmbBx->blockSignals( block );
mDrawModeComboBox->blockSignals( block );
}
Expand Down Expand Up @@ -200,16 +201,16 @@ void QgsBlurWidget::on_mBlurStrengthSpnBx_valueChanged( int value )
emit changed();
}

void QgsBlurWidget::on_mTransparencySpnBx_valueChanged( double value )
void QgsBlurWidget::on_mOpacitySpnBx_valueChanged( double value )
{
if ( !mEffect )
return;

mTransparencySlider->blockSignals( true );
mTransparencySlider->setValue( value * 10.0 );
mTransparencySlider->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 @@ -235,9 +236,9 @@ void QgsBlurWidget::on_mBlendCmbBx_currentIndexChanged( int index )
emit changed();
}

void QgsBlurWidget::on_mTransparencySlider_valueChanged( int value )
void QgsBlurWidget::on_mOpacitySlider_valueChanged( int value )
{
mTransparencySpnBx->setValue( value / 10.0 );
mOpacitySpnBx->setValue( value / 10.0 );
}


Expand Down
4 changes: 2 additions & 2 deletions src/gui/effects/qgspainteffectwidget.h
Expand Up @@ -119,10 +119,10 @@ class GUI_EXPORT QgsBlurWidget : public QgsPaintEffectWidget, private Ui::Widget

void on_mBlurTypeCombo_currentIndexChanged( int index );
void on_mBlurStrengthSpnBx_valueChanged( int value );
void on_mTransparencySpnBx_valueChanged( double value );
void on_mOpacitySpnBx_valueChanged( double value );
void on_mDrawModeComboBox_currentIndexChanged( int index );
void on_mBlendCmbBx_currentIndexChanged( int index );
void on_mTransparencySlider_valueChanged( int value );
void on_mOpacitySlider_valueChanged( int value );

};

Expand Down
23 changes: 16 additions & 7 deletions src/ui/effects/widget_blur.ui
Expand Up @@ -37,14 +37,14 @@
<item row="2" column="0">
<widget class="QLabel" name="label_28">
<property name="text">
<string>Transparency</string>
<string>Opacity</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_28">
<item>
<widget class="QSlider" name="mTransparencySlider">
<widget class="QSlider" name="mOpacitySlider">
<property name="enabled">
<bool>true</bool>
</property>
Expand All @@ -69,18 +69,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="mTransparencySpnBx">
<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 @@ -91,6 +97,9 @@
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -184,8 +193,8 @@
<tabstops>
<tabstop>mBlurTypeCombo</tabstop>
<tabstop>mBlurStrengthSpnBx</tabstop>
<tabstop>mTransparencySlider</tabstop>
<tabstop>mTransparencySpnBx</tabstop>
<tabstop>mOpacitySlider</tabstop>
<tabstop>mOpacitySpnBx</tabstop>
<tabstop>mBlendCmbBx</tabstop>
<tabstop>mDrawModeComboBox</tabstop>
</tabstops>
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgspainteffect.cpp
Expand Up @@ -357,8 +357,8 @@ void TestQgsPaintEffect::blur()
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 @@ -372,7 +372,7 @@ void TestQgsPaintEffect::blur()
QgsBlurEffect *copy = new QgsBlurEffect( *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->blurMethod(), effect->blurMethod() );
Expand All @@ -384,7 +384,7 @@ void TestQgsPaintEffect::blur()
QgsBlurEffect *cloneCast = dynamic_cast<QgsBlurEffect * >( 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->blurMethod(), effect->blurMethod() );
Expand All @@ -397,7 +397,7 @@ void TestQgsPaintEffect::blur()
QgsBlurEffect *readCast = dynamic_cast<QgsBlurEffect * >( 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->blurMethod(), effect->blurMethod() );
Expand Down

0 comments on commit 59cc09b

Please sign in to comment.