@@ -68,6 +68,10 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
6868 mBrush = QBrush ( mColor );
6969 mPen = QPen ( mBorderColor );
7070 mPen .setWidthF ( context.outputLineWidth ( mPen .widthF () ) );
71+ QColor selColor = context.selectionColor ();
72+ mSelBrush = QBrush ( selColor );
73+ mSelPen = QPen ( selColor == mColor ? selColor : mBorderColor );
74+ mSelPen .setWidthF ( mPen .widthF () );
7175
7276 mPolygon .clear ();
7377
@@ -148,6 +152,9 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
148152 else
149153 {
150154 // some markers can't be drawn as a polygon (circle, cross)
155+ // For these set the selected border color to the selected color
156+
157+ if ( mName != " circle" ) mSelPen .setColor ( selColor );
151158 }
152159
153160 // rotate if needed
@@ -176,10 +183,40 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
176183 drawMarker ( &p, context );
177184 p.end ();
178185
186+ // Construct the selected version of the Cache
187+
188+ mSelCache = QImage ( QSize ( imageSize, imageSize ), QImage::Format_ARGB32_Premultiplied );
189+ mSelCache .fill ( 0 );
190+
191+ p.begin ( &mSelCache );
192+ p.setRenderHint ( QPainter::Antialiasing );
193+ p.setBrush ( mSelBrush );
194+ p.setPen ( mSelPen );
195+ p.translate ( QPointF ( center, center ) );
196+ drawMarker ( &p, context );
197+ p.end ();
198+
199+ // Check that the selected version is different. If not, then re-render,
200+ // filling the background with the selection colour and using the normal
201+ // colours for the symbol .. could be ugly!
202+
203+ if ( mSelCache == mCache )
204+ {
205+ p.begin ( &mSelCache );
206+ p.setRenderHint ( QPainter::Antialiasing );
207+ p.fillRect ( 0 , 0 , imageSize, imageSize, selColor );
208+ p.setBrush ( mBrush );
209+ p.setPen ( mPen );
210+ p.translate ( QPointF ( center, center ) );
211+ drawMarker ( &p, context );
212+ p.end ();
213+ }
214+
179215 // opacity
180216 if ( context.alpha () < 1.0 )
181217 {
182218 QgsSymbolLayerV2Utils::multiplyImageOpacity ( &mCache , context.alpha () );
219+ if ( ! selectionIsOpaque ) QgsSymbolLayerV2Utils::multiplyImageOpacity ( &mSelCache , context.alpha () );
183220 }
184221}
185222
@@ -203,11 +240,12 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
203240 // p->translate(point);
204241
205242 // drawMarker(p);
206- // mCache.save("/home/marco/tmp/marker.png", "PNG");
207- double s = mCache .width () / context.renderContext ().rasterScaleFactor ();
243+ // mCache.save("/home/marco/tmp/marker.png","PNG");
244+ QImage &img = context.selected () ? mSelCache : mCache ;
245+ double s = img.width () / context.renderContext ().rasterScaleFactor ();
208246 p->drawImage ( QRectF ( point.x () - s / 2.0 + context.outputLineWidth ( mOffset .x () ),
209247 point.y () - s / 2.0 + context.outputLineWidth ( mOffset .y () ),
210- s, s ), mCache );
248+ s, s ), img );
211249 // p->restore();
212250}
213251
@@ -328,6 +366,13 @@ void QgsSvgMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
328366 QSvgRenderer renderer ( mPath );
329367 QPainter painter ( &mPicture );
330368 renderer.render ( &painter, rect );
369+ double selPictureSize = pictureSize * 1.2 ;
370+ QPainter selPainter ( &mSelPicture );
371+ selPainter.setRenderHint ( QPainter::Antialiasing );
372+ selPainter.setBrush ( QBrush ( context.selectionColor () ) );
373+ selPainter.setPen ( Qt::NoPen );
374+ selPainter.drawEllipse ( QPointF ( 0 , 0 ), pictureSize*0.6 , pictureSize*0.6 );
375+ renderer.render ( &selPainter, rect );
331376}
332377
333378void QgsSvgMarkerSymbolLayerV2::stopRender ( QgsSymbolV2RenderContext& context )
@@ -350,7 +395,8 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
350395 if ( mAngle != 0 )
351396 p->rotate ( mAngle );
352397
353- p->drawPicture ( 0 , 0 , mPicture );
398+ QPicture &pct = context.selected () ? mSelPicture : mPicture ;
399+ p->drawPicture ( 0 , 0 , pct );
354400
355401 if ( mAngle != 0 )
356402 p->rotate ( -mAngle );
@@ -515,7 +561,7 @@ QString QgsFontMarkerSymbolLayerV2::layerType() const
515561
516562void QgsFontMarkerSymbolLayerV2::startRender ( QgsSymbolV2RenderContext& context )
517563{
518- mFont = QFont ( mFontFamily , MM2POINT ( mSize ) );
564+ mFont = QFont ( mFontFamily , MM2POINT ( mSize ) / context. renderContext (). rasterScaleFactor () );
519565 QFontMetrics fm ( mFont );
520566 mChrOffset = QPointF ( fm.width ( mChr ) / 2 , -fm.ascent () / 2 );
521567
@@ -529,7 +575,7 @@ void QgsFontMarkerSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
529575void QgsFontMarkerSymbolLayerV2::renderPoint ( const QPointF& point, QgsSymbolV2RenderContext& context )
530576{
531577 QPainter* p = context.renderContext ().painter ();
532- QColor penColor = mColor ;
578+ QColor penColor = context. selected () ? context. selectionColor () : mColor ;
533579 penColor.setAlphaF ( context.alpha () );
534580 p->setPen ( penColor );
535581 p->setFont ( mFont );
0 commit comments