From 149a3721ff2071957ac44c6f33c61f122d657c71 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 31 Oct 2024 02:14:32 -0500 Subject: [PATCH] DolphinQt: Ensure skylanders QDateTimeEdit shows a four digit year without forcing dd-mm-yyyy format. --- Source/Core/DolphinQt/CMakeLists.txt | 2 ++ Source/Core/DolphinQt/DolphinQt.vcxproj | 2 ++ Source/Core/DolphinQt/QtUtils/QtUtils.cpp | 22 +++++++++++++++++++ Source/Core/DolphinQt/QtUtils/QtUtils.h | 11 ++++++++++ .../Core/DolphinQt/Settings/AdvancedPane.cpp | 9 ++------ .../SkylanderPortal/SkylanderModifyDialog.cpp | 6 +++-- 6 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 Source/Core/DolphinQt/QtUtils/QtUtils.cpp create mode 100644 Source/Core/DolphinQt/QtUtils/QtUtils.h diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 1daceff217..bd766e0453 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -318,6 +318,8 @@ add_executable(dolphin-emu QtUtils/ParallelProgressDialog.h QtUtils/PartiallyClosableTabWidget.cpp QtUtils/PartiallyClosableTabWidget.h + QtUtils/QtUtils.cpp + QtUtils/QtUtils.h QtUtils/SetWindowDecorations.cpp QtUtils/SetWindowDecorations.h QtUtils/SignalBlocking.h diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index f275175de6..f4bc2e0030 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -197,6 +197,7 @@ + @@ -404,6 +405,7 @@ + diff --git a/Source/Core/DolphinQt/QtUtils/QtUtils.cpp b/Source/Core/DolphinQt/QtUtils/QtUtils.cpp new file mode 100644 index 0000000000..049f4df505 --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/QtUtils.cpp @@ -0,0 +1,22 @@ +// Copyright 2024 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "DolphinQt/QtUtils/QtUtils.h" + +#include + +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"))); + } +} + +} // namespace QtUtils diff --git a/Source/Core/DolphinQt/QtUtils/QtUtils.h b/Source/Core/DolphinQt/QtUtils/QtUtils.h new file mode 100644 index 0000000000..2d3dce0878 --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/QtUtils.h @@ -0,0 +1,11 @@ +// Copyright 2024 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +class QDateTimeEdit; + +namespace QtUtils +{ + +void ShowFourDigitYear(QDateTimeEdit* widget); + +} diff --git a/Source/Core/DolphinQt/Settings/AdvancedPane.cpp b/Source/Core/DolphinQt/Settings/AdvancedPane.cpp index 5e4717a3c9..e15b8f2325 100644 --- a/Source/Core/DolphinQt/Settings/AdvancedPane.cpp +++ b/Source/Core/DolphinQt/Settings/AdvancedPane.cpp @@ -24,6 +24,7 @@ #include "Core/System.h" #include "DolphinQt/Config/ConfigControls/ConfigBool.h" +#include "DolphinQt/QtUtils/QtUtils.h" #include "DolphinQt/QtUtils/SignalBlocking.h" #include "DolphinQt/Settings.h" @@ -168,13 +169,7 @@ void AdvancedPane::CreateLayout() m_custom_rtc_datetime->setDisplayFormat(m_custom_rtc_datetime->displayFormat().replace( QStringLiteral("mm"), QStringLiteral("mm:ss"))); - if (!m_custom_rtc_datetime->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. - m_custom_rtc_datetime->setDisplayFormat(m_custom_rtc_datetime->displayFormat().replace( - QStringLiteral("yy"), QStringLiteral("yyyy"))); - } + QtUtils::ShowFourDigitYear(m_custom_rtc_datetime); m_custom_rtc_datetime->setDateTimeRange(QDateTime({2000, 1, 1}, {0, 0, 0}, Qt::UTC), QDateTime({2099, 12, 31}, {23, 59, 59}, Qt::UTC)); m_custom_rtc_datetime->setTimeSpec(Qt::UTC); diff --git a/Source/Core/DolphinQt/SkylanderPortal/SkylanderModifyDialog.cpp b/Source/Core/DolphinQt/SkylanderPortal/SkylanderModifyDialog.cpp index 387ee69386..f3f56e4d64 100644 --- a/Source/Core/DolphinQt/SkylanderPortal/SkylanderModifyDialog.cpp +++ b/Source/Core/DolphinQt/SkylanderPortal/SkylanderModifyDialog.cpp @@ -17,6 +17,7 @@ #include "Core/IOS/USB/Emulated/Skylanders/Skylander.h" #include "Core/System.h" +#include "DolphinQt/QtUtils/QtUtils.h" #include "DolphinQt/QtUtils/SetWindowDecorations.h" SkylanderModifyDialog::SkylanderModifyDialog(QWidget* parent, u8 slot) @@ -168,8 +169,9 @@ void SkylanderModifyDialog::PopulateSkylanderOptions(QVBoxLayout* layout) edit_nick->setValidator( new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^\\p{L}{0,15}$")), this)); edit_playtime->setValidator(new QIntValidator(0, INT_MAX, this)); - edit_last_reset->setDisplayFormat(QStringLiteral("dd/MM/yyyy hh:mm")); - edit_last_placed->setDisplayFormat(QStringLiteral("dd/MM/yyyy hh:mm")); + + QtUtils::ShowFourDigitYear(edit_last_reset); + QtUtils::ShowFourDigitYear(edit_last_placed); edit_toy_code->setToolTip(tr("The toy code for this figure. Only available for real figures.")); edit_money->setToolTip(tr("The amount of money this Skylander has. Between 0 and 65000"));