QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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_core.h"
21 #include "qgis.h"
22 #include "qgspainteffect.h"
23 #include "qgssymbol.h"
24 #include "qgscolorramp.h"
25 
26 #include <QPainter>
27 
28 
38 class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
39 {
40 
41  public:
42 
45  {
47  ColorRamp
48  };
49 
50  QgsGlowEffect();
51  QgsGlowEffect( const QgsGlowEffect &other );
52  ~QgsGlowEffect() override;
53 
54  QgsStringMap properties() const override;
55  void readProperties( const QgsStringMap &props ) override;
56 
64  void setSpread( const double spread ) { mSpread = spread; }
65 
73  double spread() const { return mSpread; }
74 
82  void setSpreadUnit( const QgsUnitTypes::RenderUnit unit ) { mSpreadUnit = unit; }
83 
91  QgsUnitTypes::RenderUnit spreadUnit() const { return mSpreadUnit; }
92 
100  void setSpreadMapUnitScale( const QgsMapUnitScale &scale ) { mSpreadMapUnitScale = scale; }
101 
109  const QgsMapUnitScale &spreadMapUnitScale() const { return mSpreadMapUnitScale; }
110 
119  void setBlurLevel( const double level ) { mBlurLevel = level; }
120 
128  double blurLevel() const { return mBlurLevel; }
129 
138  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
139 
148  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
149 
158  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
159 
168  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
169 
176  void setOpacity( const double opacity ) { mOpacity = opacity; }
177 
184  double opacity() const { return mOpacity; }
185 
194  void setColor( const QColor &color ) { mColor = color; }
195 
204  QColor color() const { return mColor; }
205 
213  void setRamp( QgsColorRamp *ramp SIP_TRANSFER );
214 
222  QgsColorRamp *ramp() const { return mRamp; }
223 
230  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
231 
238  QPainter::CompositionMode blendMode() const { return mBlendMode; }
239 
249  void setColorType( GlowColorType colorType ) { mColorType = colorType; }
250 
259  GlowColorType colorType() const { return mColorType; }
260 
261  QgsGlowEffect &operator=( const QgsGlowEffect &rhs );
262 
263  protected:
264 
265  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
266  void draw( QgsRenderContext &context ) override;
267 
274  virtual bool shadeExterior() const = 0;
275 
276  double mSpread = 2.0;
279  QgsColorRamp *mRamp = nullptr;
280  double mBlurLevel = 2.645;
283  double mOpacity = 0.5;
284  QColor mColor;
285  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
286  GlowColorType mColorType = SingleColor;
287 
288 };
289 
290 
299 class CORE_EXPORT QgsOuterGlowEffect : public QgsGlowEffect
300 {
301 
302  public:
303 
309  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
310 
312 
313  QString type() const override { return QStringLiteral( "outerGlow" ); }
314  QgsOuterGlowEffect *clone() const override SIP_FACTORY;
315 
316  protected:
317 
318  bool shadeExterior() const override { return true; }
319 
320 };
321 
322 
331 class CORE_EXPORT QgsInnerGlowEffect : public QgsGlowEffect
332 {
333 
334  public:
335 
341  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
342 
344 
345  QString type() const override { return QStringLiteral( "innerGlow" ); }
346  QgsInnerGlowEffect *clone() const override SIP_FACTORY;
347 
348  protected:
349 
350  bool shadeExterior() const override { return false; }
351 
352 };
353 
354 #endif // QGSGLOWEFFECT_H
355 
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:32
QgsGlowEffect::blendMode
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Definition: qgsgloweffect.h:238
QgsGlowEffect::blurMapUnitScale
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the glow blur strength (radius).
Definition: qgsgloweffect.h:168
QgsGlowEffect::setSpreadMapUnitScale
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
Definition: qgsgloweffect.h:100
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsGlowEffect::mBlurMapUnitScale
QgsMapUnitScale mBlurMapUnitScale
Definition: qgsgloweffect.h:282
QgsGlowEffect::color
QColor color() const
Returns the color for the glow.
Definition: qgsgloweffect.h:204
QgsPaintEffect::properties
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsGlowEffect::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Definition: qgsgloweffect.h:230
QgsGlowEffect::setBlurLevel
void setBlurLevel(const double level)
Sets blur level (radius) for the glow.
Definition: qgsgloweffect.h:119
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
qgspainteffect.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsGlowEffect::setOpacity
void setOpacity(const double opacity)
Sets the opacity for the effect.
Definition: qgsgloweffect.h:176
QgsGlowEffect::shadeExterior
virtual bool shadeExterior() const =0
Specifies whether the glow is drawn outside the picture or within the picture.
QgsGlowEffect::blurUnit
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the glow blur level (radius).
Definition: qgsgloweffect.h:148
QgsGlowEffect
Base class for paint effect which draw a glow inside or outside a picture.
Definition: qgsgloweffect.h:39
QgsGlowEffect::spreadMapUnitScale
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
Definition: qgsgloweffect.h:109
qgscolorramp.h
QgsGlowEffect::setBlurUnit
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow blur level (radius).
Definition: qgsgloweffect.h:138
QgsGlowEffect::setSpreadUnit
void setSpreadUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow spread distance.
Definition: qgsgloweffect.h:82
QgsPaintEffect::clone
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
QgsGlowEffect::blurLevel
double blurLevel() const
Returns the blur level (radius) for the glow.
Definition: qgsgloweffect.h:128
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsPaintEffect::readProperties
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
QgsPaintEffect::boundingRect
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
Definition: qgspainteffect.cpp:202
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:38
QgsGlowEffect::setColor
void setColor(const QColor &color)
Sets the color for the glow.
Definition: qgsgloweffect.h:194
QgsGlowEffect::ramp
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
Definition: qgsgloweffect.h:222
QgsGlowEffect::setSpread
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
Definition: qgsgloweffect.h:64
QgsGlowEffect::setColorType
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
Definition: qgsgloweffect.h:249
QgsInnerGlowEffect
A paint effect which draws a glow within a picture.
Definition: qgsgloweffect.h:332
QgsGlowEffect::mColor
QColor mColor
Definition: qgsgloweffect.h:284
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsInnerGlowEffect::type
QString type() const override
Returns the effect type.
Definition: qgsgloweffect.h:345
QgsGlowEffect::colorType
GlowColorType colorType() const
Returns the color mode used for the glow.
Definition: qgsgloweffect.h:259
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:54
QgsOuterGlowEffect
A paint effect which draws a glow outside of a picture.
Definition: qgsgloweffect.h:300
QgsGlowEffect::opacity
double opacity() const
Returns the opacity for the effect.
Definition: qgsgloweffect.h:184
QgsGlowEffect::mSpreadMapUnitScale
QgsMapUnitScale mSpreadMapUnitScale
Definition: qgsgloweffect.h:278
QgsGlowEffect::GlowColorType
GlowColorType
Color sources for the glow.
Definition: qgsgloweffect.h:45
QgsOuterGlowEffect::type
QString type() const override
Returns the effect type.
Definition: qgsgloweffect.h:313
qgssymbol.h
QgsGlowEffect::spread
double spread() const
Returns the spread distance used for drawing the glow effect.
Definition: qgsgloweffect.h:73
QgsGlowEffect::SingleColor
@ SingleColor
Use a single color and fade the color to totally transparent.
Definition: qgsgloweffect.h:46
QgsGlowEffect::spreadUnit
QgsUnitTypes::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
Definition: qgsgloweffect.h:91
QgsPaintEffect::draw
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
QgsGlowEffect::setBlurMapUnitScale
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the glow blur strength (radius).
Definition: qgsgloweffect.h:158