@@ -131,7 +131,7 @@ void QgsHighlight::setFillColor( const QColor & fillColor )
131
131
mBrush .setStyle ( Qt::SolidPattern );
132
132
}
133
133
134
- QgsFeatureRendererV2 * QgsHighlight::getRenderer ( const QgsRenderContext & context )
134
+ QgsFeatureRendererV2 * QgsHighlight::getRenderer ( const QgsRenderContext & context, const QColor & color, const QColor & fillColor )
135
135
{
136
136
QgsFeatureRendererV2 *renderer = 0 ;
137
137
QgsVectorLayer *layer = vectorLayer ();
@@ -144,30 +144,16 @@ QgsFeatureRendererV2 * QgsHighlight::getRenderer( const QgsRenderContext & conte
144
144
foreach ( QgsSymbolV2* symbol, renderer->symbols () )
145
145
{
146
146
if ( !symbol ) continue ;
147
- setSymbol ( symbol, context, mPen . color () );
147
+ setSymbol ( symbol, context, color, fillColor );
148
148
}
149
149
}
150
150
return renderer;
151
151
}
152
152
153
- void QgsHighlight::setSymbol ( QgsSymbolV2* symbol, const QgsRenderContext & context, const QColor & color )
153
+ void QgsHighlight::setSymbol ( QgsSymbolV2* symbol, const QgsRenderContext & context, const QColor & color, const QColor & fillColor )
154
154
{
155
155
if ( !symbol ) return ;
156
156
157
- // Temporary fill color must be similar to outline color (antialiasing between
158
- // outline and temporary fill) but also different enough to be distinguishable
159
- // so that it can be replaced by transparent fill.
160
- // Unfortunately the result of the transparent fill rendered over the original
161
- // (not highlighted) feature color may be either lighter or darker.
162
- if ( color.lightness () < 200 )
163
- {
164
- mTemporaryFillColor = color.lighter ( 120 );
165
- }
166
- else
167
- {
168
- mTemporaryFillColor = color.darker ( 120 );
169
- }
170
- mTemporaryFillColor .setAlpha ( 255 );
171
157
172
158
for ( int i = symbol->symbolLayerCount () - 1 ; i >= 0 ; i-- )
173
159
{
@@ -176,13 +162,13 @@ void QgsHighlight::setSymbol( QgsSymbolV2* symbol, const QgsRenderContext & cont
176
162
177
163
if ( symbolLayer->subSymbol () )
178
164
{
179
- setSymbol ( symbolLayer->subSymbol (), context, color );
165
+ setSymbol ( symbolLayer->subSymbol (), context, color, fillColor );
180
166
}
181
167
else
182
168
{
183
169
symbolLayer->setColor ( color ); // line symbology layers
184
170
symbolLayer->setOutlineColor ( color ); // marker and fill symbology layers
185
- symbolLayer->setFillColor ( mTemporaryFillColor ); // marker and fill symbology layers
171
+ symbolLayer->setFillColor ( fillColor ); // marker and fill symbology layers
186
172
187
173
// Data defined widths overwrite what we set here (widths do not work with data defined)
188
174
QgsSimpleMarkerSymbolLayerV2 * simpleMarker = dynamic_cast <QgsSimpleMarkerSymbolLayerV2*>( symbolLayer );
@@ -214,9 +200,8 @@ double QgsHighlight::getSymbolWidth( const QgsRenderContext & context, double wi
214
200
{
215
201
scale = QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context, QgsSymbolV2::MM ) / QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context, QgsSymbolV2::MapUnit );
216
202
}
217
- return qMax ( width + 2 *mBuffer *scale, mMinWidth *scale );
218
-
219
-
203
+ width = qMax ( width + 2 * mBuffer * scale, mMinWidth * scale );
204
+ return width;
220
205
}
221
206
222
207
/* !
@@ -364,7 +349,13 @@ void QgsHighlight::paint( QPainter* p )
364
349
QgsMapSettings mapSettings = mMapCanvas ->mapSettings ();
365
350
QgsRenderContext context = QgsRenderContext::fromMapSettings ( mapSettings );
366
351
367
- QgsFeatureRendererV2 *renderer = getRenderer ( context );
352
+ // Because lower level outlines must be covered by upper level fill color
353
+ // we render first with temporary opaque color, which is then replaced
354
+ // by final transparent fill color.
355
+ QColor tmpColor ( 255 , 0 , 0 , 255 );
356
+ QColor tmpFillColor ( 0 , 255 , 0 , 255 );
357
+
358
+ QgsFeatureRendererV2 *renderer = getRenderer ( context, tmpColor, tmpFillColor );
368
359
if ( layer && renderer )
369
360
{
370
361
QgsRectangle extent = mMapCanvas ->extent ();
@@ -374,10 +365,6 @@ void QgsHighlight::paint( QPainter* p )
374
365
return ; // it will be repainted after updateRect()
375
366
}
376
367
377
- // Because lower level outlines must be covered by upper level fill color
378
- // we render first with temporary opaque color, which is then replaced
379
- // by final transparent fill color.
380
- // QImage image = QImage(( int )width, ( int )height, QImage::Format_ARGB32 );
381
368
QSize imageSize ( mMapCanvas ->mapSettings ().outputSize () );
382
369
QImage image = QImage ( imageSize.width (), imageSize.height (), QImage::Format_ARGB32 );
383
370
image.fill ( 0 );
@@ -392,20 +379,21 @@ void QgsHighlight::paint( QPainter* p )
392
379
393
380
imagePainter->end ();
394
381
395
- // overwrite temporary fill color
396
- QRgb temporaryRgb = mTemporaryFillColor .rgba ();
397
- QColor color = QColor ( mBrush .color () );
398
- color.setAlpha ( 63 );
399
- QRgb colorRgb = color.rgba ();
400
-
382
+ QColor color ( mPen .color () ); // true output color
383
+ // coeficient to subtract alpha using green (temporary fill)
384
+ double k = ( 255 . - mBrush .color ().alpha () ) / 255 .;
401
385
for ( int r = 0 ; r < image.height (); r++ )
402
386
{
403
- QRgb *line = ( QRgb * ) image.scanLine ( r );
404
387
for ( int c = 0 ; c < image.width (); c++ )
405
388
{
406
- if ( line[c] == temporaryRgb )
389
+ QRgb rgba = image.pixel ( c, r );
390
+ int alpha = qAlpha ( rgba );
391
+ if ( alpha > 0 )
407
392
{
408
- line[c] = colorRgb;
393
+ int green = qGreen ( rgba );
394
+ color.setAlpha ( alpha - ( green * k ) );
395
+
396
+ image.setPixel ( c, r, color.rgba () );
409
397
}
410
398
}
411
399
}
0 commit comments