Replacing preset preview images with thumbnail widget to improve load times

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2021-11-07 15:17:11 -06:00
parent 9f9aa8f2a6
commit 5311878e87
7 changed files with 29 additions and 100 deletions
@@ -7,6 +7,7 @@
*/
#include <Atom/Feature/Utils/LightingPreset.h>
#include <Atom/RPI.Edit/Common/AssetUtils.h>
#include <Atom/Viewport/MaterialViewportRequestBus.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzFramework/Application/Application.h>
@@ -30,10 +31,10 @@ namespace MaterialEditor
QListWidgetItem* selectedItem = nullptr;
for (const auto& preset : presets)
{
QImage image;
MaterialViewportRequestBus::BroadcastResult(image, &MaterialViewportRequestBus::Events::GetLightingPresetPreview, preset);
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), image);
AZStd::string path;
MaterialViewportRequestBus::BroadcastResult(path, &MaterialViewportRequestBus::Events::GetLightingPresetLastSavePath, preset);
QListWidgetItem* item =
CreateListItem(preset->m_displayName.c_str(), AZ::RPI::AssetUtils::MakeAssetId(path, 0).GetValue(), QSize(180, 180));
m_listItemToPresetMap[item] = preset;
@@ -30,10 +30,7 @@ namespace MaterialEditor
QListWidgetItem* selectedItem = nullptr;
for (const auto& preset : presets)
{
QImage image;
MaterialViewportRequestBus::BroadcastResult(image, &MaterialViewportRequestBus::Events::GetModelPresetPreview, preset);
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), image);
QListWidgetItem* item = CreateListItem(preset->m_displayName.c_str(), preset->m_modelAsset.GetId(), QSize(90, 90));
m_listItemToPresetMap[item] = preset;
@@ -12,6 +12,10 @@
#include <AzQtComponents/Components/Widgets/ElidingLabel.h>
#include <AzQtComponents/Components/Widgets/LineEdit.h>
#include <AzQtComponents/Components/Widgets/Text.h>
#include <AzToolsFramework/AssetBrowser/Thumbnails/ProductThumbnail.h>
#include <AzToolsFramework/Thumbnails/ThumbnailContext.h>
#include <AzToolsFramework/Thumbnails/ThumbnailWidget.h>
#include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
#include <Window/PresetBrowserDialogs/PresetBrowserDialog.h>
#include <QLabel>
@@ -41,35 +45,36 @@ namespace MaterialEditor
m_ui->m_presetList->setGridSize(QSize(0, 0));
m_ui->m_presetList->setWrapping(true);
QObject::connect(m_ui->m_presetList, &QListWidget::currentItemChanged, [this]() { SelectCurrentPreset(); });
QObject::connect(m_ui->m_presetList, &QListWidget::currentItemChanged, [this](){ SelectCurrentPreset(); });
}
QListWidgetItem* PresetBrowserDialog::CreateListItem(const QString& title, const QImage& image)
QListWidgetItem* PresetBrowserDialog::CreateListItem(const QString& title, const AZ::Data::AssetId& assetId, const QSize& size)
{
const QSize gridSize = m_ui->m_presetList->gridSize();
m_ui->m_presetList->setGridSize(
QSize(AZStd::max(gridSize.width(), image.width() + 10), AZStd::max(gridSize.height(), image.height() + 10)));
QSize(AZStd::max(gridSize.width(), size.width() + 10), AZStd::max(gridSize.height(), size.height() + 10)));
QListWidgetItem* item = new QListWidgetItem(m_ui->m_presetList);
item->setData(Qt::UserRole, title);
item->setSizeHint(image.size() + QSize(4, 4));
item->setSizeHint(size + QSize(4, 4));
m_ui->m_presetList->addItem(item);
QLabel* previewImage = new QLabel(m_ui->m_presetList);
previewImage->setFixedSize(image.size());
previewImage->setMargin(0);
previewImage->setPixmap(QPixmap::fromImage(image));
previewImage->updateGeometry();
AzToolsFramework::Thumbnailer::ThumbnailWidget* thumbnail = new AzToolsFramework::Thumbnailer::ThumbnailWidget(m_ui->m_presetList);
thumbnail->setFixedSize(size);
thumbnail->SetThumbnailKey(
MAKE_TKEY(AzToolsFramework::AssetBrowser::ProductThumbnailKey, assetId),
AzToolsFramework::Thumbnailer::ThumbnailContext::DefaultContext);
thumbnail->updateGeometry();
AzQtComponents::ElidingLabel* previewLabel = new AzQtComponents::ElidingLabel(previewImage);
AzQtComponents::ElidingLabel* previewLabel = new AzQtComponents::ElidingLabel(thumbnail);
previewLabel->setText(title);
previewLabel->setFixedSize(QSize(image.width(), 15));
previewLabel->setFixedSize(QSize(size.width(), 15));
previewLabel->setMargin(0);
previewLabel->setStyleSheet("background-color: rgb(35, 35, 35)");
AzQtComponents::Text::addPrimaryStyle(previewLabel);
AzQtComponents::Text::addLabelStyle(previewLabel);
m_ui->m_presetList->setItemWidget(item, previewImage);
m_ui->m_presetList->setItemWidget(item, thumbnail);
return item;
}
@@ -79,15 +84,15 @@ namespace MaterialEditor
m_ui->m_searchWidget->setReadOnly(false);
m_ui->m_searchWidget->setContextMenuPolicy(Qt::CustomContextMenu);
AzQtComponents::LineEdit::applySearchStyle(m_ui->m_searchWidget);
connect(m_ui->m_searchWidget, &QLineEdit::textChanged, this, [this]() { ApplySearchFilter(); });
connect(m_ui->m_searchWidget, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) { ShowSearchMenu(pos); });
connect(m_ui->m_searchWidget, &QLineEdit::textChanged, this, [this](){ ApplySearchFilter(); });
connect(m_ui->m_searchWidget, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos){ ShowSearchMenu(pos); });
}
void PresetBrowserDialog::SetupDialogButtons()
{
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(this, &QDialog::rejected, this, [this]() { SelectInitialPreset(); });
connect(this, &QDialog::rejected, this, [this](){ SelectInitialPreset(); });
}
void PresetBrowserDialog::ApplySearchFilter()
@@ -9,12 +9,12 @@
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/std/containers/vector.h>
#include <QDialog>
#endif
#include <Source/Window/PresetBrowserDialogs/ui_PresetBrowserDialog.h>
#include <Window/PresetBrowserDialogs/ui_PresetBrowserDialog.h>
class QImage;
class QListWidgetItem;
@@ -32,7 +32,7 @@ namespace MaterialEditor
protected:
void SetupPresetList();
QListWidgetItem* CreateListItem(const QString& title, const QImage& image);
QListWidgetItem* CreateListItem(const QString& title, const AZ::Data::AssetId& assetId, const QSize& size);
void SetupSearchWidget();
void SetupDialogButtons();