PerScreenDpi | QLabels incorrectly handle scale for icons (#4070)

* Fixes to icon generation. Generating a pixmap out of a size won't take the screen scaling factor into account, resulting in blurry results.
Note that this is not a catchall solution, every case needs to be addressed manually.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>

* HighDpi fixes for startup splashscreen and About dialog

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>

* Add helper function to generate appropriate pixmaps for a screen based on its dpi settings.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
monroegm-disable-blank-issue-2
Danilo Aimini 4 years ago committed by GitHub
parent 73b04d7e34
commit c0426ba465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,7 @@
// AzCore // AzCore
#include <AzCore/Casting/numeric_cast.h> // for aznumeric_cast #include <AzCore/Casting/numeric_cast.h> // for aznumeric_cast
#include <AzQtComponents/Utilities/PixmapScaleUtilities.h>
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <ui_AboutDialog.h> #include <ui_AboutDialog.h>
@ -46,8 +47,13 @@ CAboutDialog::CAboutDialog(QString versionText, QString richTextCopyrightNotice,
CAboutDialog > QLabel#link { text-decoration: underline; color: #94D2FF; }"); CAboutDialog > QLabel#link { text-decoration: underline; color: #94D2FF; }");
// Prepare background image // Prepare background image
QImage backgroundImage(QStringLiteral(":/StartupLogoDialog/splashscreen_background_developer_preview.jpg")); m_backgroundImage = AzQtComponents::ScalePixmapForScreenDpi(
m_backgroundImage = QPixmap::fromImage(backgroundImage.scaled(m_enforcedWidth, m_enforcedHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); QPixmap(QStringLiteral(":/StartupLogoDialog/splashscreen_background_developer_preview.jpg")),
screen(),
QSize(m_enforcedWidth, m_enforcedHeight),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation
);
// Draw the Open 3D Engine logo from svg // Draw the Open 3D Engine logo from svg
m_ui->m_logo->load(QStringLiteral(":/StartupLogoDialog/o3de_logo.svg")); m_ui->m_logo->load(QStringLiteral(":/StartupLogoDialog/o3de_logo.svg"));

@ -9,11 +9,11 @@
// Description : implementation file // Description : implementation file
#include "EditorDefs.h" #include "EditorDefs.h"
#include "StartupLogoDialog.h" #include "StartupLogoDialog.h"
#include <AzQtComponents/Utilities/PixmapScaleUtilities.h>
// Qt // Qt
#include <QPainter> #include <QPainter>
#include <QThread> #include <QThread>
@ -22,8 +22,6 @@ AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <ui_StartupLogoDialog.h> #include <ui_StartupLogoDialog.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CStartupLogoDialog dialog // CStartupLogoDialog dialog
@ -36,13 +34,16 @@ CStartupLogoDialog::CStartupLogoDialog(QString versionText, QString richTextCopy
m_ui->setupUi(this); m_ui->setupUi(this);
s_pLogoWindow = this; s_pLogoWindow = this;
m_backgroundImage = QPixmap(QStringLiteral(":/StartupLogoDialog/splashscreen_background_developer_preview.jpg"));
setFixedSize(QSize(600, 300)); setFixedSize(QSize(600, 300));
// Prepare background image // Prepare background image
QImage backgroundImage(QStringLiteral(":/StartupLogoDialog/splashscreen_background_developer_preview.jpg")); m_backgroundImage = AzQtComponents::ScalePixmapForScreenDpi(
m_backgroundImage = QPixmap::fromImage(backgroundImage.scaled(m_enforcedWidth, m_enforcedHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); QPixmap(QStringLiteral(":/StartupLogoDialog/splashscreen_background_developer_preview.jpg")),
screen(),
QSize(m_enforcedWidth, m_enforcedHeight),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation
);
// Draw the Open 3D Engine logo from svg // Draw the Open 3D Engine logo from svg
m_ui->m_logo->load(QStringLiteral(":/StartupLogoDialog/o3de_logo.svg")); m_ui->m_logo->load(QStringLiteral(":/StartupLogoDialog/o3de_logo.svg"));

@ -34,6 +34,7 @@
// AzQtComponents // AzQtComponents
#include <AzQtComponents/Components/Widgets/CheckBox.h> #include <AzQtComponents/Components/Widgets/CheckBox.h>
#include <AzQtComponents/Components/WindowDecorationWrapper.h> #include <AzQtComponents/Components/WindowDecorationWrapper.h>
#include <AzQtComponents/Utilities/PixmapScaleUtilities.h>
// Editor // Editor
#include "Settings.h" #include "Settings.h"
@ -79,8 +80,11 @@ WelcomeScreenDialog::WelcomeScreenDialog(QWidget* pParent)
{ {
projectPreviewPath = ":/WelcomeScreenDialog/DefaultProjectImage.png"; projectPreviewPath = ":/WelcomeScreenDialog/DefaultProjectImage.png";
} }
ui->activeProjectIcon->setPixmap( ui->activeProjectIcon->setPixmap(
QPixmap(projectPreviewPath).scaled( AzQtComponents::ScalePixmapForScreenDpi(
QPixmap(projectPreviewPath),
screen(),
ui->activeProjectIcon->size(), ui->activeProjectIcon->size(),
Qt::KeepAspectRatioByExpanding, Qt::KeepAspectRatioByExpanding,
Qt::SmoothTransformation Qt::SmoothTransformation

@ -0,0 +1,31 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Casting/numeric_cast.h>
#include <AzQtComponents/Utilities/PixmapScaleUtilities.h>
#include <QtGui/private/qhighdpiscaling_p.h>
namespace AzQtComponents
{
QPixmap ScalePixmapForScreenDpi(
QPixmap pixmap, QScreen* screen, QSize size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode)
{
qreal screenDpiFactor = QHighDpiScaling::factor(screen);
pixmap.setDevicePixelRatio(screenDpiFactor);
QPixmap scaledPixmap;
size.setWidth(aznumeric_cast<int>(aznumeric_cast<qreal>(size.width()) * screenDpiFactor));
size.setHeight(aznumeric_cast<int>(aznumeric_cast<qreal>(size.height()) * screenDpiFactor));
scaledPixmap = pixmap.scaled(size, aspectRatioMode, transformationMode);
return scaledPixmap;
}
}

@ -0,0 +1,19 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzQtComponents/AzQtComponentsAPI.h>
#include <QPixmap>
#include <QScreen>
namespace AzQtComponents
{
AZ_QT_COMPONENTS_API QPixmap ScalePixmapForScreenDpi(QPixmap pixmap, QScreen* screen, QSize size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode);
}; // namespace AzQtComponents

@ -276,6 +276,8 @@ set(FILES
Utilities/HandleDpiAwareness.cpp Utilities/HandleDpiAwareness.cpp
Utilities/HandleDpiAwareness.h Utilities/HandleDpiAwareness.h
Utilities/MouseHider.h Utilities/MouseHider.h
Utilities/PixmapScaleUtilities.cpp
Utilities/PixmapScaleUtilities.h
Utilities/QtPluginPaths.cpp Utilities/QtPluginPaths.cpp
Utilities/QtPluginPaths.h Utilities/QtPluginPaths.h
Utilities/QtWindowUtilities.cpp Utilities/QtWindowUtilities.cpp

@ -47,9 +47,9 @@ namespace AzToolsFramework
return QString(); return QString();
} }
QPixmap EditorEntityUiHandlerBase::GenerateItemIcon(AZ::EntityId /*entityId*/) const QIcon EditorEntityUiHandlerBase::GenerateItemIcon(AZ::EntityId /*entityId*/) const
{ {
return QPixmap(); return QIcon();
} }
bool EditorEntityUiHandlerBase::CanToggleLockVisibility(AZ::EntityId /*entityId*/) const bool EditorEntityUiHandlerBase::CanToggleLockVisibility(AZ::EntityId /*entityId*/) const

@ -40,7 +40,7 @@ namespace AzToolsFramework
//! Returns the item tooltip text to display in the Outliner. //! Returns the item tooltip text to display in the Outliner.
virtual QString GenerateItemTooltip(AZ::EntityId entityId) const; virtual QString GenerateItemTooltip(AZ::EntityId entityId) const;
//! Returns the item icon pixmap to display in the Outliner. //! Returns the item icon pixmap to display in the Outliner.
virtual QPixmap GenerateItemIcon(AZ::EntityId entityId) const; virtual QIcon GenerateItemIcon(AZ::EntityId entityId) const;
//! Returns whether the element's lock and visibility state should be accessible in the Outliner //! Returns whether the element's lock and visibility state should be accessible in the Outliner
virtual bool CanToggleLockVisibility(AZ::EntityId entityId) const; virtual bool CanToggleLockVisibility(AZ::EntityId entityId) const;
//! Returns whether the element's name should be editable //! Returns whether the element's name should be editable

@ -66,9 +66,9 @@ namespace AzToolsFramework
return result; return result;
} }
QPixmap LayerUiHandler::GenerateItemIcon(AZ::EntityId /*entityId*/) const QIcon LayerUiHandler::GenerateItemIcon(AZ::EntityId /*entityId*/) const
{ {
return QPixmap(m_layerIconPath); return QIcon(m_layerIconPath);
} }
void LayerUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void LayerUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const

@ -24,7 +24,7 @@ namespace AzToolsFramework
// EditorEntityUiHandler... // EditorEntityUiHandler...
QString GenerateItemInfoString(AZ::EntityId entityId) const override; QString GenerateItemInfoString(AZ::EntityId entityId) const override;
QPixmap GenerateItemIcon(AZ::EntityId entityId) const override; QIcon GenerateItemIcon(AZ::EntityId entityId) const override;
void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, void PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
const QModelIndex& descendantIndex) const override; const QModelIndex& descendantIndex) const override;

@ -280,17 +280,17 @@ namespace AzToolsFramework
QVariant EntityOutlinerListModel::GetEntityIcon(const AZ::EntityId& id) const QVariant EntityOutlinerListModel::GetEntityIcon(const AZ::EntityId& id) const
{ {
auto entityUiHandler = m_editorEntityFrameworkInterface->GetHandler(id); auto entityUiHandler = m_editorEntityFrameworkInterface->GetHandler(id);
QPixmap pixmap; QIcon icon;
// Retrieve the icon from the handler // Retrieve the icon from the handler
if (entityUiHandler != nullptr) if (entityUiHandler != nullptr)
{ {
pixmap = entityUiHandler->GenerateItemIcon(id); icon = entityUiHandler->GenerateItemIcon(id);
} }
if (!pixmap.isNull()) if (!icon.isNull())
{ {
return QIcon(pixmap); return icon;
} }
// If no icon was returned by the handler, use the default one. // If no icon was returned by the handler, use the default one.
@ -299,7 +299,7 @@ namespace AzToolsFramework
if (isEditorOnly) if (isEditorOnly)
{ {
return QIcon(QPixmap(QString(":/Icons/Entity_Editor_Only.svg"))); return QIcon(QString(":/Icons/Entity_Editor_Only.svg"));
} }
AZ::Entity* entity = nullptr; AZ::Entity* entity = nullptr;
@ -308,10 +308,10 @@ namespace AzToolsFramework
if (!isInitiallyActive) if (!isInitiallyActive)
{ {
return QIcon(QPixmap(QString(":/Icons/Entity_Not_Active.svg"))); return QIcon(QString(":/Icons/Entity_Not_Active.svg"));
} }
return QIcon(QPixmap(QString(":/Icons/Entity.svg"))); return QIcon(QString(":/Icons/Entity.svg"));
} }
QVariant EntityOutlinerListModel::GetEntityTooltip(const AZ::EntityId& id) const QVariant EntityOutlinerListModel::GetEntityTooltip(const AZ::EntityId& id) const

@ -41,9 +41,9 @@ namespace AzToolsFramework
} }
} }
QPixmap LevelRootUiHandler::GenerateItemIcon(AZ::EntityId /*entityId*/) const QIcon LevelRootUiHandler::GenerateItemIcon(AZ::EntityId /*entityId*/) const
{ {
return QPixmap(m_levelRootIconPath); return QIcon(m_levelRootIconPath);
} }
QString LevelRootUiHandler::GenerateItemInfoString(AZ::EntityId entityId) const QString LevelRootUiHandler::GenerateItemInfoString(AZ::EntityId entityId) const

@ -29,7 +29,7 @@ namespace AzToolsFramework
~LevelRootUiHandler() override = default; ~LevelRootUiHandler() override = default;
// EditorEntityUiHandler... // EditorEntityUiHandler...
QPixmap GenerateItemIcon(AZ::EntityId entityId) const override; QIcon GenerateItemIcon(AZ::EntityId entityId) const override;
QString GenerateItemInfoString(AZ::EntityId entityId) const override; QString GenerateItemInfoString(AZ::EntityId entityId) const override;
bool CanToggleLockVisibility(AZ::EntityId entityId) const override; bool CanToggleLockVisibility(AZ::EntityId entityId) const override;
bool CanRename(AZ::EntityId entityId) const override; bool CanRename(AZ::EntityId entityId) const override;

@ -81,14 +81,14 @@ namespace AzToolsFramework
return tooltip; return tooltip;
} }
QPixmap PrefabUiHandler::GenerateItemIcon(AZ::EntityId entityId) const QIcon PrefabUiHandler::GenerateItemIcon(AZ::EntityId entityId) const
{ {
if (m_prefabEditInterface->IsOwningPrefabBeingEdited(entityId)) if (m_prefabEditInterface->IsOwningPrefabBeingEdited(entityId))
{ {
return QPixmap(m_prefabEditIconPath); return QIcon(m_prefabEditIconPath);
} }
return QPixmap(m_prefabIconPath); return QIcon(m_prefabIconPath);
} }
void PrefabUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void PrefabUiHandler::PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const

@ -31,7 +31,7 @@ namespace AzToolsFramework
// EditorEntityUiHandler... // EditorEntityUiHandler...
QString GenerateItemInfoString(AZ::EntityId entityId) const override; QString GenerateItemInfoString(AZ::EntityId entityId) const override;
QString GenerateItemTooltip(AZ::EntityId entityId) const override; QString GenerateItemTooltip(AZ::EntityId entityId) const override;
QPixmap GenerateItemIcon(AZ::EntityId entityId) const override; QIcon GenerateItemIcon(AZ::EntityId entityId) const override;
void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override; void PaintItemBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, void PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
const QModelIndex& descendantIndex) const override; const QModelIndex& descendantIndex) const override;

Loading…
Cancel
Save