Highlight main pane items on startup and clicks

This commit is contained in:
miruka 2020-02-13 06:58:13 -04:00
parent 7547703bb0
commit 7325c78c5a
5 changed files with 77 additions and 13 deletions

View File

@ -43,9 +43,12 @@ HTileDelegate {
} }
} }
onActivated: pageLoader.showPage( onActivated: {
becomeSelected()
pageLoader.showPage(
"AccountSettings/AccountSettings", { "userId": model.id } "AccountSettings/AccountSettings", { "userId": model.id }
) )
}
readonly property alias addChat: addChat readonly property alias addChat: addChat
@ -53,6 +56,18 @@ HTileDelegate {
readonly property bool collapsed: readonly property bool collapsed:
window.uiState.collapseAccounts[model.id] || false 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() { function toggleCollapse() {
window.uiState.collapseAccounts[model.id] = ! collapsed window.uiState.collapseAccounts[model.id] = ! collapsed
@ -62,15 +77,29 @@ HTileDelegate {
Behavior on opacity { HNumberAnimation {} } 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 { HButton {
id: addChat id: addChat
iconItem.small: true iconItem.small: true
icon.name: "add-chat" icon.name: "add-chat"
backgroundColor: "transparent" backgroundColor: "transparent"
toolTip.text: qsTr("Add new chat") toolTip.text: qsTr("Add new chat")
onClicked: pageLoader.showPage( onClicked: {
becomeSelected()
pageLoader.showPage(
"AddChat/AddChat", {userId: model.id}, "AddChat/AddChat", {userId: model.id},
) )
}
leftPadding: theme.spacing / 2 leftPadding: theme.spacing / 2
rightPadding: leftPadding rightPadding: leftPadding

View File

@ -6,12 +6,13 @@ import ".."
import "../Base" import "../Base"
Column { Column {
id: delegate id: accountRooms
// visible: account.opacity > 0 // visible: account.opacity > 0
property string userId: model.id property string userId: model.id
readonly property HListView view: ListView.view readonly property HListView view: ListView.view
readonly property int listIndex: index
readonly property bool hide: readonly property bool hide:
mainPane.filter && mainPane.filter &&
roomList.model.count < 1 && roomList.model.count < 1 &&
@ -25,7 +26,7 @@ Column {
Account { Account {
id: account id: account
width: parent.width width: parent.width
view: delegate.view view: accountRooms.view
opacity: hide ? opacity: hide ?
0 : 0 :
@ -46,7 +47,7 @@ Column {
interactive: false interactive: false
model: SortFilterProxyModel { model: SortFilterProxyModel {
sourceModel: ModelStore.get(delegate.userId, "rooms") sourceModel: ModelStore.get(accountRooms.userId, "rooms")
filters: [ filters: [
ExpressionFilter { ExpressionFilter {
@ -64,7 +65,7 @@ Column {
delegate: Room { delegate: Room {
width: roomList.width width: roomList.width
userId: delegate.userId userId: accountRooms.userId
} }
highlight: null // managed by the AccountRoomsList highlight: null // managed by the AccountRoomsList

View File

@ -20,8 +20,6 @@ HListView {
highlightRangeMode: ListView.NoHighlightRange highlightRangeMode: ListView.NoHighlightRange
highlight: Rectangle { highlight: Rectangle {
Component.onCompleted: print("coc")
Component.onDestruction: print("cod")
id: highlightRectangle id: highlightRectangle
y: y:
selectedRoom ? selectedRoom ?
@ -156,6 +154,12 @@ HListView {
currentIndex = -1 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 { Timer {
id: activateLimiter id: activateLimiter

View File

@ -134,7 +134,10 @@ HTileDelegate {
} }
} }
onActivated: pageLoader.showRoom(userId, model.id) onActivated: {
becomeSelected()
pageLoader.showRoom(userId, model.id)
}
property string userId property string userId
@ -148,6 +151,32 @@ HTileDelegate {
readonly property QtObject lastEvent: readonly property QtObject lastEvent:
eventModel.count > 0 ? eventModel.get(0) : null 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 {} } 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()
}
} }

View File

@ -73,6 +73,7 @@ HLoader {
window.uiState.page = componentUrl window.uiState.page = componentUrl
window.uiState.pageProperties = properties window.uiState.pageProperties = properties
window.uiStateChanged() window.uiStateChanged()
mainUI.mainPane.mainPaneList.forceUpdateSelection()
return true return true
} }