HLoader as room delegates test

This commit is contained in:
miruka 2020-04-05 19:23:04 -04:00
parent eacd7f1f3e
commit 2cbedaa892
5 changed files with 44 additions and 11 deletions

View File

@ -148,6 +148,7 @@
## Backend ## Backend
- Saving the room settings - Saving the room settings
- Optimize Model item replacement
- Refetch profile after manual profile change, don't wait for a room event - Refetch profile after manual profile change, don't wait for a room event
- Better config file format - Better config file format

View File

@ -10,7 +10,8 @@ Column {
// visible: account.opacity > 0 // visible: account.opacity > 0
property string userId: model.id readonly property string userId: model.id
readonly property bool firstSyncDone: model.first_sync_done
readonly property HListView view: ListView.view readonly property HListView view: ListView.view
readonly property int listIndex: index readonly property int listIndex: index
readonly property bool noFilterResults: readonly property bool noFilterResults:
@ -53,14 +54,40 @@ Column {
] ]
} }
delegate: Room { delegate: HLoader {
active: firstSyncDone && (inView || model.index === 0)
width: roomList.width width: roomList.width
userId: accountRooms.userId height: roomList.firstDelegateHeight
// XXX: these assume the view has no spacing/margins/header/footer
readonly property int yTop:
accountRooms.y + account.height + accountRooms.spacing +
model.index * height
readonly property int yBottom: yTop + height
readonly property bool inView:
yBottom >= mainPaneList.contentY &&
yTop <= mainPaneList.contentY + mainPaneList.height
readonly property var sourceModel: model
sourceComponent: Room {
width: roomList.width
userId: accountRooms.userId
view: roomList
model: sourceModel
}
} }
highlight: null // managed by the AccountRoomsList highlight: null // managed by the AccountRoomsList
// Delete 0 must *always* be loaded, and all delegates must have the
// same height
readonly property int firstDelegateHeight:
contentItem.visibleChildren[0] ?
contentItem.visibleChildren[0].implicitHeight :
0
readonly property bool hasActiveRoom: readonly property bool hasActiveRoom:
window.uiState.page === "Pages/Chat/Chat.qml" && window.uiState.page === "Pages/Chat/Chat.qml" &&
window.uiState.pageProperties.userId === userId window.uiState.pageProperties.userId === userId

View File

@ -71,7 +71,7 @@ HListView {
property bool detachedCurrentIndex: false property bool detachedCurrentIndex: false
property bool centerToHighlight: true property bool centerToHighlight: true
readonly property Room selectedRoom: readonly property HLoader selectedRoom:
currentItem ? currentItem.roomList.currentItem : null currentItem ? currentItem.roomList.currentItem : null
readonly property bool hasActiveAccount: readonly property bool hasActiveAccount:
@ -187,7 +187,8 @@ HListView {
if (! currentItem) return if (! currentItem) return
const room = currentItem.roomList.contentItem.children[index] const room = currentItem.roomList.contentItem.children[index]
if (room && room.activated) room.activated() print(index, room, room.item)
if (room && room.item && room.item.activated) room.item.activated()
} }
function requestActivate() { function requestActivate() {
@ -199,7 +200,7 @@ HListView {
if (! currentItem) return if (! currentItem) return
selectedRoom ? selectedRoom ?
currentItem.roomList.currentItem.activated() : currentItem.roomList.currentItem.item.activated() :
currentItem.account.activated() currentItem.account.activated()
detachedCurrentIndex = false detachedCurrentIndex = false

View File

@ -10,10 +10,12 @@ import "../Base/HTile"
HTileDelegate { HTileDelegate {
id: room id: room
backgroundColor: theme.mainPane.listView.room.background backgroundColor: theme.mainPane.listView.room.background
opacity: model.left ? theme.mainPane.listView.room.leftRoomOpacity : 1 opacity:
model.left ? theme.mainPane.listView.room.leftRoomOpacity : 1
topPadding: theme.spacing / (model.index === 0 ? 1 : 1.5) topPadding: theme.spacing / (model.index === 0 ? 1 : 1.5)
bottomPadding: theme.spacing / (model.index === view.count - 1 ? 1 : 1.5) bottomPadding:
theme.spacing / (model.index === view.count - 1 ? 1 : 1.5)
leftPadding: theme.spacing * 2 leftPadding: theme.spacing * 2
rightPadding: theme.spacing rightPadding: theme.spacing
@ -213,6 +215,8 @@ HTileDelegate {
property string userId property string userId
property QtObject model
readonly property bool joined: ! invited && ! parted readonly property bool joined: ! invited && ! parted
readonly property bool invited: model.inviter_id && ! parted readonly property bool invited: model.inviter_id && ! parted
readonly property bool parted: model.left readonly property bool parted: model.left

View File

@ -50,13 +50,13 @@ QtObject {
function onModelItemInserted(syncId, index, item) { function onModelItemInserted(syncId, index, item) {
print("insert", syncId, index, item) // print("insert", syncId, index, item)
ModelStore.get(syncId).insert(index, item) ModelStore.get(syncId).insert(index, item)
} }
function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){ function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){
print("change", syncId, oldIndex, newIndex, field, value) // print("change", syncId, oldIndex, newIndex, field, value)
const model = ModelStore.get(syncId) const model = ModelStore.get(syncId)
model.setProperty(oldIndex, field, value) model.setProperty(oldIndex, field, value)
@ -65,7 +65,7 @@ QtObject {
function onModelItemDeleted(syncId, index) { function onModelItemDeleted(syncId, index) {
print("del", syncId, index) // print("del", syncId, index)
ModelStore.get(syncId).remove(index) ModelStore.get(syncId).remove(index)
} }