QGIS API Documentation  3.6.0-Noosa (5873452)
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 
50  void setBlurLevel( const int level ) { mBlurLevel = level; }
51 
58  int blurLevel() const { return mBlurLevel; }
59 
66  void setOffsetAngle( const int angle ) { mOffsetAngle = angle; }
67 
74  int offsetAngle() const { return mOffsetAngle; }
75 
83  void setOffsetDistance( const double distance ) { mOffsetDist = distance; }
84 
92  double offsetDistance() const { return mOffsetDist; }
93 
101  void setOffsetUnit( const QgsUnitTypes::RenderUnit unit ) { mOffsetUnit = unit; }
102 
110  QgsUnitTypes::RenderUnit offsetUnit() const { return mOffsetUnit; }
111 
119  void setOffsetMapUnitScale( const QgsMapUnitScale &scale ) { mOffsetMapUnitScale = scale; }
120 
128  const QgsMapUnitScale &offsetMapUnitScale() const { return mOffsetMapUnitScale; }
129 
135  void setColor( const QColor &color ) { mColor = color; }
136 
142  QColor color() const { return mColor; }
143 
150  void setOpacity( const double opacity ) { mOpacity = opacity; }
151 
158  double opacity() const { return mOpacity; }
159 
166  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
167 
174  QPainter::CompositionMode blendMode() const { return mBlendMode; }
175 
176  protected:
177 
178  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
179  void draw( QgsRenderContext &context ) override;
180 
187  virtual bool exteriorShadow() const = 0;
188 
189  int mBlurLevel = 10;
190  int mOffsetAngle = 135;
191  double mOffsetDist = 2.0;
194  double mOpacity = 1.0;
195  QColor mColor;
196  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_Multiply;
197 
198 };
199 
200 
208 class CORE_EXPORT QgsDropShadowEffect : public QgsShadowEffect
209 {
210 
211  public:
212 
218  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
219 
221 
222  QString type() const override;
223  QgsDropShadowEffect *clone() const override SIP_FACTORY;
224 
225  protected:
226 
227  bool exteriorShadow() const override;
228 
229 };
230 
239 class CORE_EXPORT QgsInnerShadowEffect : public QgsShadowEffect
240 {
241 
242  public:
243 
249  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
250 
252 
253  QString type() const override;
254  QgsInnerShadowEffect *clone() const override SIP_FACTORY;
255 
256  protected:
257 
258  bool exteriorShadow() const override;
259 
260 };
261 
262 #endif // QGSSHADOWEFFECT_H
263 
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.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
void setOpacity(const double opacity)
Sets the opacity for the effect.
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.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
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.
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:69
int blurLevel() const
Returns the blur level (strength) for the shadow.
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.
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:111