Added better support for Qt5 and Qt6

This commit is contained in:
Jarrod Norwell 2024-04-10 21:23:37 +08:00
parent 0dee863e9c
commit bb85b52418
4 changed files with 44 additions and 2 deletions

View file

@ -932,14 +932,14 @@ Result ISystemSettingsServer::SetPrimaryAlbumStorage(PrimaryAlbumStorage primary
Result ISystemSettingsServer::GetBatteryLot(Out<BatteryLot> out_battery_lot) {
LOG_INFO(Service_SET, "called");
*out_battery_lot = {"SUDA0EMULATOR14022024"};
*out_battery_lot = BatteryLot{"SUDA0EMULATOR14022024"};
R_SUCCEED();
}
Result ISystemSettingsServer::GetSerialNumber(Out<SerialNumber> out_console_serial) {
LOG_INFO(Service_SET, "called");
*out_console_serial = {"YUZ10000000001"};
*out_console_serial = SerialNumber{"YUZ10000000001"};
R_SUCCEED();
}

View file

@ -736,19 +736,35 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) {
}
void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
#ifdef ENABLE_QT6
QList<QTouchEvent::TouchPoint> touch_points = event->points();
#else
QList<QTouchEvent::TouchPoint> 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<QTouchEvent::TouchPoint> touch_points = event->points();
#else
QList<QTouchEvent::TouchPoint> 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());
}

View file

@ -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<QLabel*>(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<QMouseEvent*>(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(),

View file

@ -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