1 /*************************************************************************** 2 qgstextshadowsettings.h 3 ----------------- 4 begin : May 2020 5 copyright : (C) Nyall Dawson 6 email : nyall dot dawson at gmail dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 #ifndef QGSTEXTSHADOWSETTINGS_H 17 #define QGSTEXTSHADOWSETTINGS_H 18 19 #include "qgsunittypes.h" 20 #include "qgsmapunitscale.h" 21 22 #include <QSharedDataPointer> 23 #include <QPainter> 24 #include <QDomElement> 25 26 class QgsTextShadowSettingsPrivate; 27 class QgsVectorLayer; 28 class QgsPropertyCollection; 29 30 /** 31 * \class QgsTextShadowSettings 32 * \ingroup core 33 * \brief Container for settings relating to a text shadow. 34 * \note QgsTextShadowSettings objects are implicitly shared. 35 * \since QGIS 3.0 36 */ 37 class CORE_EXPORT QgsTextShadowSettings 38 { 39 public: 40 41 /** 42 * Placement positions for text shadow. 43 */ 44 enum ShadowPlacement 45 { 46 ShadowLowest = 0, //!< Draw shadow below all text components 47 ShadowText, //!< Draw shadow under text 48 ShadowBuffer, //!< Draw shadow under buffer 49 ShadowShape //!< Draw shadow under background shape 50 }; 51 52 QgsTextShadowSettings(); 53 54 /** 55 * Copy constructor. 56 * \param other source QgsTextShadowSettings 57 */ 58 QgsTextShadowSettings( const QgsTextShadowSettings &other ); 59 60 QgsTextShadowSettings &operator=( const QgsTextShadowSettings &other ); 61 62 ~QgsTextShadowSettings(); 63 64 bool operator==( const QgsTextShadowSettings &other ) const; 65 bool operator!=( const QgsTextShadowSettings &other ) const; 66 67 /** 68 * Returns whether the shadow is enabled. 69 * \see setEnabled() 70 */ 71 bool enabled() const; 72 73 /** 74 * Sets whether the text shadow will be drawn. 75 * \param enabled set to TRUE to draw shadow 76 * \see enabled() 77 */ 78 void setEnabled( bool enabled ); 79 80 /** 81 * Returns the placement for the drop shadow. The placement determines 82 * both the z-order stacking position for the shadow and the what shape (e.g., text, 83 * background shape) is used for casting the shadow. 84 * \see setShadowPlacement() 85 */ 86 QgsTextShadowSettings::ShadowPlacement shadowPlacement() const; 87 88 /** 89 * Sets the placement for the drop shadow. The placement determines 90 * both the z-order stacking position for the shadow and the what shape (e.g., text, 91 * background shape) is used for casting the shadow. 92 * \param placement shadow placement 93 * \see shadowPlacement() 94 */ 95 void setShadowPlacement( QgsTextShadowSettings::ShadowPlacement placement ); 96 97 /** 98 * Returns the angle for offsetting the position of the shadow from the text. 99 * \see setOffsetAngle 100 * \see offsetDistance() 101 */ 102 int offsetAngle() const; 103 104 /** 105 * Sets the angle for offsetting the position of the shadow from the text. 106 * \param angle offset angle in degrees 107 * \see offsetAngle() 108 * \see setOffsetDistance() 109 */ 110 void setOffsetAngle( int angle ); 111 112 /** 113 * Returns the distance for offsetting the position of the shadow from the text. Offset units 114 * are retrieved via offsetUnit(). 115 * \see setOffsetDistance() 116 * \see offsetUnit() 117 */ 118 double offsetDistance() const; 119 120 /** 121 * Sets the distance for offsetting the position of the shadow from the text. Offset units 122 * are specified via setOffsetUnit(). 123 * \param distance offset distance 124 * \see offsetDistance() 125 * \see setOffsetUnit() 126 */ 127 void setOffsetDistance( double distance ); 128 129 /** 130 * Returns the units used for the shadow's offset. 131 * \see setOffsetUnit() 132 * \see offsetDistance() 133 */ 134 QgsUnitTypes::RenderUnit offsetUnit() const; 135 136 /** 137 * Sets the units used for the shadow's offset. 138 * \param units shadow distance units 139 * \see offsetUnit() 140 * \see setOffsetDistance() 141 */ 142 void setOffsetUnit( QgsUnitTypes::RenderUnit units ); 143 144 /** 145 * Returns the map unit scale object for the shadow offset distance. This is only used if the 146 * offsetUnit() is set to QgsUnitTypes::RenderMapUnit. 147 * \see setOffsetMapUnitScale() 148 * \see offsetUnit() 149 */ 150 QgsMapUnitScale offsetMapUnitScale() const; 151 152 /** 153 * Sets the map unit scale object for the shadow offset distance. This is only used if the 154 * offsetUnit() is set to QgsUnitTypes::RenderMapUnit. 155 * \param scale scale for shadow offset 156 * \see offsetMapUnitScale() 157 * \see setOffsetUnit() 158 */ 159 void setOffsetMapUnitScale( const QgsMapUnitScale &scale ); 160 161 /** 162 * Returns TRUE if the global shadow offset will be used. 163 * \see setOffsetGlobal() 164 */ 165 bool offsetGlobal() const; 166 167 /** 168 * Sets whether the global shadow offset should be used. 169 * \param global set to TRUE to use global shadow offset. 170 */ 171 void setOffsetGlobal( bool global ); 172 173 /** 174 * Returns the blur radius for the shadow. Radius units are retrieved via blurRadiusUnits(). 175 * \see setBlurRadius() 176 * \see blurRadiusUnit() 177 */ 178 double blurRadius() const; 179 180 /** 181 * Sets the blur radius for the shadow. Radius units are specified via setBlurRadiusUnits(). 182 * \param blurRadius blur radius 183 * \see blurRadius() 184 * \see setBlurRadiusUnit() 185 */ 186 void setBlurRadius( double blurRadius ); 187 188 /** 189 * Returns the units used for the shadow's blur radius. 190 * \see setBlurRadiusUnit() 191 * \see blurRadius() 192 */ 193 QgsUnitTypes::RenderUnit blurRadiusUnit() const; 194 195 /** 196 * Sets the units used for the shadow's blur radius. 197 * \param units shadow blur radius units 198 * \see blurRadiusUnit() 199 * \see setBlurRadius() 200 */ 201 void setBlurRadiusUnit( QgsUnitTypes::RenderUnit units ); 202 203 /** 204 * Returns the map unit scale object for the shadow blur radius. This is only used if the 205 * blurRadiusUnit() is set to QgsUnitTypes::RenderMapUnit. 206 * \see setBlurRadiusMapUnitScale() 207 * \see blurRadiusUnit() 208 */ 209 QgsMapUnitScale blurRadiusMapUnitScale() const; 210 211 /** 212 * Sets the map unit scale object for the shadow blur radius. This is only used if the 213 * blurRadiusUnit() is set to QgsUnitTypes::RenderMapUnit. 214 * \param scale scale for shadow blur radius 215 * \see blurRadiusMapUnitScale() 216 * \see setBlurRadiusUnit() 217 */ 218 void setBlurRadiusMapUnitScale( const QgsMapUnitScale &scale ); 219 220 /** 221 * Returns whether only the alpha channel for the shadow will be blurred. 222 * \see setBlurAlphaOnly() 223 */ 224 bool blurAlphaOnly() const; 225 226 /** 227 * Sets whether only the alpha channel for the shadow should be blurred. 228 * \param alphaOnly set to TRUE to blur only the alpha channel. If FALSE, all channels (including 229 * red, green and blue channel) will be blurred. 230 * \see blurAlphaOnly() 231 */ 232 void setBlurAlphaOnly( bool alphaOnly ); 233 234 /** 235 * Returns the shadow's opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally 236 * opaque). 237 * \see setOpacity() 238 */ 239 double opacity() const; 240 241 /** 242 * Sets the shadow's opacity. 243 * \param opacity opacity as a double value between 0 (fully transparent) and 1 (totally 244 * opaque) 245 * \see opacity() 246 */ 247 void setOpacity( double opacity ); 248 249 /** 250 * Returns the scaling used for the drop shadow (in percentage of original size). 251 * \see setScale() 252 */ 253 int scale() const; 254 255 /** 256 * Sets the scaling used for the drop shadow (in percentage of original size). 257 * \param scale scale percent for drop shadow 258 * \see scale() 259 */ 260 void setScale( int scale ); 261 262 /** 263 * Returns the color of the drop shadow. 264 * \see setColor() 265 */ 266 QColor color() const; 267 268 /** 269 * Sets the color for the drop shadow. 270 * \param color shadow color 271 * \see color() 272 */ 273 void setColor( const QColor &color ); 274 275 /** 276 * Returns the blending mode used for drawing the drop shadow. 277 * \see setBlendMode() 278 */ 279 QPainter::CompositionMode blendMode() const; 280 281 /** 282 * Sets the blending mode used for drawing the drop shadow. 283 * \param mode blending mode 284 * \see blendMode() 285 */ 286 void setBlendMode( QPainter::CompositionMode mode ); 287 288 /** 289 * Reads settings from a layer's custom properties (for QGIS 2.x projects). 290 * \param layer source vector layer 291 */ 292 void readFromLayer( QgsVectorLayer *layer ); 293 294 /** 295 * Read settings from a DOM element. 296 * \see writeXml() 297 */ 298 void readXml( const QDomElement &elem ); 299 300 /** 301 * Write settings into a DOM element. 302 * \see readXml() 303 */ 304 QDomElement writeXml( QDomDocument &doc ) const; 305 306 /** 307 * Updates the format by evaluating current values of data defined properties. 308 * \since QGIS 3.10 309 */ 310 void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties ); 311 312 /** 313 * Returns all field names referenced by the configuration (e.g. from data defined properties). 314 * \since QGIS 3.14 315 */ 316 QSet<QString> referencedFields( const QgsRenderContext &context ) const; 317 318 private: 319 320 QSharedDataPointer<QgsTextShadowSettingsPrivate> d; 321 322 }; 323 324 #endif // QGSTEXTSHADOWSETTINGS_H 325