Fix main pane highlight
This commit is contained in:
parent
49966e06ad
commit
aafbecfdda
20
src/gui/Base/HSortFilterProxyModel.qml
Normal file
20
src/gui/Base/HSortFilterProxyModel.qml
Normal file
|
@ -0,0 +1,20 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.12
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
SortFilterProxyModel {
|
||||
function findIndex(id) {
|
||||
for (let i = 0; i < count; i++)
|
||||
if (get(i).id === id) return i
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function find(id) {
|
||||
for (let i = 0; i < count; i++)
|
||||
if (get(i).id === id) return get(i)
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import QtQuick.Layouts 1.12
|
|||
|
||||
HTile {
|
||||
id: tile
|
||||
onActivated: view.currentIndex = model.index
|
||||
onLeftClicked: {
|
||||
view.highlightRangeMode = ListView.NoHighlightRange
|
||||
view.highlightMoveDuration = 0
|
||||
|
|
|
@ -43,9 +43,12 @@ HTileDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
onActivated: pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": model.id }
|
||||
)
|
||||
onActivated: {
|
||||
pageLoader.showPage(
|
||||
"AccountSettings/AccountSettings", { "userId": model.id }
|
||||
)
|
||||
mainPaneList.detachedCurrentIndex = false
|
||||
}
|
||||
|
||||
|
||||
readonly property alias addChat: addChat
|
||||
|
@ -54,18 +57,6 @@ HTileDelegate {
|
|||
(window.uiState.collapseAccounts[model.id] || false) &&
|
||||
! mainPane.filter
|
||||
|
||||
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 setCollapse(collapse) {
|
||||
window.uiState.collapseAccounts[model.id] = collapse
|
||||
|
@ -80,16 +71,6 @@ 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
|
||||
|
|
|
@ -36,7 +36,7 @@ Column {
|
|||
height: contentHeight
|
||||
interactive: false
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
model: HSortFilterProxyModel {
|
||||
sourceModel: ModelStore.get(accountRooms.userId, "rooms")
|
||||
|
||||
filters: [
|
||||
|
@ -60,6 +60,19 @@ Column {
|
|||
|
||||
highlight: null // managed by the AccountRoomsList
|
||||
|
||||
|
||||
Binding on currentIndex {
|
||||
value:
|
||||
window.uiState.page === "Pages/Chat/Chat.qml" &&
|
||||
window.uiState.pageProperties.userId === userId ?
|
||||
|
||||
roomList.model.findIndex(window.uiState.pageProperties.roomId)
|
||||
|| -1 :
|
||||
-1
|
||||
|
||||
when: ! view.detachedCurrentIndex
|
||||
}
|
||||
|
||||
Behavior on height { HNumberAnimation {} }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.12
|
||||
import SortFilterProxyModel 0.2
|
||||
import ".."
|
||||
import "../Base"
|
||||
|
||||
|
@ -55,10 +54,15 @@ HListView {
|
|||
}
|
||||
|
||||
|
||||
property bool detachedCurrentIndex: false
|
||||
|
||||
readonly property Room selectedRoom:
|
||||
currentItem ? currentItem.roomList.currentItem : null
|
||||
|
||||
|
||||
function previous() {
|
||||
detachedCurrentIndex = true
|
||||
|
||||
if (! mainPane.filter) {
|
||||
_previous()
|
||||
return
|
||||
|
@ -96,13 +100,15 @@ HListView {
|
|||
|
||||
if (currentAccount.collapsed || selectedIsFirst || noRooms) {
|
||||
// Have the account itself be selected
|
||||
roomList.currentIndex = -1
|
||||
roomList.currentIndex = -1 // XXX
|
||||
} else {
|
||||
roomList.decrementCurrentIndex()
|
||||
}
|
||||
}
|
||||
|
||||
function next() {
|
||||
detachedCurrentIndex = true
|
||||
|
||||
if (! mainPane.filter) {
|
||||
_next()
|
||||
return
|
||||
|
@ -142,7 +148,7 @@ HListView {
|
|||
const noRooms = roomList.count === 0
|
||||
|
||||
if (currentAccount.collapsed || selectedIsLast || noRooms) {
|
||||
roomList.currentIndex = -1
|
||||
roomList.currentIndex = -1 // XXX
|
||||
mainPaneList.incrementCurrentIndex()
|
||||
} else {
|
||||
roomList.incrementCurrentIndex()
|
||||
|
@ -159,20 +165,22 @@ HListView {
|
|||
selectedRoom ?
|
||||
currentItem.roomList.currentItem.activated() :
|
||||
currentItem.account.activated()
|
||||
|
||||
detachedCurrentIndex = false
|
||||
}
|
||||
|
||||
function accountSettings() {
|
||||
if (! currentItem) next()
|
||||
|
||||
currentItem.roomList.currentIndex = -1
|
||||
currentItem.account.activated()
|
||||
|
||||
detachedCurrentIndex = false
|
||||
}
|
||||
|
||||
function addNewChat() {
|
||||
if (! currentItem) next()
|
||||
|
||||
currentItem.roomList.currentIndex = -1
|
||||
currentItem.account.addChat.clicked()
|
||||
|
||||
detachedCurrentIndex = false
|
||||
}
|
||||
|
||||
function setCollapseAccount(collapse) {
|
||||
|
@ -187,17 +195,20 @@ HListView {
|
|||
currentItem.account.toggleCollapse()
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
if (selectedRoom) currentItem.roomList.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()
|
||||
}
|
||||
Binding on currentIndex {
|
||||
value:
|
||||
[
|
||||
"Pages/Chat/Chat.qml",
|
||||
"Pages/AddChat/AddChat.qml",
|
||||
"Pages/AccountSettings/AccountSettings.qml",
|
||||
].includes(window.uiState.page) ?
|
||||
|
||||
model.findIndex(window.uiState.pageProperties.userId) || -1 :
|
||||
-1
|
||||
|
||||
when: ! detachedCurrentIndex
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: activateLimiter
|
||||
|
|
|
@ -19,10 +19,7 @@ HRowLayout {
|
|||
icon.name: "add-account"
|
||||
toolTip.text: qsTr("Add another account")
|
||||
backgroundColor: theme.mainPane.settingsButton.background
|
||||
onClicked: {
|
||||
mainPaneList.clearSelection()
|
||||
pageLoader.showPage("AddAccount/AddAccount")
|
||||
}
|
||||
onClicked: pageLoader.showPage("AddAccount/AddAccount")
|
||||
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
|
|
|
@ -136,8 +136,8 @@ HTileDelegate {
|
|||
}
|
||||
|
||||
onActivated: {
|
||||
becomeSelected()
|
||||
pageLoader.showRoom(userId, model.id)
|
||||
mainPaneList.detachedCurrentIndex = false
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,32 +152,6 @@ 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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,13 @@ QtObject {
|
|||
ListModel {
|
||||
property var modelId
|
||||
|
||||
function findIndex(id) {
|
||||
for (let i = 0; i < count; i++)
|
||||
if (get(i).id === id) return i
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function find(id) {
|
||||
for (let i = 0; i < count; i++)
|
||||
if (get(i).id === id) return get(i)
|
||||
|
|
|
@ -73,7 +73,6 @@ HLoader {
|
|||
window.uiState.page = componentUrl
|
||||
window.uiState.pageProperties = properties
|
||||
window.uiStateChanged()
|
||||
mainUI.mainPane.mainPaneList.forceUpdateSelection()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ HColumnLayout {
|
|||
id: memberList
|
||||
clip: true
|
||||
|
||||
model: SortFilterProxyModel {
|
||||
model: HSortFilterProxyModel {
|
||||
sourceModel: ModelStore.get(chat.userId, chat.roomId, "members")
|
||||
|
||||
filters: ExpressionFilter {
|
||||
|
|
|
@ -182,12 +182,6 @@ Rectangle {
|
|||
|
||||
|
||||
model: ModelStore.get(chat.userId, chat.roomId, "events")
|
||||
// model: HSortFilterProxy {
|
||||
// model: ModelStore.get(chat.userId, chat.roomId, "events")
|
||||
// comparator: "date"
|
||||
// descendingSort: true
|
||||
// }
|
||||
|
||||
delegate: EventDelegate {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user