Fix gradient fills using color ramps not respecting symbol transparency

This commit is contained in:
Nyall Dawson 2014-03-21 19:47:00 +11:00
parent 6685932c09
commit a0c2c7aaad
4 changed files with 19 additions and 7 deletions

View File

@ -83,7 +83,7 @@ class QgsVectorGradientColorRampV2 : QgsVectorColorRampV2
/**copy color ramp stops to a QGradient
* @note added in 2.1 */
void addStopsToGradient( QGradient* gradient );
void addStopsToGradient( QGradient* gradient, double alpha = 1 );
};
class QgsVectorRandomColorRampV2 : QgsVectorColorRampV2

View File

@ -678,7 +678,7 @@ void QgsGradientFillSymbolLayerV2::applyGradient( const QgsSymbolV2RenderContext
{
//color ramp gradient
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( gradientRamp );
gradRamp->addStopsToGradient( &gradient );
gradRamp->addStopsToGradient( &gradient, context.alpha() );
}
else
{

View File

@ -219,16 +219,28 @@ void QgsVectorGradientColorRampV2::convertToDiscrete( bool discrete )
mDiscrete = discrete;
}
void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient )
void QgsVectorGradientColorRampV2::addStopsToGradient( QGradient* gradient, double alpha )
{
//copy color ramp stops to a QGradient
gradient->setColorAt( 0, mColor1 );
gradient->setColorAt( 1, mColor2 );
QColor color1 = mColor1;
QColor color2 = mColor2;
if ( alpha < 1 )
{
color1.setAlpha( color1.alpha() * alpha );
color2.setAlpha( color2.alpha() * alpha );
}
gradient->setColorAt( 0, color1 );
gradient->setColorAt( 1, color2 );
for ( QgsGradientStopsList::const_iterator it = mStops.begin();
it != mStops.end(); ++it )
{
gradient->setColorAt( it->offset , it->color );
QColor rampColor = it->color;
if ( alpha < 1 )
{
rampColor.setAlpha( rampColor.alpha() * alpha );
}
gradient->setColorAt( it->offset , rampColor );
}
}

View File

@ -94,7 +94,7 @@ class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2
/**copy color ramp stops to a QGradient
* @note added in 2.1 */
void addStopsToGradient( QGradient* gradient );
void addStopsToGradient( QGradient* gradient, double alpha = 1 );
protected:
QColor mColor1, mColor2;