From bb85b52418930bad9b9fb76fe2937ec4b0a2d965 Mon Sep 17 00:00:00 2001 From: Jarrod Norwell Date: Wed, 10 Apr 2024 21:23:37 +0800 Subject: [PATCH] Added better support for Qt5 and Qt6 --- .../service/set/system_settings_server.cpp | 4 ++-- src/sudachi/bootmanager.cpp | 16 ++++++++++++++ .../configure_touch_from_button.cpp | 21 +++++++++++++++++++ src/sudachi/configuration/configure_ui.cpp | 5 +++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/set/system_settings_server.cpp b/src/core/hle/service/set/system_settings_server.cpp index 8e1d9af..d465403 100644 --- a/src/core/hle/service/set/system_settings_server.cpp +++ b/src/core/hle/service/set/system_settings_server.cpp @@ -932,14 +932,14 @@ Result ISystemSettingsServer::SetPrimaryAlbumStorage(PrimaryAlbumStorage primary Result ISystemSettingsServer::GetBatteryLot(Out out_battery_lot) { LOG_INFO(Service_SET, "called"); - *out_battery_lot = {"SUDA0EMULATOR14022024"}; + *out_battery_lot = BatteryLot{"SUDA0EMULATOR14022024"}; R_SUCCEED(); } Result ISystemSettingsServer::GetSerialNumber(Out out_console_serial) { LOG_INFO(Service_SET, "called"); - *out_console_serial = {"YUZ10000000001"}; + *out_console_serial = SerialNumber{"YUZ10000000001"}; R_SUCCEED(); } diff --git a/src/sudachi/bootmanager.cpp b/src/sudachi/bootmanager.cpp index f35e7ca..d473602 100644 --- a/src/sudachi/bootmanager.cpp +++ b/src/sudachi/bootmanager.cpp @@ -736,19 +736,35 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) { } void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { + #ifdef ENABLE_QT6 QList touch_points = event->points(); + #else + QList touch_points = event->touchPoints(); + #endif for (const auto& touch_point : touch_points) { + #ifdef ENABLE_QT6 const auto [x, y] = ScaleTouch(touch_point.position()); + #else + const auto [x, y] = ScaleTouch(touch_point.pos()); + #endif const auto [touch_x, touch_y] = MapToTouchScreen(x, y); input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id()); } } void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) { + #ifdef ENABLE_QT6 QList touch_points = event->points(); + #else + QList touch_points = event->touchPoints(); + #endif input_subsystem->GetTouchScreen()->ClearActiveFlag(); for (const auto& touch_point : touch_points) { + #ifdef ENABLE_QT6 const auto [x, y] = ScaleTouch(touch_point.position()); + #else + const auto [x, y] = ScaleTouch(touch_point.pos()); + #endif const auto [touch_x, touch_y] = MapToTouchScreen(x, y); input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id()); } diff --git a/src/sudachi/configuration/configure_touch_from_button.cpp b/src/sudachi/configuration/configure_touch_from_button.cpp index 7cf5832..ca723a5 100644 --- a/src/sudachi/configuration/configure_touch_from_button.cpp +++ b/src/sudachi/configuration/configure_touch_from_button.cpp @@ -505,7 +505,11 @@ void TouchScreenPreview::mouseMoveEvent(QMouseEvent* event) { if (!coord_label) { return; } + #ifdef ENABLE_QT6 const auto pos = MapToDeviceCoords(event->position().x(), event->position().y()); + #else + const auto pos = MapToDeviceCoords(event->x(), event->y()); + #endif if (pos) { coord_label->setText(QStringLiteral("X: %1, Y: %2").arg(pos->x()).arg(pos->y())); } else { @@ -523,7 +527,11 @@ void TouchScreenPreview::mousePressEvent(QMouseEvent* event) { if (event->button() != Qt::MouseButton::LeftButton) { return; } + #ifdef ENABLE_QT6 const auto pos = MapToDeviceCoords(event->position().x(), event->position().y()); + #else + const auto pos = MapToDeviceCoords(event->x(), event->y()); + #endif if (pos) { emit DotAdded(*pos); } @@ -539,7 +547,11 @@ bool TouchScreenPreview::eventFilter(QObject* obj, QEvent* event) { emit DotSelected(obj->property(PropId).toInt()); drag_state.dot = qobject_cast(obj); + #ifdef ENABLE_QT6 drag_state.start_pos = mouse_event->globalPosition().toPoint(); + #else + drag_state.start_pos = mouse_event->globalPos(); + #endif return true; } case QEvent::Type::MouseMove: { @@ -548,13 +560,22 @@ bool TouchScreenPreview::eventFilter(QObject* obj, QEvent* event) { } const auto mouse_event = static_cast(event); if (!drag_state.active) { + #ifdef ENABLE_QT6 drag_state.active = (mouse_event->globalPosition().toPoint() - drag_state.start_pos) .manhattanLength() >= QApplication::startDragDistance(); + #else + drag_state.active = (mouse_event->globalPos() - drag_state.start_pos) + .manhattanLength() >= QApplication::startDragDistance(); + #endif if (!drag_state.active) { break; } } + #ifdef ENABLE_QT6 auto current_pos = mapFromGlobal(mouse_event->globalPosition().toPoint()); + #else + auto current_pos = mapFromGlobal(mouse_event->globalPos()); + #endif current_pos.setX(std::clamp(current_pos.x(), contentsMargins().left(), contentsMargins().left() + contentsRect().width() - 1)); current_pos.setY(std::clamp(current_pos.y(), contentsMargins().top(), diff --git a/src/sudachi/configuration/configure_ui.cpp b/src/sudachi/configuration/configure_ui.cpp index 179ace4..aa35acf 100644 --- a/src/sudachi/configuration/configure_ui.cpp +++ b/src/sudachi/configuration/configure_ui.cpp @@ -256,8 +256,13 @@ void ConfigureUi::InitializeLanguageComboBox() { locale.truncate(locale.lastIndexOf(QLatin1Char{'.'})); locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1); const QString lang = QLocale::languageToString(QLocale(locale).language()); + #ifdef ENABLE_QT6 const QString territory = QLocale::territoryToString(QLocale(locale).territory()); ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, territory), locale); + #else + const QString country = QLocale::countryToString(QLocale(locale).country()); + ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale); + #endif } // Unlike other configuration changes, interface language changes need to be reflected on the