QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsunittypes.h"
24 #include "qgsmapunitscale.h"
25 
26 #include <QPainter>
27 
37 {
38 
39  public:
40 
42 
43  QVariantMap properties() const override;
44  void readProperties( const QVariantMap &props ) override;
45 
54  void setBlurLevel( const double level ) { mBlurLevel = level; }
55 
64  double blurLevel() const { return mBlurLevel; }
65 
74  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
75 
84  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
85 
94  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
95 
104  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
105 
112  void setOffsetAngle( const int angle ) { mOffsetAngle = angle; }
113 
120  int offsetAngle() const { return mOffsetAngle; }
121 
129  void setOffsetDistance( const double distance ) { mOffsetDist = distance; }
130 
138  double offsetDistance() const { return mOffsetDist; }
139 
147  void setOffsetUnit( const QgsUnitTypes::RenderUnit unit ) { mOffsetUnit = unit; }
148 
156  QgsUnitTypes::RenderUnit offsetUnit() const { return mOffsetUnit; }
157 
165  void setOffsetMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetMapUnitScale = scale; }
166 
174  const QgsMapUnitScale &offsetMapUnitScale() const { return mOffsetMapUnitScale; }
175 
181  void setColor( const QColor &color ) { mColor = color; }
182 
188  QColor color() const { return mColor; }
189 
196  void setOpacity( const double opacity ) { mOpacity = opacity; }
197 
204  double opacity() const { return mOpacity; }
205 
212  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
213 
220  QPainter::CompositionMode blendMode() const { return mBlendMode; }
221 
222  protected:
223 
224  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
225  void draw( QgsRenderContext &context ) override;
226 
233  virtual bool exteriorShadow() const = 0;
234 
235  double mBlurLevel = 2.645;
238  int mOffsetAngle = 135;
239  double mOffsetDist = 2.0;
242  double mOpacity = 1.0;
243  QColor mColor;
244  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_Multiply;
245 
246 };
247 
248 
257 {
258 
259  public:
260 
266  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
267 
269 
270  QString type() const override;
271  QgsDropShadowEffect *clone() const override SIP_FACTORY;
272 
273  protected:
274 
275  bool exteriorShadow() const override;
276 
277 };
278 
288 {
289 
290  public:
291 
297  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
298 
300 
301  QString type() const override;
302  QgsInnerShadowEffect *clone() const override SIP_FACTORY;
303 
304  protected:
305 
306  bool exteriorShadow() const override;
307 
308 };
309 
310 #endif // QGSSHADOWEFFECT_H
311 
QgsShadowEffect::setBlurUnit
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow blur level (radius).
Definition: qgsshadoweffect.h:74
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsInnerShadowEffect
A paint effect which draws an offset and optionally blurred drop shadow within a picture.
Definition: qgsshadoweffect.h:287
QgsShadowEffect::mColor
QColor mColor
Definition: qgsshadoweffect.h:243
QgsShadowEffect::setColor
void setColor(const QColor &color)
Sets the color for the shadow.
Definition: qgsshadoweffect.h:181
QgsShadowEffect::color
QColor color() const
Returns the color used for the shadow.
Definition: qgsshadoweffect.h:188
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
qgsunittypes.h
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
QgsShadowEffect::offsetMapUnitScale
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale used for the shadow offset distance.
Definition: qgsshadoweffect.h:174
QgsShadowEffect::offsetDistance
double offsetDistance() const
Returns the distance used for offsetting the shadow.
Definition: qgsshadoweffect.h:138
qgspainteffect.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsShadowEffect::opacity
double opacity() const
Returns the opacity for the effect.
Definition: qgsshadoweffect.h:204
QgsShadowEffect::setOpacity
void setOpacity(const double opacity)
Sets the opacity for the effect.
Definition: qgsshadoweffect.h:196
QgsShadowEffect::mOffsetMapUnitScale
QgsMapUnitScale mOffsetMapUnitScale
Definition: qgsshadoweffect.h:241
QgsShadowEffect::blurMapUnitScale
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the shadow blur strength (radius).
Definition: qgsshadoweffect.h:104
QgsDropShadowEffect
A paint effect which draws an offset and optionally blurred drop shadow.
Definition: qgsshadoweffect.h:256
QgsShadowEffect::offsetUnit
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shadow offset distance.
Definition: qgsshadoweffect.h:156
QgsShadowEffect::setOffsetUnit
void setOffsetUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow offset distance.
Definition: qgsshadoweffect.h:147
QgsPaintEffect::clone
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
qgis_sip.h
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...
QgsShadowEffect::exteriorShadow
virtual bool exteriorShadow() const =0
Specifies whether the shadow is drawn outside the picture or within the picture.
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:36
QgsShadowEffect::blurLevel
double blurLevel() const
Returns the blur level (radius) for the shadow.
Definition: qgsshadoweffect.h:64
QgsShadowEffect::offsetAngle
int offsetAngle() const
Returns the angle used for offsetting the shadow.
Definition: qgsshadoweffect.h:120
SIP_NODEFAULTCTORS
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101
QgsShadowEffect::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Definition: qgsshadoweffect.h:212
QgsShadowEffect::setBlurLevel
void setBlurLevel(const double level)
Sets blur level (radius) for the shadow.
Definition: qgsshadoweffect.h:54
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:52
qgsmapunitscale.h
QgsShadowEffect::mBlurMapUnitScale
QgsMapUnitScale mBlurMapUnitScale
Definition: qgsshadoweffect.h:237
QgsShadowEffect::blurUnit
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the shadow blur level (radius).
Definition: qgsshadoweffect.h:84
QgsShadowEffect::setOffsetAngle
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
Definition: qgsshadoweffect.h:112
QgsShadowEffect::blendMode
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Definition: qgsshadoweffect.h:220
QgsPaintEffect::properties
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsPaintEffect::type
virtual QString type() const =0
Returns the effect type.
MathUtils::angle
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
QgsShadowEffect::setOffsetMapUnitScale
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow offset distance.
Definition: qgsshadoweffect.h:165
QgsShadowEffect::setBlurMapUnitScale
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the shadow blur strength (radius).
Definition: qgsshadoweffect.h:94
QgsShadowEffect
Base class for paint effects which offset, blurred shadows.
Definition: qgsshadoweffect.h:36
QgsShadowEffect::setOffsetDistance
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
Definition: qgsshadoweffect.h:129
QgsPaintEffect::draw
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.