QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsgloweffect.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgloweffect.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 QGSGLOWEFFECT_H
18#define QGSGLOWEFFECT_H
19
20#include "qgis.h"
21#include "qgis_core.h"
22#include "qgscolorramp.h"
23#include "qgsmapunitscale.h"
24#include "qgspainteffect.h"
25
26#include <QPainter>
27#include <QString>
28
29using namespace Qt::StringLiterals;
30
38
39class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
40{
41
42 public:
43
50
52 QgsGlowEffect( const QgsGlowEffect &other );
53 ~QgsGlowEffect() override;
54
55 Qgis::PaintEffectFlags flags() const override;
56 QVariantMap properties() const override;
57
59 void readProperties( const QVariantMap &props ) override;
60
68 void setSpread( const double spread ) { mSpread = spread; }
69
77 double spread() const { return mSpread; }
78
86 void setSpreadUnit( const Qgis::RenderUnit unit ) { mSpreadUnit = unit; }
87
96
105
114
123 void setBlurLevel( const double level ) { mBlurLevel = level; }
124
132 double blurLevel() const { return mBlurLevel; }
133
142 void setBlurUnit( const Qgis::RenderUnit unit ) { mBlurUnit = unit; }
143
153
162 void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
163
173
180 void setOpacity( const double opacity ) { mOpacity = opacity; }
181
188 double opacity() const { return mOpacity; }
189
198 void setColor( const QColor &color ) { mColor = color; }
199
208 QColor color() const { return mColor; }
209
217 void setRamp( QgsColorRamp *ramp SIP_TRANSFER );
218
226 QgsColorRamp *ramp() const { return mRamp; }
227
234 void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
235
242 QPainter::CompositionMode blendMode() const { return mBlendMode; }
243
254
264
265 QgsGlowEffect &operator=( const QgsGlowEffect &rhs );
266
267 protected:
268
269 QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
270 void draw( QgsRenderContext &context ) override;
271
278 virtual bool shadeExterior() const = 0;
279
280 double mSpread = 2.0;
283 QgsColorRamp *mRamp = nullptr;
284 double mBlurLevel = 2.645;
287 double mOpacity = 0.5;
288 QColor mColor;
289 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
291
292};
293
294
301
302class CORE_EXPORT QgsOuterGlowEffect : public QgsGlowEffect
303{
304
305 public:
306
312 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
313
315
316 QString type() const override { return u"outerGlow"_s; }
317 QgsOuterGlowEffect *clone() const override SIP_FACTORY;
318
319 protected:
320
321 bool shadeExterior() const override { return true; }
322
323};
324
325
332
333class CORE_EXPORT QgsInnerGlowEffect : public QgsGlowEffect
334{
335
336 public:
337
343 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
344
346
347 QString type() const override { return u"innerGlow"_s; }
348 QgsInnerGlowEffect *clone() const override SIP_FACTORY;
349
350 protected:
351
352 bool shadeExterior() const override { return false; }
353
354};
355
356#endif // QGSGLOWEFFECT_H
357
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
Definition qgis.h:2873
RenderUnit
Rendering size units.
Definition qgis.h:5255
@ Millimeters
Millimeters.
Definition qgis.h:5256
Abstract base class for color ramps.
Base class for paint effects which draw a glow inside or outside a picture.
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
Qgis::RenderUnit blurUnit() const
Returns the units used for the glow blur level (radius).
void setOpacity(const double opacity)
Sets the opacity for the effect.
QgsMapUnitScale mBlurMapUnitScale
Qgis::RenderUnit mSpreadUnit
double spread() const
Returns the spread distance used for drawing the glow effect.
virtual bool shadeExterior() const =0
Specifies whether the glow is drawn outside the picture or within the picture.
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
GlowColorType
Color sources for the glow.
@ SingleColor
Use a single color and fade the color to totally transparent.
@ ColorRamp
Use colors from a color ramp.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsColorRamp * mRamp
double blurLevel() const
Returns the blur level (radius) for the glow.
double opacity() const
Returns the opacity for the effect.
Qgis::RenderUnit mBlurUnit
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QColor color() const
Returns the color for the glow.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the glow blur strength (radius).
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the glow blur level (radius).
void setBlurLevel(const double level)
Sets blur level (radius) for the glow.
GlowColorType mColorType
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
Qgis::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
QPainter::CompositionMode mBlendMode
QgsMapUnitScale mSpreadMapUnitScale
void setSpreadUnit(const Qgis::RenderUnit unit)
Sets the units used for the glow spread distance.
void setColor(const QColor &color)
Sets the color for the glow.
GlowColorType colorType() const
Returns the color mode used for the glow.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the glow blur strength (radius).
A paint effect which draws a glow within a picture.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsInnerGlowEffect effect from a properties string map.
bool shadeExterior() const override
Specifies whether the glow is drawn outside the picture or within the picture.
QString type() const override
Returns the effect type.
Struct for storing maximum and minimum scales for measurements in map units.
A paint effect which draws a glow outside of a picture.
QString type() const override
Returns the effect type.
bool shadeExterior() const override
Specifies whether the glow is drawn outside the picture or within the picture.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsOuterGlowEffect effect from a properties string map.
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...
virtual Qgis::PaintEffectFlags flags() const
Returns flags which specify how the paint effect behaves.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
Contains information about the context of a rendering operation.
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84