diff --git a/libkcardgame/kabstractcarddeck.cpp b/libkcardgame/kabstractcarddeck.cpp --- a/libkcardgame/kabstractcarddeck.cpp +++ b/libkcardgame/kabstractcarddeck.cpp @@ -75,19 +75,20 @@ d->renderer(); } + const auto size = m_size * qApp->devicePixelRatio(); foreach ( const QString & element, m_elementsToRender ) { { QMutexLocker l( &m_haltMutex ); if ( m_haltFlag ) return; } - QString key = keyForPixmap( element, m_size ); + QString key = keyForPixmap( element, size ); if ( !d->cache->contains( key ) ) { //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in rendering thread."; - QImage img = d->renderCard( element, m_size ); + QImage img = d->renderCard( element, size ); d->cache->insertImage( key, img ); emit renderingDone( element, img ); } @@ -197,24 +198,27 @@ return QPixmap(); QPixmap & stored = it.value().cardPixmap; - if ( stored.size() != currentCardSize ) + const auto dpr = qApp->devicePixelRatio(); + QSize requestedCardSize = currentCardSize * dpr; + if ( stored.size() != requestedCardSize ) { - QString key = keyForPixmap( elementId , currentCardSize ); + QString key = keyForPixmap( elementId , requestedCardSize ); if ( !cache->findPixmap( key, &stored ) ) { if ( stored.isNull() ) { //qCDebug(LIBKCARDGAME_LOG) << "Renderering" << key << "in main thread."; - QImage img = renderCard( elementId, currentCardSize ); + QImage img = renderCard( elementId, requestedCardSize ); cache->insertImage( key, img ); stored = QPixmap::fromImage( img ); } else { - stored = stored.scaled( currentCardSize ); + stored = stored.scaled( requestedCardSize ); } } - Q_ASSERT( stored.size() == currentCardSize ); + Q_ASSERT( stored.size() == requestedCardSize ); + stored.setDevicePixelRatio( dpr ); } return stored; } @@ -235,16 +239,19 @@ // If the currentCardSize has changed since the rendering was performed, // we sadly just have to throw it away. - if ( image.size() != currentCardSize ) + const auto dpr = qApp->devicePixelRatio(); + if ( image.size() != currentCardSize * dpr) return; // The RenderingThread just put the image in the cache, but due to the // volatility of the cache there's no guarantee that it'll still be there // by the time this slot is called, in which case we convert the QImage // passed in the signal. - if ( !cache->findPixmap( keyForPixmap( elementId, currentCardSize ), &pix ) ) + if ( !cache->findPixmap( keyForPixmap( elementId, currentCardSize * dpr ), &pix ) ) pix = QPixmap::fromImage( image ); + pix.setDevicePixelRatio( dpr ); + QHash::iterator it; it = frontIndex.find( elementId ); if ( it != frontIndex.end() ) diff --git a/libkcardgame/kcard.cpp b/libkcardgame/kcard.cpp --- a/libkcardgame/kcard.cpp +++ b/libkcardgame/kcard.cpp @@ -312,7 +312,7 @@ Q_UNUSED( option ); Q_UNUSED( widget ); - if ( pixmap().size() != d->deck->cardSize() ) + if ( pixmap().size() != d->deck->cardSize() * pixmap().devicePixelRatio() ) { QPixmap newPix = d->deck->cardPixmap( d->id, d->faceUp ); if ( d->faceUp ) diff --git a/libkcardgame/kcardthemewidget.cpp b/libkcardgame/kcardthemewidget.cpp --- a/libkcardgame/kcardthemewidget.cpp +++ b/libkcardgame/kcardthemewidget.cpp @@ -81,7 +81,8 @@ return; } - QImage img( d->previewSize, QImage::Format_ARGB32 ); + const auto dpr = qApp->devicePixelRatio(); + QImage img( d->previewSize * dpr, QImage::Format_ARGB32 ); img.fill( Qt::transparent ); QPainter p( &img ); @@ -100,7 +101,7 @@ { foreach ( const QString & card, pile ) { - renderer.render( &p, card, QRectF( QPointF( xPos, yPos ), size ) ); + renderer.render( &p, card, QRectF( QPointF( xPos, yPos ) * dpr, size * dpr ) ); xPos += 0.3 * spacingWidth; } xPos += 1 * size.width() + ( 0.1 - 0.3 ) * spacingWidth; @@ -147,6 +148,7 @@ m_previews.clear(); QList previewsNeeded; + const auto dpr = qApp->devicePixelRatio(); foreach( const KCardTheme & theme, KCardTheme::findAllWithFeatures( d->requiredFeatures ) ) { @@ -157,8 +159,10 @@ QDateTime timestamp; if ( cacheFind( d->cache, timestampKey( theme ), ×tamp ) && timestamp >= theme.lastModified() - && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) ) + && d->cache->findPixmap( previewKey( theme, d->previewString ), pix ) + && pix->size() == d->previewSize * dpr ) { + pix->setDevicePixelRatio( dpr ); m_previews.insert( theme.displayName(), pix ); } else @@ -199,6 +203,7 @@ cacheInsert( d->cache, timestampKey( theme ), theme.lastModified() ); QPixmap * pix = new QPixmap( QPixmap::fromImage( image ) ); + pix->setDevicePixelRatio( qApp->devicePixelRatio() ); delete m_previews.value( theme.displayName(), 0 ); m_previews.insert( theme.displayName(), pix ); diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -101,6 +101,8 @@ int main( int argc, char **argv ) { + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); + QApplication app(argc, argv); KLocalizedString::setApplicationDomain("kpat");