Merge pull request #5463 from spycrab/qt_hidpi
Qt: Fix HiDPI icon scaling
This commit is contained in:
commit
25f24d32ff
|
@ -19,6 +19,9 @@
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
UICommon::SetUserDirectory("");
|
||||
|
|
|
@ -2,46 +2,92 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
#include <QStringList>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "DolphinQt2/Resources.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
|
||||
QList<QPixmap> Resources::m_platforms;
|
||||
QList<QPixmap> Resources::m_countries;
|
||||
QList<QPixmap> Resources::m_ratings;
|
||||
QList<QPixmap> Resources::m_misc;
|
||||
|
||||
QIcon Resources::GetIcon(const QString& name, const QString& dir)
|
||||
{
|
||||
QString base_path = dir + name;
|
||||
|
||||
const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio();
|
||||
|
||||
QIcon icon(base_path.append(QStringLiteral(".png")));
|
||||
|
||||
if (dpr > 2)
|
||||
{
|
||||
QPixmap pixmap(base_path.append(QStringLiteral("@4x.png")));
|
||||
if (!pixmap.isNull())
|
||||
{
|
||||
pixmap.setDevicePixelRatio(4.0);
|
||||
icon.addPixmap(pixmap);
|
||||
}
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
QPixmap Resources::GetPixmap(const QString& name, const QString& dir)
|
||||
{
|
||||
const auto icon = GetIcon(name, dir);
|
||||
return icon.pixmap(icon.availableSizes()[0]);
|
||||
}
|
||||
|
||||
QIcon Resources::GetScaledIcon(const std::string& name)
|
||||
{
|
||||
return GetIcon(QString::fromStdString(name), Settings().GetResourcesDir());
|
||||
}
|
||||
|
||||
QIcon Resources::GetScaledThemeIcon(const std::string& name)
|
||||
{
|
||||
return GetIcon(QString::fromStdString(name), Settings().GetThemeDir());
|
||||
}
|
||||
|
||||
QPixmap Resources::GetScaledPixmap(const std::string& name)
|
||||
{
|
||||
return GetPixmap(QString::fromStdString(name), Settings().GetResourcesDir());
|
||||
}
|
||||
|
||||
QPixmap Resources::GetScaledThemePixmap(const std::string& name)
|
||||
{
|
||||
return GetPixmap(QString::fromStdString(name), Settings().GetThemeDir());
|
||||
}
|
||||
|
||||
void Resources::Init()
|
||||
{
|
||||
QString sys_dir = QString::fromStdString(File::GetSysDirectory() + RESOURCES_DIR + DIR_SEP);
|
||||
|
||||
QStringList platforms{QStringLiteral("Platform_Gamecube.png"), QStringLiteral("Platform_Wii.png"),
|
||||
QStringLiteral("Platform_Wad.png"), QStringLiteral("Platform_File.png")};
|
||||
for (QString platform : platforms)
|
||||
m_platforms.append(QPixmap(platform.prepend(sys_dir)));
|
||||
for (const std::string& platform :
|
||||
{"Platform_Gamecube", "Platform_Wii", "Platform_Wad", "Platform_File"})
|
||||
{
|
||||
m_platforms.append(GetScaledPixmap(platform));
|
||||
}
|
||||
|
||||
QStringList countries{
|
||||
QStringLiteral("Flag_Europe.png"), QStringLiteral("Flag_Japan.png"),
|
||||
QStringLiteral("Flag_USA.png"), QStringLiteral("Flag_Australia.png"),
|
||||
QStringLiteral("Flag_France.png"), QStringLiteral("Flag_Germany.png"),
|
||||
QStringLiteral("Flag_Italy.png"), QStringLiteral("Flag_Korea.png"),
|
||||
QStringLiteral("Flag_Netherlands.png"), QStringLiteral("Flag_Russia.png"),
|
||||
QStringLiteral("Flag_Spain.png"), QStringLiteral("Flag_Taiwan.png"),
|
||||
QStringLiteral("Flag_International.png"), QStringLiteral("Flag_Unknown.png")};
|
||||
for (QString country : countries)
|
||||
m_countries.append(QPixmap(country.prepend(sys_dir)));
|
||||
for (const std::string& country :
|
||||
{"Flag_Europe", "Flag_Japan", "Flag_USA", "Flag_Australia", "Flag_France", "Flag_Germany",
|
||||
"Flag_Italy", "Flag_Korea", "Flag_Netherlands", "Flag_Russia", "Flag_Spain", "Flag_Taiwan",
|
||||
"Flag_International", "Flag_Unknown"})
|
||||
{
|
||||
m_countries.append(GetScaledPixmap(country));
|
||||
}
|
||||
for (int stars = 0; stars <= 5; stars++)
|
||||
m_ratings.append(GetScaledPixmap("rating" + std::to_string(stars)));
|
||||
|
||||
QStringList ratings{QStringLiteral("rating0.png"), QStringLiteral("rating1.png"),
|
||||
QStringLiteral("rating2.png"), QStringLiteral("rating3.png"),
|
||||
QStringLiteral("rating4.png"), QStringLiteral("rating5.png")};
|
||||
for (QString rating : ratings)
|
||||
m_ratings.append(QPixmap(rating.prepend(sys_dir)));
|
||||
|
||||
m_misc.append(QPixmap(QStringLiteral("nobanner.png").prepend(sys_dir)));
|
||||
m_misc.append(QPixmap(QStringLiteral("dolphin_logo.png").prepend(sys_dir)));
|
||||
m_misc.append(QPixmap(QStringLiteral("Dolphin.png").prepend(sys_dir)));
|
||||
m_misc.append(GetScaledPixmap("nobanner"));
|
||||
m_misc.append(GetScaledPixmap("dolphin_logo"));
|
||||
m_misc.append(GetScaledPixmap("Dolphin"));
|
||||
}
|
||||
|
||||
QPixmap Resources::GetPlatform(int platform)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
|
||||
// Store for various QPixmaps that will be used repeatedly.
|
||||
class Resources final
|
||||
|
@ -26,8 +25,17 @@ public:
|
|||
LOGO_SMALL
|
||||
};
|
||||
|
||||
static QIcon GetScaledIcon(const std::string& name);
|
||||
static QIcon GetScaledThemeIcon(const std::string& name);
|
||||
|
||||
static QPixmap GetScaledPixmap(const std::string& name);
|
||||
static QPixmap GetScaledThemePixmap(const std::string& name);
|
||||
|
||||
private:
|
||||
Resources() {}
|
||||
static QIcon GetIcon(const QString& name, const QString& dir);
|
||||
static QPixmap GetPixmap(const QString& name, const QString& dir);
|
||||
|
||||
static QList<QPixmap> m_platforms;
|
||||
static QList<QPixmap> m_countries;
|
||||
static QList<QPixmap> m_ratings;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <QIcon>
|
||||
|
||||
#include "DolphinQt2/Resources.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
#include "DolphinQt2/ToolBar.h"
|
||||
|
||||
|
@ -91,15 +92,13 @@ void ToolBar::MakeActions()
|
|||
|
||||
void ToolBar::UpdateIcons()
|
||||
{
|
||||
QString dir = Settings().GetThemeDir();
|
||||
|
||||
m_open_action->setIcon(QIcon(QStringLiteral("open.png").prepend(dir)));
|
||||
m_paths_action->setIcon(QIcon(QStringLiteral("browse.png").prepend(dir)));
|
||||
m_play_action->setIcon(QIcon(QStringLiteral("play.png").prepend(dir)));
|
||||
m_pause_action->setIcon(QIcon(QStringLiteral("pause.png").prepend(dir)));
|
||||
m_stop_action->setIcon(QIcon(QStringLiteral("stop.png").prepend(dir)));
|
||||
m_fullscreen_action->setIcon(QIcon(QStringLiteral("fullscreen.png").prepend(dir)));
|
||||
m_screenshot_action->setIcon(QIcon(QStringLiteral("screenshot.png").prepend(dir)));
|
||||
m_config_action->setIcon(QIcon(QStringLiteral("config.png").prepend(dir)));
|
||||
m_controllers_action->setIcon(QIcon(QStringLiteral("classic.png").prepend(dir)));
|
||||
m_open_action->setIcon(Resources::GetScaledThemeIcon("open"));
|
||||
m_paths_action->setIcon(Resources::GetScaledThemeIcon("browse"));
|
||||
m_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
|
||||
m_pause_action->setIcon(Resources::GetScaledThemeIcon("pause"));
|
||||
m_stop_action->setIcon(Resources::GetScaledThemeIcon("stop"));
|
||||
m_fullscreen_action->setIcon(Resources::GetScaledThemeIcon("fullscreen"));
|
||||
m_screenshot_action->setIcon(Resources::GetScaledThemeIcon("screenshot"));
|
||||
m_config_action->setIcon(Resources::GetScaledThemeIcon("config"));
|
||||
m_controllers_action->setIcon(Resources::GetScaledThemeIcon("classic"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue