Merge pull request #291 from aws-lumberyard-dev/Atom/guthadam/ATOM-15326
ATOM-15326 support for image thumbnails in asset browser and thumbnail widget
This commit is contained in:
+5
-2
@@ -139,8 +139,11 @@ namespace AzToolsFramework
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap pixmap = thumbnail->GetPixmap(size);
|
||||
painter->drawPixmap(point, pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
// Scaling and centering pixmap within bounds to preserve aspect ratio
|
||||
const QPixmap pixmap = thumbnail->GetPixmap(size).scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
const QSize sizeDelta = size - pixmap.size();
|
||||
const QPoint pointDelta = QPoint(sizeDelta.width() / 2, sizeDelta.height() / 2);
|
||||
painter->drawPixmap(point + pointDelta, pixmap);
|
||||
}
|
||||
return m_iconSize;
|
||||
}
|
||||
|
||||
@@ -71,20 +71,12 @@ namespace AzToolsFramework
|
||||
SharedThumbnail thumbnail;
|
||||
ThumbnailerRequestsBus::BroadcastResult(thumbnail, &ThumbnailerRequests::GetThumbnail, m_key, m_contextName.c_str());
|
||||
QPainter painter(this);
|
||||
QPixmap pixmap = thumbnail->GetPixmap();
|
||||
// preserve thumbnail image's ratio, if the widget is wider than the image, center the image hotizontally
|
||||
float aspectRatio = aznumeric_cast<float>(pixmap.width()) / pixmap.height();
|
||||
int originalWidth = width();
|
||||
int originalHeight = height();
|
||||
int realHeight = qMin(aznumeric_cast<int>(originalWidth /aspectRatio), originalHeight);
|
||||
int realWidth = aznumeric_cast<int>(realHeight * aspectRatio);
|
||||
int x = (originalWidth - realWidth) / 2;
|
||||
// pixmap needs to be manually scaled to produce smoother result and avoid looking pixelated
|
||||
// using painter.setRenderHint(QPainter::SmoothPixmapTransform); does not seem to work
|
||||
// Note: there is a potential issue with pixmap.scaled:
|
||||
// it is multithreaded (using global threadPool) and blocking until finished.
|
||||
// A deadlock will happen if global threadPool has no free threads available.
|
||||
painter.drawPixmap(QPoint(x, 0), pixmap.scaled(realWidth, realHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
|
||||
// Scaling and centering pixmap within bounds to preserve aspect ratio
|
||||
const QPixmap pixmap = thumbnail->GetPixmap().scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
const QSize sizeDelta = size() - pixmap.size();
|
||||
const QPoint pointDelta = QPoint(sizeDelta.width() / 2, sizeDelta.height() / 2);
|
||||
painter.drawPixmap(pointDelta, pixmap);
|
||||
}
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user