Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: Fix HiDPI icon scaling #5463

Merged
merged 1 commit into from May 30, 2017
Merged

Qt: Fix HiDPI icon scaling #5463

merged 1 commit into from May 30, 2017

Conversation

spycrab
Copy link
Contributor

@spycrab spycrab commented May 21, 2017

No description provided.

@@ -93,7 +93,10 @@ void ControllersWindow::CreateGamecubeLayout()
m_gc_box = new QGroupBox();
m_gc_layout = new QFormLayout();
m_gc_label = new QLabel();
m_gc_label->setPixmap(QPixmap(m_gamecube_icon));

auto pixmap = QPixmap(m_gamecube_icon).scaled(QSize(64, 64));

This comment was marked as off-topic.

This comment was marked as off-topic.

@spycrab spycrab force-pushed the qt_hidpi branch 12 times, most recently from e2c4490 to 21c9891 Compare May 21, 2017 17:30
@spycrab spycrab changed the title [WIP] Qt: Fix HiDPI icon scaling Qt: Fix HiDPI icon scaling May 21, 2017
@spycrab spycrab changed the title Qt: Fix HiDPI icon scaling [WIP] Qt: Fix HiDPI icon scaling May 21, 2017
@spycrab spycrab force-pushed the qt_hidpi branch 3 times, most recently from 1919a22 to 7ea4b1c Compare May 22, 2017 11:28
@spycrab spycrab changed the title [WIP] Qt: Fix HiDPI icon scaling Qt: Fix HiDPI icon scaling May 22, 2017
@spycrab
Copy link
Contributor Author

spycrab commented May 22, 2017

Ready to be reviewed & merged now.

Copy link
Member

@JosJuice JosJuice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I've missed something, the game list is still using low-res images on high-DPI screens.

m_wii_icon(Settings().GetResourcesDir().append(QStringLiteral("Platform_Wii.png")))
m_gamecube_icon(
Settings().GetResourcesDir().append(QStringLiteral("Platform_Gamecube@2x.png"))),
m_wii_icon(Settings().GetResourcesDir().append(QStringLiteral("Platform_Wii@2x.png")))

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

std::string number = QString::number(num, 'f', 1).toStdString();

if (num == static_cast<int>(num))
number = number.substr(0, number.length() - 2);

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@Starsam80
Copy link
Contributor

Starsam80 commented May 22, 2017

Toolbar icons are still not scaled, and the icons seem a bit fuzzy
snip

Here is WX for a comparison
snip

@spycrab spycrab force-pushed the qt_hidpi branch 6 times, most recently from 7a445e7 to 8b3216f Compare May 22, 2017 21:35
@Starsam80
Copy link
Contributor

LGTM:
image

Copy link
Contributor

@ligfx ligfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't work on macOS, use the Qt HighDpi attributes, or use devicePixelRatio() correctly. Could you please go over the patch I posted above again, and make sure you understand it? I'm usually on IRC if you have more questions.

{
double GetScale()
{
return static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio() * 1.1;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

return static_cast<QGuiApplication*>(QGuiApplication::instance())->devicePixelRatio() * 1.1;
}

double GetScaledIconSize(const double scale)

This comment was marked as off-topic.

std::string number = QString::number(num, 'f', 1).toStdString();

if (num == static_cast<int>(num))
number = number.substr(0, number.length() - 2);

This comment was marked as off-topic.

@@ -83,7 +83,7 @@ void GameList::MakeTableView()
QHeaderView* hor_header = m_table->horizontalHeader();
hor_header->setSectionResizeMode(GameListModel::COL_PLATFORM, QHeaderView::ResizeToContents);
hor_header->setSectionResizeMode(GameListModel::COL_COUNTRY, QHeaderView::ResizeToContents);
hor_header->setSectionResizeMode(GameListModel::COL_ID, QHeaderView::ResizeToContents);
hor_header->setSectionResizeMode(GameListModel::COL_ID, QHeaderView::Fixed);

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

case GameListModel::COL_ID:
painter->drawText(option.rect,

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

const auto height =
static_cast<double>(pixmap.height()) / (icon_scaled ? Resources::GetIconScale() : 1) * scale;

DrawPixmap(painter, rect, icon_scaled ?

This comment was marked as off-topic.

@@ -11,10 +11,13 @@ class TableDelegate final : public QStyledItemDelegate
Q_OBJECT

public:
explicit TableDelegate(QWidget* parent = nullptr);

This comment was marked as off-topic.

This comment was marked as off-topic.

void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap) const;
void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap,
const QSize& size) const;
void DrawPixmap(QPainter* painter, const QRect& rect, const QPixmap& pixmap,

This comment was marked as off-topic.

{
setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
setMovable(false);
setFloatable(false);
setIconSize(ICON_SIZE);
setIconSize(ICON_SIZE * m_scale);

This comment was marked as off-topic.

m_controllers_action->setIcon(QIcon(QStringLiteral("classic.png").prepend(dir)));
const QString suffix = DPI::GetScaledIconSuffix(m_scale, 2);

m_open_action->setIcon(QIcon(QStringLiteral("open%1.png").arg(suffix).prepend(dir)));

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

break;
case GameListModel::COL_BANNER:
DrawPixmap(painter, option.rect,
data.value<QPixmap>().scaled(NORMAL_BANNER_SIZE, Qt::KeepAspectRatio,
Qt::SmoothTransformation));
data.value<QPixmap>().scaled(NORMAL_BANNER_SIZE * scale, Qt::KeepAspectRatio,

This comment was marked as off-topic.

@spycrab spycrab force-pushed the qt_hidpi branch 2 times, most recently from 65e643c to 3846e90 Compare May 27, 2017 09:41
Copy link
Contributor

@Starsam80 Starsam80 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a few comments, tested and LGTM.

for (QString country : countries)
m_countries.append(QPixmap(country.prepend(sys_dir)));
m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir)));

QStringList ratings{QStringLiteral("rating0.png"), QStringLiteral("rating1.png"),

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -40,7 +56,9 @@ void Resources::Init()
m_ratings.append(QPixmap(rating.prepend(sys_dir)));

m_misc.append(QPixmap(QStringLiteral("nobanner.png").prepend(sys_dir)));

This comment was marked as off-topic.

This comment was marked as off-topic.

m_misc.append(QPixmap(QStringLiteral("dolphin_logo.png").prepend(sys_dir)));
m_misc.append(QPixmap(QStringLiteral("dolphin_logo%1.png")
.arg(Resources::GetPreferredIconScale())
.prepend(sys_dir)));
m_misc.append(QPixmap(QStringLiteral("Dolphin.png").prepend(sys_dir)));

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@ligfx ligfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great on macOS. Couple code cleanup things.

for (QString country : countries)
m_countries.append(QPixmap(country.prepend(sys_dir)));
m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir)));

QStringList ratings{QStringLiteral("rating0.png"), QStringLiteral("rating1.png"),

This comment was marked as off-topic.

m_misc.append(QPixmap(QStringLiteral("dolphin_logo.png").prepend(sys_dir)));
m_misc.append(QPixmap(QStringLiteral("dolphin_logo%1.png")
.arg(Resources::GetPreferredIconScale())
.prepend(sys_dir)));
m_misc.append(QPixmap(QStringLiteral("Dolphin.png").prepend(sys_dir)));

This comment was marked as off-topic.

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(

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -13,25 +17,37 @@ QList<QPixmap> Resources::m_countries;
QList<QPixmap> Resources::m_ratings;
QList<QPixmap> Resources::m_misc;

QString Resources::GetPreferredIconScale(int max)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

for (QString country : countries)
m_countries.append(QPixmap(country.prepend(sys_dir)));
m_countries.append(QPixmap(country.arg(GetPreferredIconScale()).prepend(sys_dir)));

This comment was marked as off-topic.

This comment was marked as off-topic.

@spycrab spycrab force-pushed the qt_hidpi branch 2 times, most recently from dffdf50 to df36821 Compare May 28, 2017 09:31
for (QString platform : platforms)
m_platforms.append(QPixmap(platform.prepend(sys_dir)));
m_platforms.append(GetScaledIcon(platform.prepend(QStringLiteral("Platform_"))));

This comment was marked as off-topic.

for (QString country : countries)
m_countries.append(QPixmap(country.prepend(sys_dir)));
m_countries.append(GetScaledIcon(country.prepend(QStringLiteral("Flag_"))));

This comment was marked as off-topic.

m_fullscreen_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("fullscreen"))));
m_screenshot_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("screenshot"))));
m_config_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("config"))));
m_controllers_action->setIcon(QIcon(Resources::GetScaledThemeIcon(QStringLiteral("classic"))));

This comment was marked as off-topic.

@@ -13,25 +17,37 @@ QList<QPixmap> Resources::m_countries;
QList<QPixmap> Resources::m_ratings;
QList<QPixmap> Resources::m_misc;

QString Resources::GetPreferredIconScale(int max)

This comment was marked as off-topic.

return QStringLiteral("");
}

QPixmap Resources::GetScaledIcon(const QString& name, int max, const QString& dir)

This comment was marked as off-topic.

return QStringLiteral("");
}

QPixmap Resources::GetScaledIcon(const QString& name, int max, const QString& dir)

This comment was marked as off-topic.


QList<QPixmap> Resources::m_platforms;
QList<QPixmap> Resources::m_countries;
QList<QPixmap> Resources::m_ratings;
QList<QPixmap> Resources::m_misc;

QString Resources::GetPreferredIconScale(int max)

This comment was marked as off-topic.

@@ -26,6 +26,11 @@ class Resources final
LOGO_SMALL
};

static QString GetPreferredIconScale(int max = 4);

This comment was marked as off-topic.

static QString GetPreferredIconScale(int max = 4);
static QPixmap GetScaledIcon(const QString& name, int max = 4,
const QString& dir = QStringLiteral(""));
static QPixmap GetScaledThemeIcon(const QString& name, int max = 4);

This comment was marked as off-topic.

This comment was marked as off-topic.

@spycrab
Copy link
Contributor Author

spycrab commented May 28, 2017

I think this can be merged now as all points have been addressed

@ligfx
Copy link
Contributor

ligfx commented May 28, 2017

@spycrab That's not how it works :) Make changes, get more reviews, then merge.

return QStringLiteral("");
}

QPixmap Resources::GetScaledPixmap(const std::string& name, int max, Resources::Directory dir)

This comment was marked as off-topic.

Theme
};

static QString GetPreferredIconScale(int max = 4);

This comment was marked as off-topic.

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(QIcon(Resources::GetScaledPixmap("open", 4, Resources::Directory::Theme)));

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


QList<QPixmap> Resources::m_platforms;
QList<QPixmap> Resources::m_countries;
QList<QPixmap> Resources::m_ratings;
QList<QPixmap> Resources::m_misc;

QString Resources::GetPreferredPixmapScale(int max)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@spycrab spycrab force-pushed the qt_hidpi branch 2 times, most recently from 21721f8 to 37db2f8 Compare May 28, 2017 22:19
QPixmap pixmap;
for (int scale : {4, 2, 1})
{
pixmap = QPixmap(QStringLiteral("%1%2%3.png")

This comment was marked as off-topic.

return QStringLiteral("");
}

QPixmap Resources::GetScaledPixmap(const std::string& name, bool is_themed)

This comment was marked as off-topic.

QPixmap Resources::GetScaledPixmap(const std::string& name, bool is_themed)
{
QPixmap pixmap;
for (int scale : {4, 2, 1})

This comment was marked as off-topic.

@spycrab
Copy link
Contributor Author

spycrab commented May 30, 2017

@ligfx Can you take a look again?

Copy link
Contributor

@ligfx ligfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @spycrab! One small thing left.

const auto sizes = icon.availableSizes();
const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio();

return icon.pixmap(sizes[std::min((dpr <= 1) ? 1 : (dpr <= 2) ? 2 : 4, sizes.size() - 1)]);

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@ligfx ligfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, that fixed it. Great job. This makes DolphinQt2 look so much better!

@Helios747 Helios747 merged commit 25f24d3 into dolphin-emu:master May 30, 2017
@spycrab spycrab deleted the qt_hidpi branch May 31, 2017 03:48
@leoetlino leoetlino modified the milestone: Qt Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants