diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-01-13 04:16:11 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-01-26 21:44:13 +0100 |
commit | aaae72a4f2936df84dbb94052c0d303a1fcc33a9 (patch) | |
tree | 8dfe774cf267beab74a0d6edd3de033cb8d49ded /src | |
parent | Initial qml root window (diff) | |
download | nheko-aaae72a4f2936df84dbb94052c0d303a1fcc33a9.tar.xz |
Fix focus and qml parenting with qml root
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatPage.cpp | 2 | ||||
-rw-r--r-- | src/ChatPage.h | 1 | ||||
-rw-r--r-- | src/MainWindow.cpp | 6 | ||||
-rw-r--r-- | src/MainWindow.h | 1 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 2 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.cpp | 11 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.h | 11 |
7 files changed, 14 insertions, 20 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index fc90e6c7..f30e0466 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -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); diff --git a/src/ChatPage.h b/src/ChatPage.h index 5e3b509d..4b7351a5 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -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); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5e7fe6ce..03a99b0f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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); diff --git a/src/MainWindow.h b/src/MainWindow.h index 04311e12..ea919f4d 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -91,7 +91,6 @@ private slots: virtual void setWindowTitle(int notificationCount); signals: - void focusChanged(const bool focused); void reload(); void secretsChanged(); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index e769fa40..6b380f79 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -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')) { diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 5d2a4443..0abd102b 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -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 diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 424d78d6..9419f224 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -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; |