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;