mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-10-22 16:09:06 +00:00
The `QtUtils::AdjustSizeWithinScreen()` function now centers the widget on their parent window after the widget's size is adjusted. This is required in some desktop environments (generally on Linux systems) to ensure that the just-resized widget remains aligned with its parent window. The creation of the **Cheats Manager** dialog is now deferred to first show, as creating it within the main window's constructor prevents the dialog from knowing the real position of its parent window, which is only properly calculated on first show. For the same reasons, the analytics prompt is now shown only when the application is ready (i.e. when the main window has been shown). | Before | After | | ------ | ----- | | <img width="1920" height="1080" alt="[Dolphin Emulator] Misplaced analytics prompt" title="[Dolphin Emulator] Misplaced analytics prompt" src="https://github.com/user-attachments/assets/c3e43b3b-cf79-4398-b531-7de6068c583e" /> | <img width="1920" height="1080" alt="[Dolphin Emulator] Centered analytics prompt" title="[Dolphin Emulator] Centered analytics prompt" src="https://github.com/user-attachments/assets/a10d06d9-7438-4032-b96c-dfcb48826349" /> | | <img width="1920" height="1080" alt="[Dolphin Emulator] Misplaced Settings dialog" title="[Dolphin Emulator] Misplaced Settings dialog" src="https://github.com/user-attachments/assets/f35b10ee-4f07-48d4-86f9-2537ad5ca7ca" /> | <img width="1920" height="1080" alt="[Dolphin Emulator] Centered Settings dialog" title="[Dolphin Emulator] Centered Settings dialog" src="https://github.com/user-attachments/assets/33e37237-77a4-44f6-a0e2-b709f65b672b" /> | | <img width="1920" height="1080" alt="[Dolphin Emulator] Misplaced Cheats Manager dialog" title="[Dolphin Emulator] Misplaced Cheats Manager dialog" src="https://github.com/user-attachments/assets/1fbd3836-5639-4d5a-b57e-e2e21f21c9db" /> | <img width="1920" height="1080" alt="[Dolphin Emulator] Centered Cheats Manager dialog" title="[Dolphin Emulator] Centered Cheats Manager dialog" src="https://github.com/user-attachments/assets/3f2b1b50-de16-49b7-bac4-c444c6cab0bc" /> |
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
// Copyright 2024 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "DolphinQt/QtUtils/QtUtils.h"
|
|
|
|
#include <QDateTimeEdit>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QScreen>
|
|
|
|
namespace QtUtils
|
|
{
|
|
|
|
void ShowFourDigitYear(QDateTimeEdit* widget)
|
|
{
|
|
if (!widget->displayFormat().contains(QStringLiteral("yyyy")))
|
|
{
|
|
// Always show the full year, no matter what the locale specifies. Otherwise, two-digit years
|
|
// will always be interpreted as in the 21st century.
|
|
widget->setDisplayFormat(
|
|
widget->displayFormat().replace(QStringLiteral("yy"), QStringLiteral("yyyy")));
|
|
}
|
|
}
|
|
|
|
QWidget* CreateIconWarning(QWidget* parent, QStyle::StandardPixmap standard_pixmap, QLabel* label)
|
|
{
|
|
const auto size = QFontMetrics(parent->font()).height() * 5 / 4;
|
|
|
|
auto* const icon = new QLabel{};
|
|
icon->setPixmap(parent->style()->standardIcon(standard_pixmap).pixmap(size, size));
|
|
|
|
auto* const widget = new QWidget;
|
|
auto* const layout = new QHBoxLayout{widget};
|
|
layout->addWidget(icon);
|
|
layout->addWidget(label, 1);
|
|
return widget;
|
|
}
|
|
|
|
void AdjustSizeWithinScreen(QWidget* widget)
|
|
{
|
|
const auto screen_size = widget->screen()->availableSize();
|
|
|
|
const auto adj_screen_size = screen_size * 9 / 10;
|
|
|
|
widget->resize(widget->sizeHint().boundedTo(adj_screen_size));
|
|
|
|
CenterOnParentWindow(widget);
|
|
}
|
|
|
|
void CenterOnParentWindow(QWidget* const widget)
|
|
{
|
|
// Find the top-level window.
|
|
const QWidget* const parent_widget{widget->parentWidget()};
|
|
if (!parent_widget)
|
|
return;
|
|
const QWidget* const window{parent_widget->window()};
|
|
|
|
// Calculate position based on the widgets' size and position.
|
|
const QRect window_geometry{window->geometry()};
|
|
const QSize window_size{window_geometry.size()};
|
|
const QPoint window_pos{window_geometry.topLeft()};
|
|
const QRect geometry{widget->geometry()};
|
|
const QSize size{geometry.size()};
|
|
const QPoint offset{(window_size.width() - size.width()) / 2,
|
|
(window_size.height() - size.height()) / 2};
|
|
const QPoint pos{window_pos + offset};
|
|
|
|
widget->setGeometry(QRect(pos, size));
|
|
}
|
|
|
|
} // namespace QtUtils
|