QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 "qgis_core.h"
21 #include "qgspainteffect.h"
22 #include "qgis_sip.h"
23 #include "qgssymbol.h"
24 #include <QPainter>
25 
34 class CORE_EXPORT QgsShadowEffect : public QgsPaintEffect
35 {
36 
37  public:
38 
40 
41  QgsStringMap properties() const override;
42  void readProperties( const QgsStringMap &props ) override;
43 
52  void setBlurLevel( const double level ) { mBlurLevel = level; }
53 
62  double blurLevel() const { return mBlurLevel; }
63 
72  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
73 
82  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
83 
92  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
93 
102  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
103 
110  void setOffsetAngle( const int angle ) { mOffsetAngle = angle; }
111 
118  int offsetAngle() const { return mOffsetAngle; }
119 
127  void setOffsetDistance( const double distance ) { mOffsetDist = distance; }
128 
136  double offsetDistance() const { return mOffsetDist; }
137 
145  void setOffsetUnit( const QgsUnitTypes::RenderUnit unit ) { mOffsetUnit = unit; }
146 
154  QgsUnitTypes::RenderUnit offsetUnit() const { return mOffsetUnit; }
155 
163  void setOffsetMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetMapUnitScale = scale; }
164 
172  const QgsMapUnitScale &offsetMapUnitScale() const { return mOffsetMapUnitScale; }
173 
179  void setColor( const QColor &color ) { mColor = color; }
180 
186  QColor color() const { return mColor; }
187 
194  void setOpacity( const double opacity ) { mOpacity = opacity; }
195 
202  double opacity() const { return mOpacity; }
203 
210  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
211 
218  QPainter::CompositionMode blendMode() const { return mBlendMode; }
219 
220  protected:
221 
222  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
223  void draw( QgsRenderContext &context ) override;
224 
231  virtual bool exteriorShadow() const = 0;
232 
233  double mBlurLevel = 2.645;
236  int mOffsetAngle = 135;
237  double mOffsetDist = 2.0;
240  double mOpacity = 1.0;
241  QColor mColor;
242  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_Multiply;
243 
244 };
245 
246 
254 class CORE_EXPORT QgsDropShadowEffect : public QgsShadowEffect
255 {
256 
257  public:
258 
264  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
265 
267 
268  QString type() const override;
269  QgsDropShadowEffect *clone() const override SIP_FACTORY;
270 
271  protected:
272 
273  bool exteriorShadow() const override;
274 
275 };
276 
285 class CORE_EXPORT QgsInnerShadowEffect : public QgsShadowEffect
286 {
287 
288  public:
289 
295  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
296 
298 
299  QString type() const override;
300  QgsInnerShadowEffect *clone() const override SIP_FACTORY;
301 
302  protected:
303 
304  bool exteriorShadow() const override;
305 
306 };
307 
308 #endif // QGSSHADOWEFFECT_H
309 
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the shadow blur level (radius).
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
double blurLevel() const
Returns the blur level (radius) for the shadow.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow blur strength (radius).
double offsetDistance() const
Returns the distance used for offsetting the shadow.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the shadow blur strength (radius).
Base class for visual effects which can be applied to QPicture drawings.
QgsMapUnitScale mBlurMapUnitScale
QMap< QString, QString > QgsStringMap
Definition: qgis.h:612
virtual bool exteriorShadow() const =0
Specifies whether the shadow is drawn outside the picture or within the picture.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
void setBlurLevel(const double level)
Sets blur level (radius) for the shadow.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsMapUnitScale mOffsetMapUnitScale
double opacity() const
Returns the opacity for the effect.
QColor color() const
Returns the color used for the shadow.
virtual QString type() const =0
Returns the effect type.
#define SIP_FACTORY
Definition: qgis_sip.h:76
A paint effect which draws an offset and optionally blurred drop shadow.
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.
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow blur level (radius).
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.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shadow offset distance.
void setOffsetUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow offset distance.
Base class for paint effects which offset, blurred shadows.
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.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale used for the shadow offset distance.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:145