Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix pixelated ratio lock button
  • Loading branch information
nyalldawson committed May 15, 2023
1 parent 73a2a0f commit a7e947e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/gui/qgsratiolockbutton.cpp
Expand Up @@ -14,6 +14,8 @@
***************************************************************************/

#include "qgsratiolockbutton.h"
#include "qgsapplication.h"
#include "qgssvgcache.h"
#include "qgis.h"

#include <QApplication>
Expand Down Expand Up @@ -117,24 +119,36 @@ void QgsRatioLockButton::drawButton()
return;
}

QPixmap pm;
pm = QPixmap( currentIconSize );
const double pixelRatio = devicePixelRatioF();
QPixmap pm( currentIconSize * pixelRatio );
pm.setDevicePixelRatio( pixelRatio );
pm.fill( Qt::transparent );

QPainter painter;
QPen pen = ( QColor( 136, 136, 136 ) );
QPen pen = QPen( QColor( 136, 136, 136 ) );
pen.setWidth( 2 );

painter.begin( &pm );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( pen );

painter.drawLine( 1, 1, currentIconSize.width() / 2, 1 );
painter.drawLine( currentIconSize.width() / 2, 1, currentIconSize.width() / 2, currentIconSize.height() / 2 - 13 );
painter.drawLine( currentIconSize.width() / 2, currentIconSize.height() / 2 + 13, currentIconSize.width() / 2, currentIconSize.height() - 2 );
painter.drawLine( currentIconSize.width() / 2, currentIconSize.height() - 2, 1, currentIconSize.height() - 2 );

const QImage image( mLocked ? QStringLiteral( ":/images/themes/default/lockedGray.svg" ) : QStringLiteral( ":/images/themes/default/unlockedGray.svg" ) );
painter.drawImage( QRectF( currentIconSize.width() / 2 - 8, currentIconSize.height() / 2 - 8, 16, 16 ), image, QRectF( 0, 0, 16, 16 ) );
painter.drawLine( QPointF( 1, 1 ), QPointF( currentIconSize.width() / 2, 1 ) );
painter.drawLine( QPointF( currentIconSize.width() / 2, 1 ), QPointF( currentIconSize.width() / 2, currentIconSize.height() / 2 - 13 ) );
painter.drawLine( QPointF( currentIconSize.width() / 2, currentIconSize.height() / 2 + 13 ), QPointF( currentIconSize.width() / 2, currentIconSize.height() - 2 ) );
painter.drawLine( QPointF( currentIconSize.width() / 2, currentIconSize.height() - 2 ), QPointF( 1, currentIconSize.height() - 2 ) );

const QString imageSource = mLocked ? QStringLiteral( ":/images/themes/default/lockedGray.svg" ) : QStringLiteral( ":/images/themes/default/unlockedGray.svg" );
bool fitsInCache = false;
QImage image = QgsApplication::svgCache()->svgAsImage(
imageSource, 16 * pixelRatio, QColor(), QColor(), 0, 1, fitsInCache
);
image.setDevicePixelRatio( pixelRatio );
painter.drawImage( QRectF(
currentIconSize.width() / 2 - 8,
currentIconSize.height() / 2 - 8,
16,
16 ),
image );

painter.end();

Expand Down

0 comments on commit a7e947e

Please sign in to comment.