QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgscoloreffect.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscoloreffect.h
3  ----------------
4  begin : March 2015
5  copyright : (C) 2015 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 QGSCOLOREFFECT_H
18 #define QGSCOLOREFFECT_H
19 
20 #include "qgis_core.h"
21 #include "qgspainteffect.h"
22 #include "qgsimageoperation.h"
23 #include "qgis_sip.h"
24 #include <QPainter>
25 
36 {
37 
38  public:
39 
45  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
46 
48 
49  QString type() const override { return QStringLiteral( "color" ); }
50  QgsStringMap properties() const override;
51  void readProperties( const QgsStringMap &props ) override;
52  QgsColorEffect *clone() const override SIP_FACTORY;
53 
61  void setBrightness( int brightness ) { mBrightness = qBound( -255, brightness, 255 ); }
62 
70  int brightness() const { return mBrightness; }
71 
79  void setContrast( int contrast ) { mContrast = qBound( -100, contrast, 100 ); }
80 
88  int contrast() const { return mContrast; }
89 
97  void setSaturation( double saturation ) { mSaturation = saturation; }
98 
106  double saturation() const { return mSaturation; }
107 
113  void setGrayscaleMode( QgsImageOperation::GrayscaleMode grayscaleMode ) { mGrayscaleMode = grayscaleMode; }
114 
120  QgsImageOperation::GrayscaleMode grayscaleMode() const { return mGrayscaleMode; }
121 
129  void setColorizeOn( bool colorizeOn ) { mColorizeOn = colorizeOn; }
130 
138  bool colorizeOn() const { return mColorizeOn; }
139 
148  void setColorizeColor( const QColor &colorizeColor );
149 
158  QColor colorizeColor() const { return mColorizeColor; }
159 
168  void setColorizeStrength( int colorizeStrength ) { mColorizeStrength = colorizeStrength; }
169 
178  int colorizeStrength() const { return mColorizeStrength; }
179 
186  void setOpacity( const double opacity ) { mOpacity = opacity; }
187 
194  double opacity() const { return mOpacity; }
195 
202  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
203 
210  QPainter::CompositionMode blendMode() const { return mBlendMode; }
211 
212  protected:
213 
214  void draw( QgsRenderContext &context ) override;
215 
216  private:
217 
218  double mOpacity = 1.0;
219  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
220  int mBrightness = 0;
221  int mContrast = 0;
222  double mSaturation = 1.0;
224  bool mColorizeOn = false;
225  QColor mColorizeColor;
226  int mColorizeStrength = 100;
227 };
228 
229 #endif // QGSBLUREFFECT_H
230 
QgsColorEffect::opacity
double opacity() const
Returns the opacity for the effect.
Definition: qgscoloreffect.h:194
QgsColorEffect::setOpacity
void setOpacity(const double opacity)
Sets the opacity for the effect.
Definition: qgscoloreffect.h:186
QgsColorEffect::brightness
int brightness() const
Returns the brightness modification for the effect.
Definition: qgscoloreffect.h:70
QgsPaintEffect::properties
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsColorEffect::colorizeColor
QColor colorizeColor() const
Returns the color used for colorizing a picture.
Definition: qgscoloreffect.h:158
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsColorEffect
A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.
Definition: qgscoloreffect.h:36
QgsImageOperation::GrayscaleOff
@ GrayscaleOff
No change.
Definition: qgsimageoperation.h:58
qgsimageoperation.h
qgspainteffect.h
QgsColorEffect::setColorizeStrength
void setColorizeStrength(int colorizeStrength)
Sets the strength for colorizing a picture.
Definition: qgscoloreffect.h:168
QgsColorEffect::setGrayscaleMode
void setGrayscaleMode(QgsImageOperation::GrayscaleMode grayscaleMode)
Sets whether the effect should convert a picture to grayscale.
Definition: qgscoloreffect.h:113
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsColorEffect::setColorizeOn
void setColorizeOn(bool colorizeOn)
Sets whether the effect should colorize a picture.
Definition: qgscoloreffect.h:129
QgsColorEffect::blendMode
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Definition: qgscoloreffect.h:210
QgsPaintEffect::clone
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
qgis_sip.h
QgsPaintEffect::readProperties
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
QgsColorEffect::setContrast
void setContrast(int contrast)
Sets the contrast modification for the effect.
Definition: qgscoloreffect.h:79
SIP_NODEFAULTCTORS
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsColorEffect::grayscaleMode
QgsImageOperation::GrayscaleMode grayscaleMode() const
Returns whether the effect will convert a picture to grayscale.
Definition: qgscoloreffect.h:120
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:54
QgsColorEffect::colorizeStrength
int colorizeStrength() const
Returns the strength used for colorizing a picture.
Definition: qgscoloreffect.h:178
QgsColorEffect::type
QString type() const override
Returns the effect type.
Definition: qgscoloreffect.h:49
QgsColorEffect::setSaturation
void setSaturation(double saturation)
Sets the saturation modification for the effect.
Definition: qgscoloreffect.h:97
QgsColorEffect::contrast
int contrast() const
Returns the contrast modification for the effect.
Definition: qgscoloreffect.h:88
QgsColorEffect::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Definition: qgscoloreffect.h:202
QgsImageOperation::GrayscaleMode
GrayscaleMode
Modes for converting a QImage to grayscale.
Definition: qgsimageoperation.h:54
QgsColorEffect::saturation
double saturation() const
Returns the saturation modification for the effect.
Definition: qgscoloreffect.h:106
QgsPaintEffect::draw
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
QgsColorEffect::colorizeOn
bool colorizeOn() const
Returns whether the effect will colorize a picture.
Definition: qgscoloreffect.h:138