QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
118  void setBlurLevel( const int level ) { mBlurLevel = level; }
119 
126  int blurLevel() const { return mBlurLevel; }
127 
134  void setOpacity( const double opacity ) { mOpacity = opacity; }
135 
142  double opacity() const { return mOpacity; }
143 
152  void setColor( const QColor &color ) { mColor = color; }
153 
162  QColor color() const { return mColor; }
163 
171  void setRamp( QgsColorRamp *ramp SIP_TRANSFER );
172 
180  QgsColorRamp *ramp() const { return mRamp; }
181 
188  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
189 
196  QPainter::CompositionMode blendMode() const { return mBlendMode; }
197 
207  void setColorType( GlowColorType colorType ) { mColorType = colorType; }
208 
217  GlowColorType colorType() const { return mColorType; }
218 
219  QgsGlowEffect &operator=( const QgsGlowEffect &rhs );
220 
221  protected:
222 
223  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
224  void draw( QgsRenderContext &context ) override;
225 
232  virtual bool shadeExterior() const = 0;
233 
234  double mSpread = 2.0;
237  QgsColorRamp *mRamp = nullptr;
238  int mBlurLevel = 3;
239  double mOpacity = 0.5;
240  QColor mColor;
241  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
242  GlowColorType mColorType = SingleColor;
243 
244 };
245 
246 
255 class CORE_EXPORT QgsOuterGlowEffect : public QgsGlowEffect
256 {
257 
258  public:
259 
265  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
266 
268 
269  QString type() const override { return QStringLiteral( "outerGlow" ); }
270  QgsOuterGlowEffect *clone() const override SIP_FACTORY;
271 
272  protected:
273 
274  bool shadeExterior() const override { return true; }
275 
276 };
277 
278 
287 class CORE_EXPORT QgsInnerGlowEffect : public QgsGlowEffect
288 {
289 
290  public:
291 
297  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
298 
300 
301  QString type() const override { return QStringLiteral( "innerGlow" ); }
302  QgsInnerGlowEffect *clone() const override SIP_FACTORY;
303 
304  protected:
305 
306  bool shadeExterior() const override { return false; }
307 
308 };
309 
310 #endif // QGSGLOWEFFECT_H
311 
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
double opacity() const
Returns the opacity for the effect.
bool shadeExterior() const override
Specifies whether the glow is drawn outside the picture or within the picture.
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
Base class for visual effects which can be applied to QPicture drawings.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:501
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Base class for paint effect which draw a glow inside or outside a picture.
Definition: qgsgloweffect.h:38
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
void setSpreadMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the spread distance.
void setBlurLevel(const int level)
Sets blur level (strength) for the glow.
QString type() const override
Returns the effect type.
QgsUnitTypes::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
Definition: qgsgloweffect.h:91
void setSpreadUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the glow spread distance.
Definition: qgsgloweffect.h:82
void setColorType(GlowColorType colorType)
Sets the color mode to use for the glow.
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QString type() const override
Returns the effect type.
#define SIP_FACTORY
Definition: qgis_sip.h:69
GlowColorType
Color sources for the glow.
Definition: qgsgloweffect.h:44
void setSpread(const double spread)
Sets the spread distance for drawing the glow effect.
Definition: qgsgloweffect.h:64
GlowColorType colorType() const
Returns the color mode used for the glow.
A paint effect which draws a glow outside of a picture.
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect&#39;s properties and restores the effect to the state described by the pr...
void setOpacity(const double opacity)
Sets the opacity for the effect.
Use a single color and fade the color to totally transparent.
Definition: qgsgloweffect.h:46
Contains information about the context of a rendering operation.
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
double spread() const
Returns the spread distance used for drawing the glow effect.
Definition: qgsgloweffect.h:73
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Struct for storing maximum and minimum scales for measurements in map units.
QgsMapUnitScale mSpreadMapUnitScale
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect&#39;s result on to the specified render context.
A paint effect which draws a glow within a picture.
void setColor(const QColor &color)
Sets the color for the glow.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:100
int blurLevel() const
Returns the blur level (strength) for the glow.
bool shadeExterior() const override
Specifies whether the glow is drawn outside the picture or within the picture.
QColor color() const
Returns the color for the glow.