diff --git a/src/gui/MainPane/Account.qml b/src/gui/MainPane/Account.qml index aeb19f01..70ed2cbe 100644 --- a/src/gui/MainPane/Account.qml +++ b/src/gui/MainPane/Account.qml @@ -43,9 +43,12 @@ HTileDelegate { } } - onActivated: pageLoader.showPage( - "AccountSettings/AccountSettings", { "userId": model.id } - ) + onActivated: { + becomeSelected() + pageLoader.showPage( + "AccountSettings/AccountSettings", { "userId": model.id } + ) + } readonly property alias addChat: addChat @@ -53,6 +56,18 @@ HTileDelegate { readonly property bool collapsed: window.uiState.collapseAccounts[model.id] || false + readonly property bool shouldBeSelected: + ( + window.uiState.page === "Pages/AddChat/AddChat.qml" || + window.uiState.page === "Pages/AccountSettings/AccountSettings.qml" + ) && + window.uiState.pageProperties.userId === model.id + + + function becomeSelected() { + accountRooms.roomList.currentIndex = -1 + mainPaneList.currentIndex = index + } function toggleCollapse() { window.uiState.collapseAccounts[model.id] = ! collapsed @@ -62,15 +77,29 @@ HTileDelegate { Behavior on opacity { HNumberAnimation {} } + + // Trying to set the current item to ourself usually won't work from the + // first time, when this delegate is being initialized + Timer { + interval: 100 + repeat: true + running: shouldBeSelected && mainPaneList.currentIndex === -1 + triggeredOnStart: true + onTriggered: becomeSelected() + } + HButton { id: addChat iconItem.small: true icon.name: "add-chat" backgroundColor: "transparent" toolTip.text: qsTr("Add new chat") - onClicked: pageLoader.showPage( - "AddChat/AddChat", {userId: model.id}, - ) + onClicked: { + becomeSelected() + pageLoader.showPage( + "AddChat/AddChat", {userId: model.id}, + ) + } leftPadding: theme.spacing / 2 rightPadding: leftPadding diff --git a/src/gui/MainPane/AccountRoomsDelegate.qml b/src/gui/MainPane/AccountRoomsDelegate.qml index c5b60bc0..82244e80 100644 --- a/src/gui/MainPane/AccountRoomsDelegate.qml +++ b/src/gui/MainPane/AccountRoomsDelegate.qml @@ -6,12 +6,13 @@ import ".." import "../Base" Column { - id: delegate + id: accountRooms // visible: account.opacity > 0 property string userId: model.id readonly property HListView view: ListView.view + readonly property int listIndex: index readonly property bool hide: mainPane.filter && roomList.model.count < 1 && @@ -25,7 +26,7 @@ Column { Account { id: account width: parent.width - view: delegate.view + view: accountRooms.view opacity: hide ? 0 : @@ -46,7 +47,7 @@ Column { interactive: false model: SortFilterProxyModel { - sourceModel: ModelStore.get(delegate.userId, "rooms") + sourceModel: ModelStore.get(accountRooms.userId, "rooms") filters: [ ExpressionFilter { @@ -64,7 +65,7 @@ Column { delegate: Room { width: roomList.width - userId: delegate.userId + userId: accountRooms.userId } highlight: null // managed by the AccountRoomsList diff --git a/src/gui/MainPane/AccountRoomsList.qml b/src/gui/MainPane/AccountRoomsList.qml index a3508237..4d41dea6 100644 --- a/src/gui/MainPane/AccountRoomsList.qml +++ b/src/gui/MainPane/AccountRoomsList.qml @@ -20,8 +20,6 @@ HListView { highlightRangeMode: ListView.NoHighlightRange highlight: Rectangle { - Component.onCompleted: print("coc") - Component.onDestruction: print("cod") id: highlightRectangle y: selectedRoom ? @@ -156,6 +154,12 @@ HListView { currentIndex = -1 } + function forceUpdateSelection() { + // When the selection is cleared, if an account or room delegate is + // supposed to be selected, it will try to be so again. + clearSelection() + } + Timer { id: activateLimiter diff --git a/src/gui/MainPane/Room.qml b/src/gui/MainPane/Room.qml index 0560a2e0..1874cd20 100644 --- a/src/gui/MainPane/Room.qml +++ b/src/gui/MainPane/Room.qml @@ -134,7 +134,10 @@ HTileDelegate { } } - onActivated: pageLoader.showRoom(userId, model.id) + onActivated: { + becomeSelected() + pageLoader.showRoom(userId, model.id) + } property string userId @@ -148,6 +151,32 @@ HTileDelegate { readonly property QtObject lastEvent: eventModel.count > 0 ? eventModel.get(0) : null + readonly property bool shouldBeSelected: + window.uiState.page === "Pages/Chat/Chat.qml" && + window.uiState.pageProperties.userId === userId && + window.uiState.pageProperties.roomId === model.id + + + function becomeSelected() { + mainPaneList.currentIndex = accountRooms.listIndex + roomList.currentIndex = index + } + Behavior on opacity { HNumberAnimation {} } + + + // Trying to set the current item to ourself usually won't work from the + // first time, when this delegate is being initialized + Timer { + interval: 100 + repeat: true + running: + shouldBeSelected && + mainPaneList.currentIndex === -1 && + roomList.currentIndex === -1 + + triggeredOnStart: true + onTriggered: becomeSelected() + } } diff --git a/src/gui/PageLoader.qml b/src/gui/PageLoader.qml index 7f0ac9ba..f4a911c2 100644 --- a/src/gui/PageLoader.qml +++ b/src/gui/PageLoader.qml @@ -73,6 +73,7 @@ HLoader { window.uiState.page = componentUrl window.uiState.pageProperties = properties window.uiStateChanged() + mainUI.mainPane.mainPaneList.forceUpdateSelection() return true }