Skip to content

Commit

Permalink
Use fontMetrics to scale grid markers
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 27, 2018
1 parent b5371b2 commit 790c367
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gui/qgssnaptogridcanvasitem.cpp
Expand Up @@ -37,6 +37,12 @@ void QgsSnapToGridCanvasItem::paint( QPainter *painter )
painter->setRenderHints( QPainter::Antialiasing );
painter->setCompositionMode( QPainter::CompositionMode_Difference );

double scaleFactor = painter->fontMetrics().xHeight() * .2;

mGridPen.setWidth( scaleFactor );
mCurrentPointPen.setWidth( scaleFactor * 3 );
const int gridMarkerLength = scaleFactor * 3;

try
{
const QgsRectangle layerExtent = mTransform.transformBoundingBox( mapRect, QgsCoordinateTransform::ReverseTransform );
Expand All @@ -54,16 +60,16 @@ void QgsSnapToGridCanvasItem::paint( QPainter *painter )
const QgsPointXY pt = mTransform.transform( x, y );
const QPointF canvasPt = toCanvasCoordinates( pt );

if ( qgsDoubleNear( layerPt.x(), x, mPrecision / 3 ) && qgsDoubleNear( layerPt.y(), y, mPrecision / 3 ) )
if ( qgsDoubleNear( layerPt.x(), x, mPrecision / 2 ) && qgsDoubleNear( layerPt.y(), y, mPrecision / 2 ) )
{
painter->setPen( mCurrentPointPen );
}
else
{
painter->setPen( mGridPen );
}
painter->drawLine( canvasPt.x() - 3, canvasPt.y(), canvasPt.x() + 3, canvasPt.y() );
painter->drawLine( canvasPt.x(), canvasPt.y() - 3, canvasPt.x(), canvasPt.y() + 3 );
painter->drawLine( canvasPt.x() - gridMarkerLength, canvasPt.y(), canvasPt.x() + gridMarkerLength, canvasPt.y() );
painter->drawLine( canvasPt.x(), canvasPt.y() - gridMarkerLength, canvasPt.x(), canvasPt.y() + gridMarkerLength );

}
}
Expand Down

0 comments on commit 790c367

Please sign in to comment.