QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgscolorramp.h"
24 #include "qgsunittypes.h"
25 #include "qgsmapunitscale.h"
26 
27 #include <QPainter>
28 
29 
39 class CORE_EXPORT QgsGlowEffect : public QgsPaintEffect
40 {
41 
42  public:
43 
46  {
48  ColorRamp
49  };
50 
51  QgsGlowEffect();
52  QgsGlowEffect( const QgsGlowEffect &other );
53  ~QgsGlowEffect() override;
54 
55  QVariantMap properties() const override;
56  void readProperties( const QVariantMap &props ) override;
57 
65  void setSpread( const double spread ) { mSpread = spread; }
66 
74  double spread() const { return mSpread; }
75 
83  void setSpreadUnit( const QgsUnitTypes::RenderUnit unit ) { mSpreadUnit = unit; }
84 
92  QgsUnitTypes::RenderUnit spreadUnit() const { return mSpreadUnit; }
93 
101  void setSpreadMapUnitScale( const QgsMapUnitScale &scale ) { mSpreadMapUnitScale = scale; }
102 
110  const QgsMapUnitScale &spreadMapUnitScale() const { return mSpreadMapUnitScale; }
111 
120  void setBlurLevel( const double level ) { mBlurLevel = level; }
121 
129  double blurLevel() const { return mBlurLevel; }
130 
139  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
140 
149  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
150 
159  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
160 
169  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
170 
177  void setOpacity( const double opacity ) { mOpacity = opacity; }
178 
185  double opacity() const { return mOpacity; }
186 
195  void setColor( const QColor &color ) { mColor = color; }
196 
205  QColor color() const { return mColor; }
206 
214  void setRamp( QgsColorRamp *ramp SIP_TRANSFER );
215 
223  QgsColorRamp *ramp() const { return mRamp; }
224 
231  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
232 
239  QPainter::CompositionMode blendMode() const { return mBlendMode; }
240 
250  void setColorType( GlowColorType colorType ) { mColorType = colorType; }
251 
260  GlowColorType colorType() const { return mColorType; }
261 
262  QgsGlowEffect &operator=( const QgsGlowEffect &rhs );
263 
264  protected:
265 
266  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
267  void draw( QgsRenderContext &context ) override;
268 
275  virtual bool shadeExterior() const = 0;
276 
277  double mSpread = 2.0;
280  QgsColorRamp *mRamp = nullptr;
281  double mBlurLevel = 2.645;
284  double mOpacity = 0.5;
285  QColor mColor;
286  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
287  GlowColorType mColorType = SingleColor;
288 
289 };
290 
291 
300 class CORE_EXPORT QgsOuterGlowEffect : public QgsGlowEffect
301 {
302 
303  public:
304 
310  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
311 
313 
314  QString type() const override { return QStringLiteral( "outerGlow" ); }
315  QgsOuterGlowEffect *clone() const override SIP_FACTORY;
316 
317  protected:
318 
319  bool shadeExterior() const override { return true; }
320 
321 };
322 
323 
332 class CORE_EXPORT QgsInnerGlowEffect : public QgsGlowEffect
333 {
334 
335  public:
336 
342  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
343 
345 
346  QString type() const override { return QStringLiteral( "innerGlow" ); }
347  QgsInnerGlowEffect *clone() const override SIP_FACTORY;
348 
349  protected:
350 
351  bool shadeExterior() const override { return false; }
352 
353 };
354 
355 #endif // QGSGLOWEFFECT_H
356 
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
QgsGlowEffect::blendMode
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Definition: qgsgloweffect.h:239
QgsGlowEffect::blurMapUnitScale
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the glow blur strength (radius).
Definition: qgsgloweffect.h:169
QgsGlowEffect::setSpreadMapUnitScale
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
Definition: qgsgloweffect.h:101
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsGlowEffect::mBlurMapUnitScale
QgsMapUnitScale mBlurMapUnitScale
Definition: qgsgloweffect.h:283
QgsGlowEffect::color
QColor color() const
Returns the color for the glow.
Definition: qgsgloweffect.h:205
QgsGlowEffect::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Definition: qgsgloweffect.h:231
QgsGlowEffect::setBlurLevel
void setBlurLevel(const double level)
Sets blur level (radius) for the glow.
Definition: qgsgloweffect.h:120
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
qgsunittypes.h
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
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:177
QgsGlowEffect::blurUnit
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the glow blur level (radius).
Definition: qgsgloweffect.h:149
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:110
qgscolorramp.h
QgsGlowEffect::setBlurUnit
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow blur level (radius).
Definition: qgsgloweffect.h:139
QgsGlowEffect::setSpreadUnit
void setSpreadUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow spread distance.
Definition: qgsgloweffect.h:83
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:129
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsPaintEffect::boundingRect
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
Definition: qgspainteffect.cpp:175
QgsPaintEffect::readProperties
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...
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:36
QgsGlowEffect::setColor
void setColor(const QColor &color)
Sets the color for the glow.
Definition: qgsgloweffect.h:195
QgsGlowEffect::ramp
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
Definition: qgsgloweffect.h:223
QgsGlowEffect::setSpread
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
Definition: qgsgloweffect.h:65
QgsGlowEffect::setColorType
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
Definition: qgsgloweffect.h:250
QgsInnerGlowEffect
A paint effect which draws a glow within a picture.
Definition: qgsgloweffect.h:332
QgsGlowEffect::mColor
QColor mColor
Definition: qgsgloweffect.h:285
QgsInnerGlowEffect::type
QString type() const override
Returns the effect type.
Definition: qgsgloweffect.h:346
QgsGlowEffect::colorType
GlowColorType colorType() const
Returns the color mode used for the glow.
Definition: qgsgloweffect.h:260
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:52
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:185
QgsGlowEffect::mSpreadMapUnitScale
QgsMapUnitScale mSpreadMapUnitScale
Definition: qgsgloweffect.h:279
qgsmapunitscale.h
QgsGlowEffect::GlowColorType
GlowColorType
Color sources for the glow.
Definition: qgsgloweffect.h:45
QgsPaintEffect::properties
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsOuterGlowEffect::type
QString type() const override
Returns the effect type.
Definition: qgsgloweffect.h:314
QgsGlowEffect::spread
double spread() const
Returns the spread distance used for drawing the glow effect.
Definition: qgsgloweffect.h:74
QgsGlowEffect::SingleColor
@ SingleColor
Use a single color and fade the color to totally transparent.
Definition: qgsgloweffect.h:47
QgsGlowEffect::spreadUnit
QgsUnitTypes::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
Definition: qgsgloweffect.h:92
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:159