28 : mEnabled( other.enabled() )
29 , mDrawMode( other.drawMode() )
40 delete mEffectPainter;
56 if ( element.isNull() )
61 QDomElement effectElement = doc.createElement( QStringLiteral(
"effect" ) );
62 effectElement.setAttribute( QStringLiteral(
"type" ),
type() );
65 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
67 QDomElement propEl = doc.createElement( QStringLiteral(
"prop" ) );
68 propEl.setAttribute( QStringLiteral(
"k" ), it.key() );
69 propEl.setAttribute( QStringLiteral(
"v" ), it.value() );
70 effectElement.appendChild( propEl );
73 element.appendChild( effectElement );
79 if ( element.isNull() )
87 QDomElement e = element.firstChildElement();
90 if ( e.tagName() != QLatin1String(
"prop" ) )
96 QString propKey = e.attribute( QStringLiteral(
"k" ) );
97 QString propValue = e.attribute( QStringLiteral(
"v" ) );
98 props[propKey] = propValue;
100 e = e.nextSiblingElement();
112 mSourceImage =
nullptr;
120 mPrevPainter = context.
painter();
123 mTempPicture =
new QPicture();
125 delete mEffectPainter;
126 mEffectPainter =
new QPainter();
127 mEffectPainter->begin( mTempPicture );
134 if ( !mEffectPainter )
137 mEffectPainter->end();
138 delete mEffectPainter;
139 mEffectPainter =
nullptr;
143 mPrevPainter =
nullptr;
147 context.
painter()->setPen( Qt::NoPen );
148 context.
painter()->setBrush( Qt::NoBrush );
151 render( *mTempPicture, context );
155 mTempPicture =
nullptr;
164 painter.drawPicture( 0, 0, *mPicture );
169 painter.drawPicture( 0, 0, *mPicture );
186 QRectF bounds = imageBoundingRect( context );
187 mSourceImage =
new QImage( bounds.width(), bounds.height(), QImage::Format_ARGB32 );
188 mSourceImage->fill( Qt::transparent );
189 QPainter imagePainter( mSourceImage );
190 imagePainter.setRenderHint( QPainter::Antialiasing );
191 imagePainter.translate( -bounds.left(), -bounds.top() );
192 imagePainter.drawPicture( 0, 0, *mPicture );
200 return imageBoundingRect( context ).topLeft();
215 painter->scale(
static_cast< double >(
qt_defaultDpiX() ) / painter->device()->logicalDpiX(),
216 static_cast< double >(
qt_defaultDpiY() ) / painter->device()->logicalDpiY() );
219 QRectF QgsPaintEffect::imageBoundingRect(
const QgsRenderContext &context )
const
221 return boundingRect( mPicture->boundingRect(), context );
241 QPainter *painter = context.
painter();
243 if ( mBlendMode == QPainter::CompositionMode_SourceOver &&
qgsDoubleNear( mOpacity, 1.0 ) )
254 painter->setCompositionMode( mBlendMode );
255 painter->drawImage(
imageOffset( context ), image );
268 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
269 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
270 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int( mBlendMode ) ) );
271 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
278 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
283 if ( props.contains( QStringLiteral(
"transparency" ) ) )
285 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
288 mOpacity = 1.0 - transparency;
293 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
299 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
309 : mRenderContext( renderContext )
312 mPainter = renderContext.
painter();
317 : mRenderContext( renderContext )
320 mPainter = mRenderContext.
painter();
322 mEffect->
begin( mRenderContext );
327 Q_ASSERT( !mEffect );
330 mEffect->
begin( mRenderContext );
337 mEffect->
end( mRenderContext );