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>
This commit is contained in:
@@ -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.h
|
||||
Utilities/MouseHider.h
|
||||
Utilities/PixmapScaleUtilities.cpp
|
||||
Utilities/PixmapScaleUtilities.h
|
||||
Utilities/QtPluginPaths.cpp
|
||||
Utilities/QtPluginPaths.h
|
||||
Utilities/QtWindowUtilities.cpp
|
||||
|
||||
+2
-2
@@ -47,9 +47,9 @@ namespace AzToolsFramework
|
||||
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
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ namespace AzToolsFramework
|
||||
//! Returns the item tooltip text to display in the Outliner.
|
||||
virtual QString GenerateItemTooltip(AZ::EntityId entityId) const;
|
||||
//! 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
|
||||
virtual bool CanToggleLockVisibility(AZ::EntityId entityId) const;
|
||||
//! Returns whether the element's name should be editable
|
||||
|
||||
@@ -66,9 +66,9 @@ namespace AzToolsFramework
|
||||
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
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace AzToolsFramework
|
||||
|
||||
// EditorEntityUiHandler...
|
||||
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 PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
|
||||
const QModelIndex& descendantIndex) const override;
|
||||
|
||||
+7
-7
@@ -280,17 +280,17 @@ namespace AzToolsFramework
|
||||
QVariant EntityOutlinerListModel::GetEntityIcon(const AZ::EntityId& id) const
|
||||
{
|
||||
auto entityUiHandler = m_editorEntityFrameworkInterface->GetHandler(id);
|
||||
QPixmap pixmap;
|
||||
QIcon icon;
|
||||
|
||||
// Retrieve the icon from the handler
|
||||
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.
|
||||
@@ -299,7 +299,7 @@ namespace AzToolsFramework
|
||||
|
||||
if (isEditorOnly)
|
||||
{
|
||||
return QIcon(QPixmap(QString(":/Icons/Entity_Editor_Only.svg")));
|
||||
return QIcon(QString(":/Icons/Entity_Editor_Only.svg"));
|
||||
}
|
||||
|
||||
AZ::Entity* entity = nullptr;
|
||||
@@ -308,10 +308,10 @@ namespace AzToolsFramework
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace AzToolsFramework
|
||||
~LevelRootUiHandler() override = default;
|
||||
|
||||
// EditorEntityUiHandler...
|
||||
QPixmap GenerateItemIcon(AZ::EntityId entityId) const override;
|
||||
QIcon GenerateItemIcon(AZ::EntityId entityId) const override;
|
||||
QString GenerateItemInfoString(AZ::EntityId entityId) const override;
|
||||
bool CanToggleLockVisibility(AZ::EntityId entityId) const override;
|
||||
bool CanRename(AZ::EntityId entityId) const override;
|
||||
|
||||
@@ -81,14 +81,14 @@ namespace AzToolsFramework
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
QPixmap PrefabUiHandler::GenerateItemIcon(AZ::EntityId entityId) const
|
||||
QIcon PrefabUiHandler::GenerateItemIcon(AZ::EntityId entityId) const
|
||||
{
|
||||
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
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace AzToolsFramework
|
||||
// EditorEntityUiHandler...
|
||||
QString GenerateItemInfoString(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 PaintDescendantBackground(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index,
|
||||
const QModelIndex& descendantIndex) const override;
|
||||
|
||||
Reference in New Issue
Block a user