From 2cbedaa89204eba8ee4def65c8dc4f567611fbb2 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 5 Apr 2020 19:23:04 -0400 Subject: [PATCH] HLoader as room delegates test --- TODO.md | 1 + src/gui/MainPane/AccountRoomsDelegate.qml | 33 +++++++++++++++++-- src/gui/MainPane/AccountRoomsList.qml | 7 ++-- src/gui/MainPane/Room.qml | 8 +++-- .../PythonBridge/Privates/EventHandlers.qml | 6 ++-- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index b41d11b6..418bc958 100644 --- a/TODO.md +++ b/TODO.md @@ -148,6 +148,7 @@ ## Backend - Saving the room settings +- Optimize Model item replacement - Refetch profile after manual profile change, don't wait for a room event - Better config file format diff --git a/src/gui/MainPane/AccountRoomsDelegate.qml b/src/gui/MainPane/AccountRoomsDelegate.qml index 6afe1a39..c9821ce8 100644 --- a/src/gui/MainPane/AccountRoomsDelegate.qml +++ b/src/gui/MainPane/AccountRoomsDelegate.qml @@ -10,7 +10,8 @@ Column { // 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 int listIndex: index readonly property bool noFilterResults: @@ -53,14 +54,40 @@ Column { ] } - delegate: Room { + delegate: HLoader { + active: firstSyncDone && (inView || model.index === 0) 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 + // 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: window.uiState.page === "Pages/Chat/Chat.qml" && window.uiState.pageProperties.userId === userId diff --git a/src/gui/MainPane/AccountRoomsList.qml b/src/gui/MainPane/AccountRoomsList.qml index 4634aef4..4e2bfd31 100644 --- a/src/gui/MainPane/AccountRoomsList.qml +++ b/src/gui/MainPane/AccountRoomsList.qml @@ -71,7 +71,7 @@ HListView { property bool detachedCurrentIndex: false property bool centerToHighlight: true - readonly property Room selectedRoom: + readonly property HLoader selectedRoom: currentItem ? currentItem.roomList.currentItem : null readonly property bool hasActiveAccount: @@ -187,7 +187,8 @@ HListView { if (! currentItem) return 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() { @@ -199,7 +200,7 @@ HListView { if (! currentItem) return selectedRoom ? - currentItem.roomList.currentItem.activated() : + currentItem.roomList.currentItem.item.activated() : currentItem.account.activated() detachedCurrentIndex = false diff --git a/src/gui/MainPane/Room.qml b/src/gui/MainPane/Room.qml index aff10583..203d0dcf 100644 --- a/src/gui/MainPane/Room.qml +++ b/src/gui/MainPane/Room.qml @@ -10,10 +10,12 @@ import "../Base/HTile" HTileDelegate { id: room 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) - 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 rightPadding: theme.spacing @@ -213,6 +215,8 @@ HTileDelegate { property string userId + property QtObject model + readonly property bool joined: ! invited && ! parted readonly property bool invited: model.inviter_id && ! parted readonly property bool parted: model.left diff --git a/src/gui/PythonBridge/Privates/EventHandlers.qml b/src/gui/PythonBridge/Privates/EventHandlers.qml index d9f4e032..b98ebc14 100644 --- a/src/gui/PythonBridge/Privates/EventHandlers.qml +++ b/src/gui/PythonBridge/Privates/EventHandlers.qml @@ -50,13 +50,13 @@ QtObject { function onModelItemInserted(syncId, index, item) { - print("insert", syncId, index, item) + // print("insert", syncId, index, item) ModelStore.get(syncId).insert(index, item) } 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) model.setProperty(oldIndex, field, value) @@ -65,7 +65,7 @@ QtObject { function onModelItemDeleted(syncId, index) { - print("del", syncId, index) + // print("del", syncId, index) ModelStore.get(syncId).remove(index) }