87 void QgsHighlight::init()
106 setColor( QColor( Qt::lightGray ) );
119 mPen.setColor( color );
120 QColor fillColor( color.red(), color.green(), color.blue(), 63 );
121 mBrush.setColor( fillColor );
122 mBrush.setStyle( Qt::SolidPattern );
127 mBrush.setColor( fillColor );
128 mBrush.setStyle( Qt::SolidPattern );
143 if ( !symbol )
continue;
144 setSymbol( symbol, context, color, fillColor );
150 void QgsHighlight::setSymbol(
QgsSymbolV2* symbol,
const QgsRenderContext & context,
const QColor & color,
const QColor & fillColor )
152 if ( !symbol )
return;
158 if ( !symbolLayer )
continue;
162 setSymbol( symbolLayer->
subSymbol(), context, color, fillColor );
200 width = qMax( width + 2 * mBuffer * scale, mMinWidth * scale );
209 mPen.setWidth( width );
212 void QgsHighlight::paintPoint( QPainter *p,
QgsPoint point )
226 void QgsHighlight::paintLine( QPainter *p,
QgsPolyline line )
228 QPolygonF polygon( line.size() );
230 for (
int i = 0; i < line.size(); i++ )
235 p->drawPolyline( polygon );
238 void QgsHighlight::paintPolygon( QPainter *p,
QgsPolygon polygon )
244 p->setBrush( mBrush );
246 for (
int i = 0; i < polygon.size(); i++ )
248 if ( polygon[i].empty() )
continue;
251 ring.reserve( polygon[i].
size() + 1 );
253 for (
int j = 0; j < polygon[i].size(); j++ )
257 if ( 0 == j || std::abs( ring.back().x() - cur.x() ) > 1 || std::abs( ring.back().y() - cur.y() ) > 1 )
259 ring.push_back( cur );
263 ring.push_back( ring[ 0 ] );
265 path.addPolygon( ring );
284 p->setBrush( mBrush );
286 switch ( mGeometry->
wkbType() )
291 paintPoint( p, mGeometry->
asPoint() );
299 for (
int i = 0; i < m.size(); i++ )
301 paintPoint( p, m[i] );
318 for (
int i = 0; i < m.size(); i++ )
320 paintLine( p, m[i] );
328 paintPolygon( p, mGeometry->
asPolygon() );
336 for (
int i = 0; i < m.size(); i++ )
338 paintPolygon( p, m[i] );
359 QColor tmpColor( 255, 0, 0, 255 );
360 QColor tmpFillColor( 0, 255, 0, 255 );
363 if ( layer && renderer )
367 QImage image = QImage( imageSize.width(), imageSize.height(), QImage::Format_ARGB32 );
369 QPainter *imagePainter =
new QPainter( &image );
370 imagePainter->setRenderHint( QPainter::Antialiasing,
true );
380 QColor color( mPen.color() );
382 double k = ( 255. - mBrush.color().alpha() ) / 255.;
383 for (
int r = 0; r < image.height(); r++ )
385 for (
int c = 0; c < image.width(); c++ )
387 QRgb rgba = image.pixel( c, r );
388 int alpha = qAlpha( rgba );
391 int green = qGreen( rgba );
392 color.setAlpha( qBound<int>( 0, alpha - ( green * k ), 255 ) );
394 image.setPixel( c, r, color.rgba() );
399 p->drawImage( 0, 0, image );
423 setVisible( mGeometry );
438 QgsRectangle rect( topLeft.
x(), topLeft.
y(), topLeft.
x() + imageSize.width()*res, topLeft.
y() - imageSize.height()*res );