Skip to content

Commit

Permalink
[layouts] Fix layout item refresh state icon drawing on high DPI screens
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 31, 2024
1 parent 381c881 commit 1e7027b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/core/layout/qgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,11 @@ void QgsLayoutItem::drawRefreshingOverlay( QPainter *painter, const QStyleOption
{
const QgsScopedQPainterState painterState( painter );
bool fitsInCache = false;
const int xSize = QFontMetrics( QFont() ).horizontalAdvance( 'X' );
const int xSize = std::floor( static_cast<double>( QFontMetrics( QFont() ).horizontalAdvance( 'X' ) ) * painter->device()->devicePixelRatioF() );
const QImage refreshingImage = QgsApplication::svgCache()->svgAsImage( QStringLiteral( ":/images/composer/refreshing_item.svg" ), xSize * 3, QColor(), QColor(), 1, 1, fitsInCache );

const double previewScaleFactor = QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle, painter );
painter->scale( 1.0 / previewScaleFactor, 1.0 / previewScaleFactor );
painter->scale( 1.0 / previewScaleFactor / painter->device()->devicePixelRatioF(), 1.0 / previewScaleFactor / painter->device()->devicePixelRatioF() );
painter->drawImage( xSize, xSize, refreshingImage );
}

Expand Down
8 changes: 1 addition & 7 deletions src/core/layout/qgslayoutitemmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,6 @@ void QgsLayoutItemMap::recreateCachedImageInBackground()
{
devicePixelRatio = ( activeWindow->screen() ? QApplication::activeWindow()->screen()->devicePixelRatio() : 1.0 );
}

mCacheRenderingImage.reset( new QImage( w * devicePixelRatio, h * devicePixelRatio, QImage::Format_ARGB32 ) );

// set DPI of the image
Expand Down Expand Up @@ -1678,12 +1677,7 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF
if ( layout()->renderContext().isPreviewRender() )
{
jobMapSettings.setDpiTarget( layout()->renderContext().dpi() );
double devicePixelRatio = 1.0;
if ( QWidget *activeWindow = QApplication::activeWindow() )
{
devicePixelRatio = ( activeWindow->screen() ? QApplication::activeWindow()->screen()->devicePixelRatio() : 1.0 );
}
jobMapSettings.setDevicePixelRatio( devicePixelRatio );
jobMapSettings.setDevicePixelRatio( mPainter ? mPainter->device()->devicePixelRatioF() : 1.0 );
}
jobMapSettings.setBackgroundColor( Qt::transparent );
jobMapSettings.setRotation( mEvaluatedMapRotation );
Expand Down

0 comments on commit 1e7027b

Please sign in to comment.