QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgspainteffect.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspainteffect.h
3 ----------------
4 begin : December 2014
5 copyright : (C) 2014 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSPAINTEFFECT_H
18#define QGSPAINTEFFECT_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include <QPainter>
23#include <QDomDocument>
24#include <QDomElement>
25
27
52{
53
54#ifdef SIP_RUN
56 if ( sipCpp->type() == "drawSource" && dynamic_cast<QgsDrawSourceEffect *>( sipCpp ) != NULL )
57 {
58 sipType = sipType_QgsDrawSourceEffect;
59 }
60 else if ( sipCpp->type() == "effectStack" && dynamic_cast<QgsEffectStack *>( sipCpp ) != NULL )
61 {
62 sipType = sipType_QgsEffectStack;
63 }
64 else if ( sipCpp->type() == "blur" && dynamic_cast<QgsBlurEffect *>( sipCpp ) != NULL )
65 {
66 sipType = sipType_QgsBlurEffect;
67 }
68 else if ( sipCpp->type() == "dropShadow" && dynamic_cast<QgsDropShadowEffect *>( sipCpp ) != NULL )
69 {
70 sipType = sipType_QgsDropShadowEffect;
71 }
72 else if ( sipCpp->type() == "outerGlow" && dynamic_cast<QgsOuterGlowEffect *>( sipCpp ) != NULL )
73 {
74 sipType = sipType_QgsOuterGlowEffect;
75 }
76 else if ( sipCpp->type() == "innerGlow" && dynamic_cast<QgsInnerGlowEffect *>( sipCpp ) != NULL )
77 {
78 sipType = sipType_QgsInnerGlowEffect;
79 }
80 else if ( sipCpp->type() == "transform" && dynamic_cast<QgsTransformEffect *>( sipCpp ) != NULL )
81 {
82 sipType = sipType_QgsTransformEffect;
83 }
84 else if ( sipCpp->type() == "color" && dynamic_cast<QgsColorEffect *>( sipCpp ) != NULL )
85 {
86 sipType = sipType_QgsColorEffect;
87 }
88 else
89 {
90 sipType = 0;
91 }
93#endif
94
95 public:
96
103 {
106 ModifyAndRender
107 };
108
109 QgsPaintEffect() = default;
110
111 QgsPaintEffect( const QgsPaintEffect &other );
112 virtual ~QgsPaintEffect();
113
118 virtual QString type() const = 0;
119
124 virtual QgsPaintEffect *clone() const = 0 SIP_FACTORY;
125
133 virtual QVariantMap properties() const = 0;
134
141 virtual void readProperties( const QVariantMap &props ) = 0;
142
152 virtual bool saveProperties( QDomDocument &doc, QDomElement &element ) const;
153
160 virtual bool readProperties( const QDomElement &element );
161
168 virtual void render( QPicture &picture, QgsRenderContext &context );
169
178 virtual void begin( QgsRenderContext &context );
179
186 virtual void end( QgsRenderContext &context );
187
193 bool enabled() const { return mEnabled; }
194
200 void setEnabled( bool enabled );
201
208 DrawMode drawMode() const { return mDrawMode; }
209
216 void setDrawMode( DrawMode drawMode );
217
218 protected:
219
220 bool mEnabled = true;
221 DrawMode mDrawMode = ModifyAndRender;
222 bool requiresQPainterDpiFix = true;
223
231 virtual void draw( QgsRenderContext &context ) = 0;
232
240 void drawSource( QPainter &painter );
241
249 const QPicture *source() const { return mPicture; }
250
262 QImage *sourceAsImage( QgsRenderContext &context );
263
271 QPointF imageOffset( const QgsRenderContext &context ) const;
272
282 virtual QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const;
283
292 Q_DECL_DEPRECATED void fixQPictureDpi( QPainter *painter ) const SIP_DEPRECATED;
293
294 private:
295
296 const QPicture *mPicture = nullptr;
297 QImage *mSourceImage = nullptr;
298 bool mOwnsImage = false;
299
300 QPainter *mPrevPainter = nullptr;
301 QPainter *mEffectPainter = nullptr;
302 QPicture *mTempPicture = nullptr;
303
304 QRectF imageBoundingRect( const QgsRenderContext &context ) const;
305
306 friend class QgsEffectStack;
307
308 QgsPaintEffect &operator= ( const QgsPaintEffect & ) = delete;
309
310};
311
325{
326 public:
327
329
335 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
336
337 QString type() const override { return QStringLiteral( "drawSource" ); }
338 QgsDrawSourceEffect *clone() const override SIP_FACTORY;
339 QVariantMap properties() const override;
340 void readProperties( const QVariantMap &props ) override;
341
348 void setOpacity( const double opacity ) { mOpacity = opacity; }
349
356 double opacity() const { return mOpacity; }
357
364 void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
365
372 QPainter::CompositionMode blendMode() const { return mBlendMode; }
373
374 protected:
375
376 void draw( QgsRenderContext &context ) override;
377
378 private:
379
380 double mOpacity = 1.0;
381 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
382};
383
390class CORE_EXPORT QgsEffectPainter
391{
392 public:
393
399 QgsEffectPainter( QgsRenderContext &renderContext );
400
407 QgsEffectPainter( QgsRenderContext &renderContext, QgsPaintEffect *effect );
409
415 void setEffect( QgsPaintEffect *effect );
416
418
423 QPainter *operator->() { return mPainter; }
425
426 private:
427#ifdef SIP_RUN
428 const QgsEffectPainter &operator=( const QgsEffectPainter & );
429#endif
430
431 QgsRenderContext &mRenderContext;
432 QPainter *mPainter = nullptr;
433 QgsPaintEffect *mEffect = nullptr;
434};
435
436#endif // QGSPAINTEFFECT_H
437
A paint effect which blurs a source picture, using a number of different blur methods.
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.
A paint effect which draws the source picture with minor or no alterations.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QgsDrawSourceEffect()=default
double opacity() const
Returns the opacity for the effect.
QString type() const override
Returns the effect type.
A paint effect which draws an offset and optionally blurred drop shadow.
A class to manager painter saving and restoring required for effect drawing.
A paint effect which consists of a stack of other chained paint effects.
A paint effect which draws a glow within a picture.
A paint effect which draws a glow outside of a picture.
Base class for visual effects which can be applied to QPicture drawings.
QgsPaintEffect()=default
virtual void readProperties(const QVariantMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
DrawMode drawMode() const
Returns the draw mode for the effect.
const QPicture * source() const
Returns the source QPicture.
bool enabled() const
Returns whether the effect is enabled.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
DrawMode
Drawing modes for effects.
@ Render
The result of the effect is rendered on the destination, but does not affect subsequent effects in th...
@ Modifier
The result of the effect is not rendered, but is passed on to following effects in the stack.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
virtual QString type() const =0
Returns the effect type.
Contains information about the context of a rendering operation.
A paint effect which applies transformations (such as move, scale and rotate) to a picture.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:101
#define SIP_END
Definition qgis_sip.h:208