Qt: Provide a central point for getting the app logo

And ensure it's using high DPI.
This commit is contained in:
Stenzek
2025-11-16 00:31:43 +10:00
parent 75aee64772
commit b3385094f9
17 changed files with 45 additions and 67 deletions

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
#include "aboutdialog.h"
#include "qthost.h"
#include "qtutils.h"
#include "core/settings.h"
@@ -22,6 +23,7 @@
AboutDialog::AboutDialog(QWidget* parent /* = nullptr */) : QDialog(parent)
{
m_ui.setupUi(this);
m_ui.icon->setPixmap(QtHost::GetAppLogo());
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setFixedSize(geometry().width(), geometry().height());

View File

@@ -13,16 +13,12 @@
<property name="windowTitle">
<string>About DuckStation</string>
</property>
<property name="windowIcon">
<iconset resource="resources/icons.qrc">
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="iconWidget" native="true">
<layout class="QVBoxLayout" name="iconLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>1</number>
@@ -47,18 +43,18 @@
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="resources/icons.qrc">:/icons/duck.png</pixmap>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="iconSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -93,7 +89,6 @@
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
@@ -120,8 +115,6 @@
</item>
</layout>
</widget>
<resources>
<include location="resources/icons.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View File

@@ -14,7 +14,7 @@ AchievementLoginDialog::AchievementLoginDialog(QWidget* parent, Achievements::Lo
: QDialog(parent), m_reason(reason)
{
m_ui.setupUi(this);
m_ui.iconLabel->setPixmap(QPixmap(QString::fromStdString(QtHost::GetResourcePath("images/ra-icon.webp", true))));
m_ui.iconLabel->setPixmap(QPixmap(QtHost::GetResourceQPath("images/ra-icon.webp", true)));
QFont title_font(m_ui.titleLabel->font());
title_font.setBold(true);
title_font.setPixelSize(20);

View File

@@ -643,7 +643,7 @@ const QPixmap& GameListModel::getFlagPixmapForEntry(const GameList::Entry* ge) c
if (it != m_flag_pixmap_cache.end())
return it->second;
const QIcon icon(QString::fromStdString(QtHost::GetResourcePath(ge->GetLanguageIconName(), true)));
const QIcon icon(QtHost::GetResourceQPath(ge->GetLanguageIconName(), true));
it = m_flag_pixmap_cache.emplace(name, icon.pixmap(FLAG_PIXMAP_SIZE, m_device_pixel_ratio)).first;
return it->second;
}
@@ -1267,13 +1267,12 @@ void GameListModel::loadCommonImages()
.pixmap(COMPATIBILITY_PIXMAP_SIZE, m_device_pixel_ratio);
}
m_no_achievements_pixmap = QIcon(QString::fromStdString(QtHost::GetResourcePath("images/trophy-icon-gray.svg", true)))
m_no_achievements_pixmap = QIcon(QtHost::GetResourceQPath("images/trophy-icon-gray.svg", true))
.pixmap(ACHIEVEMENT_PIXMAP_SIZE, m_device_pixel_ratio);
m_has_achievements_pixmap = QIcon(QString::fromStdString(QtHost::GetResourcePath("images/trophy-icon.svg", true)))
m_has_achievements_pixmap = QIcon(QtHost::GetResourceQPath("images/trophy-icon.svg", true))
.pixmap(ACHIEVEMENT_PIXMAP_SIZE, m_device_pixel_ratio);
m_mastered_achievements_pixmap =
QIcon(QString::fromStdString(QtHost::GetResourcePath("images/trophy-icon-star.svg", true)))
.pixmap(ACHIEVEMENT_PIXMAP_SIZE, m_device_pixel_ratio);
m_mastered_achievements_pixmap = QIcon(QtHost::GetResourceQPath("images/trophy-icon-star.svg", true))
.pixmap(ACHIEVEMENT_PIXMAP_SIZE, m_device_pixel_ratio);
}
class GameListSortModel final : public QSortFilterProxyModel

View File

@@ -10,13 +10,6 @@
<height>562</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
@@ -52,7 +45,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="title" />
<widget class="QLineEdit" name="title"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="restoreTitle">

View File

@@ -110,9 +110,7 @@ void LogWindow::updateWindowTitle()
void LogWindow::createUi()
{
QIcon icon;
icon.addFile(QString::fromUtf8(":/icons/duck.png"), QSize(), QIcon::Normal, QIcon::Off);
setWindowIcon(icon);
setWindowIcon(QIcon::fromTheme(QStringLiteral("file-list-line")));
setWindowFlag(Qt::CustomizeWindowHint, true);
setWindowFlag(Qt::WindowCloseButtonHint, false);
updateWindowTitle();

View File

@@ -1893,6 +1893,8 @@ void MainWindow::setupAdditionalUi()
m_status_vps_widget->setFixedSize(150, 16);
m_status_vps_widget->hide();
m_ui.actionAbout->setIcon(QtHost::GetAppIcon());
m_settings_toolbar_menu = new QMenu(m_ui.toolBar);
QtUtils::StylePopupMenu(m_settings_toolbar_menu);
m_settings_toolbar_menu->addAction(m_ui.actionSettings);

View File

@@ -13,13 +13,6 @@
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>DuckStation</string>
</property>
<property name="windowIcon">
<iconset resource="resources/duckstation-qt.qrc">
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
</property>
<property name="unifiedTitleAndToolBarOnMac">
<bool>true</bool>
</property>
@@ -581,10 +574,6 @@
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset resource="resources/duckstation-qt.qrc">
<normaloff>:/icons/duck_64.png</normaloff>:/icons/duck_64.png</iconset>
</property>
<property name="text">
<string>&amp;About DuckStation...</string>
</property>

View File

@@ -412,6 +412,13 @@ const QIcon& QtHost::GetAppIcon()
return s_state.app_icon;
}
QPixmap QtHost::GetAppLogo()
{
QPixmap pm(GetResourceQPath("images/duck.png", true));
pm.setDevicePixelRatio(qApp->devicePixelRatio());
return pm;
}
std::optional<bool> QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url, std::vector<u8>* data)
{
static constexpr u32 HTTP_POLL_INTERVAL = 10;
@@ -637,7 +644,7 @@ bool QtHost::SetDataDirectory()
void QtHost::LoadResources()
{
s_state.app_icon = QIcon(QStringLiteral(":/icons/duck.png"));
s_state.app_icon = QIcon(GetResourceQPath("images/duck.png", true));
}
void Host::LoadSettings(const SettingsInterface& si, std::unique_lock<std::mutex>& lock)
@@ -2761,6 +2768,11 @@ std::string QtHost::GetResourcePath(std::string_view filename, bool allow_overri
Path::Combine(EmuFolders::Resources, filename);
}
QString QtHost::GetResourceQPath(std::string_view name, bool allow_override)
{
return QString::fromStdString(GetResourcePath(name, allow_override));
}
const QStringList& QtHost::GetRobotoFontFamilies()
{
std::call_once(s_state.roboto_font_once_flag, []() {

View File

@@ -384,11 +384,15 @@ QString GetAppConfigSuffix();
/// Returns the main application icon.
const QIcon& GetAppIcon();
/// Returns a higher resolution logo for the application.
QPixmap GetAppLogo();
/// Returns the base path for resources. This may be : prefixed, if we're using embedded resources.
QString GetResourcesBasePath();
/// Returns the path to the specified resource.
std::string GetResourcePath(std::string_view name, bool allow_override);
QString GetResourceQPath(std::string_view name, bool allow_override);
/// Returns the font family for the bundled Roboto font.
const QStringList& GetRobotoFontFamilies();

View File

@@ -386,13 +386,13 @@ QIcon QtUtils::GetIconForRegion(ConsoleRegion region)
switch (region)
{
case ConsoleRegion::NTSC_J:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/NTSC-J.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/NTSC-J.svg", true));
case ConsoleRegion::NTSC_U:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/NTSC-U.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/NTSC-U.svg", true));
case ConsoleRegion::PAL:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/PAL.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/PAL.svg", true));
case ConsoleRegion::Auto:
return QIcon(QStringLiteral(":/icons/system-search.png"));
@@ -407,13 +407,13 @@ QIcon QtUtils::GetIconForRegion(DiscRegion region)
switch (region)
{
case DiscRegion::NTSC_J:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/NTSC-J.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/NTSC-J.svg", true));
case DiscRegion::NTSC_U:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/NTSC-U.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/NTSC-U.svg", true));
case DiscRegion::PAL:
return QIcon(QString::fromStdString(QtHost::GetResourcePath("images/flags/PAL.svg", true)));
return QIcon(QtHost::GetResourceQPath("images/flags/PAL.svg", true));
case DiscRegion::Other:
case DiscRegion::NonPS1:
@@ -442,14 +442,12 @@ QIcon QtUtils::GetIconForEntryType(GameList::EntryType type)
QIcon QtUtils::GetIconForCompatibility(GameDatabase::CompatibilityRating rating)
{
return QIcon(QString::fromStdString(
QtHost::GetResourcePath(TinyString::from_format("images/star-{}.svg", static_cast<u32>(rating)), true)));
return QIcon(QtHost::GetResourceQPath(TinyString::from_format("images/star-{}.svg", static_cast<u32>(rating)), true));
}
QIcon QtUtils::GetIconForLanguage(std::string_view language_name)
{
return QIcon(
QString::fromStdString(QtHost::GetResourcePath(GameDatabase::GetLanguageFlagResourceName(language_name), true)));
return QIcon(QtHost::GetResourceQPath(GameDatabase::GetLanguageFlagResourceName(language_name), true));
}
template<typename T>

View File

@@ -153,9 +153,6 @@
<file>icons/drive-optical@2x.png</file>
<file>icons/drive-removable-media.png</file>
<file>icons/drive-removable-media@2x.png</file>
<file>icons/duck.png</file>
<file>icons/duck_128.png</file>
<file>icons/duck_64.png</file>
<file>icons/edit-clear-16.png</file>
<file>icons/edit-clear-16@2x.png</file>
<file>icons/edit-find.png</file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

View File

@@ -146,10 +146,7 @@ void SetupWizardDialog::confirmCancel()
void SetupWizardDialog::setupUi()
{
m_ui.setupUi(this);
m_ui.logo->setPixmap(
QPixmap(QString::fromUtf8(Path::Combine(EmuFolders::Resources, "images" FS_OSPATH_SEPARATOR_STR "duck.png"))));
m_ui.logo->setPixmap(QtHost::GetAppLogo());
m_ui.pages->setCurrentIndex(0);
m_page_labels[Page_Language] = m_ui.labelLanguage;
@@ -569,8 +566,7 @@ void SetupWizardDialog::setupAchievementsPage(bool initial)
{
if (initial)
{
m_ui.achievementsIconLabel->setPixmap(
QPixmap(QString::fromStdString(QtHost::GetResourcePath("images/ra-icon.webp", true))));
m_ui.achievementsIconLabel->setPixmap(QPixmap(QtHost::GetResourceQPath("images/ra-icon.webp", true)));
QFont title_font(m_ui.achievementsTitleLabel->font());
title_font.setBold(true);
title_font.setPixelSize(20);

View File

@@ -13,11 +13,6 @@
<property name="windowTitle">
<string>DuckStation Setup Wizard</string>
</property>
<property name="windowIcon">
<iconset>
<normalon>:/icons/duck.png</normalon>
</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>10</number>