QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsshadoweffect.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsshadoweffect.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 QGSSHADOWEFFECT_H
18 #define QGSSHADOWEFFECT_H
19 
20 #include "qgspainteffect.h"
21 #include "qgis.h"
22 #include "qgssymbolv2.h"
23 #include <QPainter>
24 
32 class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
33 {
34 
35  public:
36 
38  virtual ~QgsShadowEffect();
39 
40  virtual QgsStringMap properties() const override;
41  virtual void readProperties( const QgsStringMap& props ) override;
42 
48  void setBlurLevel( const int level ) { mBlurLevel = level; }
49 
55  int blurLevel() const { return mBlurLevel; }
56 
62  void setOffsetAngle( const int angle ) { mOffsetAngle = angle; }
63 
69  int offsetAngle() const { return mOffsetAngle; }
70 
77  void setOffsetDistance( const double distance ) { mOffsetDist = distance; }
78 
85  double offsetDistance() const { return mOffsetDist; }
86 
93  void setOffsetUnit( const QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
94 
101  QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
102 
109  void setOffsetMapUnitScale( const QgsMapUnitScale& scale ) { mOffsetMapUnitScale = scale; }
110 
117  const QgsMapUnitScale& offsetMapUnitScale() const { return mOffsetMapUnitScale; }
118 
123  void setColor( const QColor& color ) { mColor = color; }
124 
129  QColor color() const { return mColor; }
130 
136  void setTransparency( const double transparency ) { mTransparency = transparency; }
137 
143  double transparency() const { return mTransparency; }
144 
150  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
151 
157  QPainter::CompositionMode blendMode() const { return mBlendMode; }
158 
159  protected:
160 
161  virtual QRectF boundingRect( const QRectF& rect, const QgsRenderContext& context ) const override;
162  virtual void draw( QgsRenderContext& context ) override;
163 
169  virtual bool exteriorShadow() const = 0;
170 
173  double mOffsetDist;
178  QPainter::CompositionMode mBlendMode;
179 
180 };
181 
182 
189 class CORE_EXPORT QgsDropShadowEffect : public QgsShadowEffect
190 {
191 
192  public:
193 
198  static QgsPaintEffect* create( const QgsStringMap& map );
199 
201  virtual ~QgsDropShadowEffect();
202 
203  virtual QString type() const override { return QString( "dropShadow" ); }
204  virtual QgsDropShadowEffect* clone() const override;
205 
206  protected:
207 
208  virtual bool exteriorShadow() const override { return true; }
209 
210 };
211 
219 class CORE_EXPORT QgsInnerShadowEffect : public QgsShadowEffect
220 {
221 
222  public:
223 
228  static QgsPaintEffect* create( const QgsStringMap& map );
229 
231  virtual ~QgsInnerShadowEffect();
232 
233  virtual QString type() const override { return QString( "innerShadow" ); }
234  virtual QgsInnerShadowEffect* clone() const override;
235 
236  protected:
237 
238  virtual bool exteriorShadow() const override { return false; }
239 
240 };
241 
242 #endif // QGSSHADOWEFFECT_H
243 
virtual bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
virtual QString type() const override
Returns the effect type.
double offsetDistance() const
Returns the distance used for offsetting the shadow.
Base class for visual effects which can be applied to QPicture drawings.
void setBlurLevel(const int level)
Sets blur level (strength) for the shadow.
void setOffsetUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the shadow offset distance.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsMapUnitScale mOffsetMapUnitScale
QColor color() const
Returns the color used for the shadow.
virtual QString type() const override
Returns the effect type.
QPainter::CompositionMode mBlendMode
int blurLevel() const
Returns the blur level (strength) for the shadow.
double transparency() const
Returns the transparency for the effect.
A paint effect which draws an offset and optionally blurred drop shadow.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
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...
A paint effect which draws an offset and optionally blurred drop shadow within a picture.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow offset distance.
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.
Struct for storing maximum and minimum scales for measurements in map units.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
QgsSymbolV2::OutputUnit mOffsetUnit
virtual bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
Base class for paint effects which offset, blurred shadows.
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units used for the shadow offset distance.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect&#39;s result on to the specified render context.
void setColor(const QColor &color)
Sets the color for the shadow.
int offsetAngle() const
Returns the angle used for offsetting the shadow.
void setTransparency(const double transparency)
Sets the transparency for the effect.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale used for the shadow offset distance.