From b106eafb0edab2e596a997592e75a81396f8f36c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 12 Jan 2022 19:09:46 +0100 Subject: Initial qml root window --- src/timeline/TimelineViewManager.cpp | 204 ++--------------------------------- 1 file changed, 10 insertions(+), 194 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index e689e2fa..5d2a4443 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -45,10 +44,6 @@ #include "ui/NhekoGlobalObject.h" #include "ui/UIA.h" -Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) -Q_DECLARE_METATYPE(std::vector) -Q_DECLARE_METATYPE(std::vector) - namespace msgs = mtx::events::msg; namespace { @@ -102,19 +97,6 @@ void TimelineViewManager::updateColorPalette() { userColors.clear(); - - if (ChatPage::instance()->userSettings()->theme() == QLatin1String("light")) { - view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette()); - view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), - QPalette()); - } else if (ChatPage::instance()->userSettings()->theme() == QLatin1String("dark")) { - view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette()); - view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), - QPalette()); - } else { - view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette()); - view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), nullptr); - } } QColor @@ -126,112 +108,15 @@ TimelineViewManager::userColor(QString id, QColor background) return userColors.value(idx); } -TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent) +TimelineViewManager::TimelineViewManager(CallManager *, ChatPage *parent) : QObject(parent) - , imgProvider(new MxcImageProvider()) - , colorImgProvider(new ColorImageProvider()) - , blurhashProvider(new BlurhashProvider()) - , jdenticonProvider(new JdenticonProvider()) , rooms_(new RoomlistModel(this)) , communities_(new CommunitiesModel(this)) - , callManager_(callManager) , verificationManager_(new VerificationManager(this)) , presenceEmitter(new PresenceEmitter(this)) { - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - - qRegisterMetaType>(); - - qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject, - "im.nheko", - 1, - 0, - "MtxEvent", - QStringLiteral("Can't instantiate enum!")); - qmlRegisterUncreatableMetaObject( - olm::staticMetaObject, "im.nheko", 1, 0, "Olm", QStringLiteral("Can't instantiate enum!")); - qmlRegisterUncreatableMetaObject(crypto::staticMetaObject, - "im.nheko", - 1, - 0, - "Crypto", - QStringLiteral("Can't instantiate enum!")); - qmlRegisterUncreatableMetaObject(verification::staticMetaObject, - "im.nheko", - 1, - 0, - "VerificationStatus", - QStringLiteral("Can't instantiate enum!")); - - qmlRegisterType("im.nheko", 1, 0, "DelegateChoice"); - qmlRegisterType("im.nheko", 1, 0, "DelegateChooser"); - qmlRegisterType("im.nheko", 1, 0, "NhekoDropArea"); - qmlRegisterType("im.nheko", 1, 0, "CursorShape"); - qmlRegisterType("im.nheko", 1, 0, "MxcAnimatedImage"); - qmlRegisterType("im.nheko", 1, 0, "MxcMedia"); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "DeviceVerificationFlow", - QStringLiteral("Can't create verification flow from QML!")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "UserProfileModel", - QStringLiteral("UserProfile needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "MemberList", - QStringLiteral("MemberList needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "RoomSettingsModel", - QStringLiteral("Room Settings needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", 1, 0, "Room", QStringLiteral("Room needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "ImagePackListModel", - QStringLiteral("ImagePackListModel needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "SingleImagePackModel", - QStringLiteral("SingleImagePackModel needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "InviteesModel", - QStringLiteral("InviteesModel needs to be instantiated on the C++ side")); - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "ReadReceiptsProxy", - QStringLiteral("ReadReceiptsProxy needs to be instantiated on the C++ side")); - static auto self = this; - qmlRegisterSingletonInstance("im.nheko", 1, 0, "MainWindow", MainWindow::instance()); qmlRegisterSingletonInstance("im.nheko", 1, 0, "TimelineManager", self); - qmlRegisterSingletonInstance("im.nheko", 1, 0, "UIA", UIA::instance()); qmlRegisterSingletonType( "im.nheko", 1, 0, "Rooms", [](QQmlEngine *, QJSEngine *) -> QObject * { auto ptr = new FilteredRoomlistModel(self->rooms_); @@ -247,79 +132,15 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par return ptr; }); qmlRegisterSingletonInstance("im.nheko", 1, 0, "Communities", self->communities_); - qmlRegisterSingletonInstance( - "im.nheko", 1, 0, "Settings", ChatPage::instance()->userSettings().data()); - qmlRegisterSingletonInstance( - "im.nheko", 1, 0, "CallManager", ChatPage::instance()->callManager()); - qmlRegisterSingletonType( - "im.nheko", 1, 0, "Clipboard", [](QQmlEngine *, QJSEngine *) -> QObject * { - return new Clipboard(); - }); - qmlRegisterSingletonType( - "im.nheko", 1, 0, "Nheko", [](QQmlEngine *, QJSEngine *) -> QObject * { - return new Nheko(); - }); - qmlRegisterSingletonType( - "im.nheko", 1, 0, "UserSettingsModel", [](QQmlEngine *, QJSEngine *) -> QObject * { - return new UserSettingsModel(); - }); qmlRegisterSingletonInstance("im.nheko", 1, 0, "VerificationManager", verificationManager_); qmlRegisterSingletonInstance("im.nheko", 1, 0, "Presence", presenceEmitter); - qmlRegisterSingletonType( - "im.nheko", 1, 0, "SelfVerificationStatus", [](QQmlEngine *, QJSEngine *) -> QObject * { - auto ptr = new SelfVerificationStatus(); - QObject::connect(ChatPage::instance(), - &ChatPage::initializeEmptyViews, - ptr, - &SelfVerificationStatus::invalidate); - return ptr; - }); - qRegisterMetaType(); - qRegisterMetaType>(); - - qmlRegisterUncreatableType( - "im.nheko", - 1, - 0, - "FilteredCommunitiesModel", - QStringLiteral("Use Communities.filtered() to create a FilteredCommunitiesModel")); - - qmlRegisterType("im.nheko.EmojiModel", 1, 0, "EmojiModel"); - qmlRegisterUncreatableType( - "im.nheko.EmojiModel", 1, 0, "Emoji", QStringLiteral("Used by emoji models")); - qmlRegisterUncreatableMetaObject(emoji::staticMetaObject, - "im.nheko.EmojiModel", - 1, - 0, - "EmojiCategory", - QStringLiteral("Error: Only enums")); - - qmlRegisterType("im.nheko", 1, 0, "RoomDirectoryModel"); - -#ifdef USE_QUICK_VIEW - view = new QQuickView(parent); - container = QWidget::createWindowContainer(view, parent); -#else - view = new QQuickWidget(parent); - container = view; - view->setResizeMode(QQuickWidget::SizeRootObjectToView); - container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - connect(view, &QQuickWidget::statusChanged, this, [](QQuickWidget::Status status) { - nhlog::ui()->debug("Status changed to {}", status); - }); -#endif - container->setMinimumSize(200, 200); updateColorPalette(); - view->engine()->addImageProvider(QStringLiteral("MxcImage"), imgProvider); - view->engine()->addImageProvider(QStringLiteral("colorimage"), colorImgProvider); - view->engine()->addImageProvider(QStringLiteral("blurhash"), blurhashProvider); - if (JdenticonProvider::isAvailable()) - view->engine()->addImageProvider(QStringLiteral("jdenticon"), jdenticonProvider); - view->setSource(QUrl(QStringLiteral("qrc:///qml/Root.qml"))); - - connect(parent, &ChatPage::themeChanged, this, &TimelineViewManager::updateColorPalette); + + connect(UserSettings::instance().get(), + &UserSettings::themeChanged, + this, + &TimelineViewManager::updateColorPalette); connect(parent, &ChatPage::receivedRoomDeviceVerificationRequest, verificationManager_, @@ -379,7 +200,8 @@ void TimelineViewManager::setVideoCallItem() { WebRTCSession::instance().setVideoItem( - view->rootObject()->findChild(QStringLiteral("videoCallItem"))); + MainWindow::instance()->rootObject()->findChild( + QStringLiteral("videoCallItem"))); } void @@ -401,7 +223,7 @@ TimelineViewManager::showEvent(const QString &room_id, const QString &event_id) if (auto room = rooms_->getRoomById(room_id)) { if (rooms_->currentRoom() != room) { rooms_->setCurrentRoom(room_id); - container->setFocus(); + MainWindow::instance()->requestActivate(); nhlog::ui()->info("Activated room {}", room_id.toStdString()); } @@ -439,7 +261,7 @@ TimelineViewManager::saveMedia(QString mxcUrl) QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); const QString openLocation = downloadsFolder + "/" + mxcUrl.splitRef(u'/').constLast(); - const QString filename = QFileDialog::getSaveFileName(getWidget(), {}, openLocation); + const QString filename = QFileDialog::getSaveFileName(nullptr, {}, openLocation); if (filename.isEmpty()) return; @@ -590,12 +412,6 @@ TimelineViewManager::completerFor(QString completerName, QString roomId) return nullptr; } -void -TimelineViewManager::focusTimeline() -{ - getWidget()->setFocus(); -} - void TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId) -- cgit 1.5.1 From aaae72a4f2936df84dbb94052c0d303a1fcc33a9 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 13 Jan 2022 04:16:11 +0100 Subject: Fix focus and qml parenting with qml root --- resources/qml/PrivacyScreen.qml | 2 +- resources/qml/device-verification/DeviceVerification.qml | 1 - resources/qml/dialogs/ImagePackEditorDialog.qml | 2 -- resources/qml/dialogs/ImagePackSettingsDialog.qml | 1 - resources/qml/dialogs/InputDialog.qml | 1 - resources/qml/dialogs/InviteDialog.qml | 1 - resources/qml/dialogs/JoinRoomDialog.qml | 1 - resources/qml/dialogs/PhoneNumberInputDialog.qml | 1 - resources/qml/dialogs/RawMessageDialog.qml | 1 - resources/qml/dialogs/ReadReceipts.qml | 1 - resources/qml/dialogs/RoomDirectory.qml | 1 - resources/qml/dialogs/RoomMembers.qml | 1 - resources/qml/dialogs/RoomSettings.qml | 1 - resources/qml/dialogs/UserProfile.qml | 4 ---- src/ChatPage.cpp | 2 -- src/ChatPage.h | 1 - src/MainWindow.cpp | 6 ------ src/MainWindow.h | 1 - src/timeline/TimelineModel.cpp | 2 +- src/timeline/TimelineViewManager.cpp | 11 +++++++++++ src/timeline/TimelineViewManager.h | 11 ++--------- 21 files changed, 15 insertions(+), 38 deletions(-) (limited to 'src/timeline/TimelineViewManager.cpp') diff --git a/resources/qml/PrivacyScreen.qml b/resources/qml/PrivacyScreen.qml index 6ad2a557..fb3818df 100644 --- a/resources/qml/PrivacyScreen.qml +++ b/resources/qml/PrivacyScreen.qml @@ -26,7 +26,7 @@ Item { } } - target: MainWindow + target: TimelineManager } Timer { diff --git a/resources/qml/device-verification/DeviceVerification.qml b/resources/qml/device-verification/DeviceVerification.qml index c00a0bdb..90dc9ac4 100644 --- a/resources/qml/device-verification/DeviceVerification.qml +++ b/resources/qml/device-verification/DeviceVerification.qml @@ -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 diff --git a/resources/qml/dialogs/ImagePackEditorDialog.qml b/resources/qml/dialogs/ImagePackEditorDialog.qml index 3ba04d94..9c46a490 100644 --- a/resources/qml/dialogs/ImagePackEditorDialog.qml +++ b/resources/qml/dialogs/ImagePackEditorDialog.qml @@ -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) diff --git a/resources/qml/dialogs/ImagePackSettingsDialog.qml b/resources/qml/dialogs/ImagePackSettingsDialog.qml index fa079855..18c32c41 100644 --- a/resources/qml/dialogs/ImagePackSettingsDialog.qml +++ b/resources/qml/dialogs/ImagePackSettingsDialog.qml @@ -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 diff --git a/resources/qml/dialogs/InputDialog.qml b/resources/qml/dialogs/InputDialog.qml index 63ca3181..cf1474dc 100644 --- a/resources/qml/dialogs/InputDialog.qml +++ b/resources/qml/dialogs/InputDialog.qml @@ -18,7 +18,6 @@ ApplicationWindow { modality: Qt.NonModal flags: Qt.Dialog - Component.onCompleted: Nheko.reparent(inputDialog) width: 350 height: fontMetrics.lineSpacing * 7 diff --git a/resources/qml/dialogs/InviteDialog.qml b/resources/qml/dialogs/InviteDialog.qml index 917bc856..e7dd4e3a 100644 --- a/resources/qml/dialogs/InviteDialog.qml +++ b/resources/qml/dialogs/InviteDialog.qml @@ -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" diff --git a/resources/qml/dialogs/JoinRoomDialog.qml b/resources/qml/dialogs/JoinRoomDialog.qml index 9ce6bcf1..e49f538d 100644 --- a/resources/qml/dialogs/JoinRoomDialog.qml +++ b/resources/qml/dialogs/JoinRoomDialog.qml @@ -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 diff --git a/resources/qml/dialogs/PhoneNumberInputDialog.qml b/resources/qml/dialogs/PhoneNumberInputDialog.qml index 399b11d5..9c36c98f 100644 --- a/resources/qml/dialogs/PhoneNumberInputDialog.qml +++ b/resources/qml/dialogs/PhoneNumberInputDialog.qml @@ -19,7 +19,6 @@ ApplicationWindow { modality: Qt.NonModal flags: Qt.Dialog - Component.onCompleted: Nheko.reparent(inputDialog) width: 350 height: fontMetrics.lineSpacing * 7 diff --git a/resources/qml/dialogs/RawMessageDialog.qml b/resources/qml/dialogs/RawMessageDialog.qml index 34104394..774b078b 100644 --- a/resources/qml/dialogs/RawMessageDialog.qml +++ b/resources/qml/dialogs/RawMessageDialog.qml @@ -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 diff --git a/resources/qml/dialogs/ReadReceipts.qml b/resources/qml/dialogs/ReadReceipts.qml index aced4374..da87996e 100644 --- a/resources/qml/dialogs/ReadReceipts.qml +++ b/resources/qml/dialogs/ReadReceipts.qml @@ -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 diff --git a/resources/qml/dialogs/RoomDirectory.qml b/resources/qml/dialogs/RoomDirectory.qml index f458ac51..99da63bb 100644 --- a/resources/qml/dialogs/RoomDirectory.qml +++ b/resources/qml/dialogs/RoomDirectory.qml @@ -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 { diff --git a/resources/qml/dialogs/RoomMembers.qml b/resources/qml/dialogs/RoomMembers.qml index 89cce414..55d5488b 100644 --- a/resources/qml/dialogs/RoomMembers.qml +++ b/resources/qml/dialogs/RoomMembers.qml @@ -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 diff --git a/resources/qml/dialogs/RoomSettings.qml b/resources/qml/dialogs/RoomSettings.qml index c9f2b1a1..48d2e2b7 100644 --- a/resources/qml/dialogs/RoomSettings.qml +++ b/resources/qml/dialogs/RoomSettings.qml @@ -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 { diff --git a/resources/qml/dialogs/UserProfile.qml b/resources/qml/dialogs/UserProfile.qml index 29ce2c3f..73c4e68b 100644 --- a/resources/qml/dialogs/UserProfile.qml +++ b/resources/qml/dialogs/UserProfile.qml @@ -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 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, 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(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 #include #include #include @@ -157,6 +158,16 @@ TimelineViewManager::TimelineViewManager(CallManager *, ChatPage *parent) isInitialSync_ = true; emit initialSyncChanged(true); }); + connect(qobject_cast(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 &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; -- cgit 1.5.1