Fix focus and qml parenting with qml root

This commit is contained in:
Nicolas Werner 2022-01-13 04:16:11 +01:00
parent b106eafb0e
commit aaae72a4f2
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
21 changed files with 15 additions and 38 deletions

View file

@ -26,7 +26,7 @@ Item {
}
}
target: MainWindow
target: TimelineManager
}
Timer {

View file

@ -21,7 +21,6 @@ ApplicationWindow {
minimumHeight: stack.implicitHeight
width: stack.implicitWidth
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(dialog)
StackView {
id: stack

View file

@ -12,8 +12,6 @@ import QtQuick.Layouts 1.12
import im.nheko 1.0
ApplicationWindow {
//Component.onCompleted: Nheko.reparent(win)
id: win
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 2.3)

View file

@ -28,7 +28,6 @@ ApplicationWindow {
color: Nheko.colors.base
modality: Qt.NonModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(win)
Component {
id: packEditor

View file

@ -18,7 +18,6 @@ ApplicationWindow {
modality: Qt.NonModal
flags: Qt.Dialog
Component.onCompleted: Nheko.reparent(inputDialog)
width: 350
height: fontMetrics.lineSpacing * 7

View file

@ -37,7 +37,6 @@ ApplicationWindow {
palette: Nheko.colors
color: Nheko.colors.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(inviteDialogRoot)
Shortcut {
sequence: "Ctrl+Enter"

View file

@ -17,7 +17,6 @@ ApplicationWindow {
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
palette: Nheko.colors
color: Nheko.colors.window
Component.onCompleted: Nheko.reparent(joinRoomRoot)
width: 350
height: fontMetrics.lineSpacing * 7

View file

@ -19,7 +19,6 @@ ApplicationWindow {
modality: Qt.NonModal
flags: Qt.Dialog
Component.onCompleted: Nheko.reparent(inputDialog)
width: 350
height: fontMetrics.lineSpacing * 7

View file

@ -17,7 +17,6 @@ ApplicationWindow {
palette: Nheko.colors
color: Nheko.colors.window
flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(rawMessageRoot)
Shortcut {
sequence: StandardKey.Cancel

View file

@ -22,7 +22,6 @@ ApplicationWindow {
palette: Nheko.colors
color: Nheko.colors.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(readReceiptsRoot)
Shortcut {
sequence: StandardKey.Cancel

View file

@ -22,7 +22,6 @@ ApplicationWindow {
color: Nheko.colors.window
modality: Qt.WindowModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(roomDirectoryWindow)
title: qsTr("Explore Public Rooms")
Shortcut {

View file

@ -24,7 +24,6 @@ ApplicationWindow {
palette: Nheko.colors
color: Nheko.colors.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(roomMembersRoot)
Shortcut {
sequence: StandardKey.Cancel

View file

@ -23,7 +23,6 @@ ApplicationWindow {
color: Nheko.colors.window
modality: Qt.NonModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(roomSettingsDialog)
title: qsTr("Room Settings")
Shortcut {

View file

@ -13,9 +13,6 @@ import QtQuick.Window 2.13
import im.nheko 1.0
ApplicationWindow {
// this does not work in ApplicationWindow, just in Window
//transientParent: Nheko.mainwindow()
id: userProfileDialog
property var profile
@ -29,7 +26,6 @@ ApplicationWindow {
title: profile.isGlobalUserProfile ? qsTr("Global User Profile") : qsTr("Room User Profile")
modality: Qt.NonModal
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
Component.onCompleted: Nheko.reparent(userProfileDialog)
Shortcut {
sequence: StandardKey.Cancel

View file

@ -175,8 +175,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
&ChatPage::initializeEmptyViews,
view_manager_,
&TimelineViewManager::initializeRoomlist);
connect(
this, &ChatPage::chatFocusChanged, view_manager_, &TimelineViewManager::chatFocusChanged);
connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Sync &sync) {
view_manager_->sync(sync);

View file

@ -143,7 +143,6 @@ signals:
void retrievedPresence(const QString &statusMsg, mtx::presence::PresenceState state);
void themeChanged();
void decryptSidebarChanged();
void chatFocusChanged(const bool focused);
//! Signals for device verificaiton
void receivedDeviceVerificationAccept(const mtx::events::msg::KeyVerificationAccept &message);

View file

@ -130,8 +130,6 @@ MainWindow::MainWindow(QWindow *parent)
connect(chat_page_, SIGNAL(contentLoaded()), this, SLOT(removeOverlayProgressBar()));
connect(this, &MainWindow::focusChanged, chat_page_, &ChatPage::chatFocusChanged);
// connect(login_page_, &LoginPage::loginOk, this, [this](const mtx::responses::Login &res) {
// http::client()->set_user(res.user_id);
// showChatPage();
@ -342,10 +340,6 @@ MainWindow::event(QEvent *event)
if (type == QEvent::Close) {
closeEvent(static_cast<QCloseEvent *>(event));
} else if (type == QEvent::WindowActivate) {
emit focusChanged(true);
} else if (type == QEvent::WindowDeactivate) {
emit focusChanged(false);
}
return QQuickView::event(event);

View file

@ -91,7 +91,6 @@ private slots:
virtual void setWindowTitle(int notificationCount);
signals:
void focusChanged(const bool focused);
void reload();
void secretsChanged();

View file

@ -1031,7 +1031,7 @@ TimelineModel::setCurrentIndex(int index)
if (index != oldIndex)
emit currentIndexChanged(index);
if (!MainWindow::instance()->isActive())
if (MainWindow::instance() != QGuiApplication::focusWindow())
return;
if (!currentId.startsWith('m')) {

View file

@ -5,6 +5,7 @@
#include "TimelineViewManager.h"
#include <QApplication>
#include <QDropEvent>
#include <QFileDialog>
#include <QMetaType>
@ -157,6 +158,16 @@ TimelineViewManager::TimelineViewManager(CallManager *, ChatPage *parent)
isInitialSync_ = true;
emit initialSyncChanged(true);
});
connect(qobject_cast<QApplication *>(QApplication::instance()),
&QApplication::focusWindowChanged,
this,
&TimelineViewManager::focusChanged);
}
bool
TimelineViewManager::isWindowFocused() const
{
return MainWindow::instance() == QApplication::focusWindow();
}
void

View file

@ -41,8 +41,7 @@ class TimelineViewManager : public QObject
Q_PROPERTY(
bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
Q_PROPERTY(
bool isWindowFocused MEMBER isWindowFocused_ READ isWindowFocused NOTIFY focusChanged)
Q_PROPERTY(bool isWindowFocused READ isWindowFocused NOTIFY focusChanged)
public:
TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr);
@ -54,7 +53,7 @@ public:
void clearAll() { rooms_->clear(); }
Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; }
bool isWindowFocused() const { return isWindowFocused_; }
bool isWindowFocused() const;
Q_INVOKABLE void openImageOverlay(TimelineModel *room, QString mxcUrl, QString eventId);
Q_INVOKABLE void openImagePackSettings(QString roomid);
Q_INVOKABLE void saveMedia(QString mxcUrl);
@ -93,11 +92,6 @@ public slots:
void updateReadReceipts(const QString &room_id, const std::vector<QString> &event_ids);
void receivedSessionKey(const std::string &room_id, const std::string &session_id);
void initializeRoomlist();
void chatFocusChanged(bool focused)
{
isWindowFocused_ = focused;
emit focusChanged();
}
void showEvent(const QString &room_id, const QString &event_id);
@ -117,7 +111,6 @@ public slots:
private:
bool isInitialSync_ = true;
bool isWindowFocused_ = false;
RoomlistModel *rooms_ = nullptr;
CommunitiesModel *communities_ = nullptr;