From 590fba7deb0978ce1b8a676e5e2de404c34bd910 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 15 Jan 2025 16:38:11 -0500 Subject: [PATCH] Always open the user details dialog in the focused window This fixes some odd UX where you tap on someone's user in a search or pinned messages window, but it opens in the NeoChat main window instead. Fixes #681 --- src/qml/Main.qml | 8 +++++--- src/utils.cpp | 11 +++++++++++ src/utils.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 156b91274..92f8dcae3 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -325,11 +325,13 @@ Kirigami.ApplicationWindow { }) } function showUserDetail(user, room) { - Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root.QQC2.ApplicationWindow.window, { + const dialog = Qt.createComponent("org.kde.neochat", "UserDetailDialog").createObject(root, { room: room, user: user, - connection: root.connection - }).open(); + connection: root.connection, + }); + dialog.parent = QmlUtils.focusedWindowItem(); // Kirigami Dialogs overwrite the parent, so we need to set it again + dialog.open(); } function load() { diff --git a/src/utils.cpp b/src/utils.cpp index 1e44a8dc2..9a14adfa4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -13,6 +13,7 @@ #include #include +#include using namespace Quotient; @@ -37,6 +38,16 @@ QColor QmlUtils::getUserColor(qreal hueF) return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1); } +QQuickItem *QmlUtils::focusedWindowItem() +{ + const auto window = qobject_cast(QGuiApplication::focusWindow()); + if (window) { + return window->contentItem(); + } else { + return nullptr; + } +} + bool Utils::isEmoji(const QString &text) { #ifdef HAVE_ICU diff --git a/src/utils.h b/src/utils.h index 6941546f9..6f5112055 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,7 @@ public: Q_INVOKABLE bool isValidJson(const QByteArray &json); Q_INVOKABLE QString escapeString(const QString &string); Q_INVOKABLE QColor getUserColor(qreal hueF); + Q_INVOKABLE QQuickItem *focusedWindowItem(); private: QmlUtils() = default;