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