diff --git a/.gitmodules b/.gitmodules index 26774e64..4c6e05fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "submodules/gel"] path = submodules/gel url = https://github.com/Cutehacks/gel +[submodule "submodules/SortFilterProxyModel"] + path = submodules/SortFilterProxyModel + url = https://github.com/oKcerG/SortFilterProxyModel diff --git a/harmonyqml.pro b/harmonyqml.pro index 9eee5841..21290de6 100644 --- a/harmonyqml.pro +++ b/harmonyqml.pro @@ -43,8 +43,7 @@ executables.files = $$TARGET # Libraries includes -include(submodules/qsyncable/qsyncable.pri) -include(submodules/gel/com_cutehacks_gel.pri) +include(submodules/SortFilterProxyModel/SortFilterProxyModel.pri) # Custom functions diff --git a/src/backend/models/items.py b/src/backend/models/items.py index 5ed999ec..a98eec9c 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -45,11 +45,6 @@ class Account(ModelItem): other_name = other.display_name or other.id[1:] return name.lower() < other_name.lower() - @property - def filter_string(self) -> str: - """Filter based on display name.""" - return self.display_name - @dataclass class Room(ModelItem): @@ -106,12 +101,6 @@ class Room(ModelItem): (other.display_name or other.id).lower(), ) - @property - def filter_string(self) -> str: - """Filter based on room display name, topic, and last event content.""" - - return " ".join((self.display_name, self.topic)) - @dataclass class Member(ModelItem): diff --git a/src/gui/MainPane/Account.qml b/src/gui/MainPane/Account.qml index 1984d4b7..30aa4db0 100644 --- a/src/gui/MainPane/Account.qml +++ b/src/gui/MainPane/Account.qml @@ -12,7 +12,7 @@ HTileDelegate { bottomPadding: topPadding backgroundColor: theme.mainPane.account.background - opacity: collapsed && ! anyFilter ? + opacity: collapsed && ! mainPane.filter ? theme.mainPane.account.collapsedOpacity : 1 title.color: theme.mainPane.account.name @@ -51,8 +51,6 @@ HTileDelegate { readonly property bool collapsed: window.uiState.collapseAccounts[model.id] || false - readonly property bool anyFilter: Boolean(mainPaneList.filter) - function toggleCollapse() { window.uiState.collapseAccounts[model.id] = ! collapsed @@ -99,7 +97,7 @@ HTileDelegate { leftPadding: theme.spacing / 2 rightPadding: leftPadding - opacity: ! loading && account.anyFilter ? 0 : 1 + opacity: ! loading && mainPane.filter ? 0 : 1 visible: opacity > 0 && Layout.maximumWidth > 0 Layout.fillHeight: true diff --git a/src/gui/MainPane/AccountRoomsDelegate.qml b/src/gui/MainPane/AccountRoomsDelegate.qml index 13d9a101..86f0c8a2 100644 --- a/src/gui/MainPane/AccountRoomsDelegate.qml +++ b/src/gui/MainPane/AccountRoomsDelegate.qml @@ -1,66 +1,68 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 +import SortFilterProxyModel 0.2 import ".." import "../Base" Column { id: delegate + // visible: account.opacity > 0 property string userId: model.id readonly property HListView view: ListView.view + readonly property bool hide: + mainPane.filter && + roomList.model.count < 1 && + ! utils.filterMatches(mainPane.filter, model.display_name) Account { id: account width: parent.width view: delegate.view + + opacity: hide ? + 0 : + collapsed && ! mainPane.filter ? + theme.mainPane.account.collapsedOpacity : + 1 + scale: hide ? opacity : 1 + height: implicitHeight * (hide ? opacity : 1) + + Behavior on opacity { HNumberAnimation {} } } HListView { id: roomList width: parent.width - height: contentHeight * opacity - opacity: account.collapsed ? 0 : 1 - visible: opacity > 0 + height: hide ? 0 : contentHeight + visible: ! hide interactive: false - model: ModelStore.get(delegate.userId, "rooms") - // model: HSortFilterProxy { - // model: ModelStore.get(delegate.userId, "rooms") - // comparator: (a, b) => - // // Sort by membership, then last event date (most recent first) - // // then room display name or ID. - // // Invited rooms are first, then joined rooms, then left rooms. + model: SortFilterProxyModel { + sourceModel: ModelStore.get(delegate.userId, "rooms") - // // Left rooms may still have an inviter_id, so check left first - // [ - // a.left, - // b.inviter_id, + filters: [ + ExpressionFilter { + expression: ! account.collapsed + enabled: ! mainPane.filter + }, - // b.last_event && b.last_event.date ? - // b.last_event.date.getTime() : 0, - - // (a.display_name || a.id).toLocaleLowerCase(), - // ] < [ - // b.left, - // a.inviter_id, - - // a.last_event && a.last_event.date ? - // a.last_event.date.getTime() : 0, - - // (b.display_name || b.id).toLocaleLowerCase(), - // ] - // } + ExpressionFilter { + expression: utils.filterMatches( + mainPane.filter, model.display_name, + ) + } + ] + } delegate: Room { width: roomList.width userId: delegate.userId } - Behavior on opacity { - HNumberAnimation { easing.type: Easing.InOutCirc } - } + Behavior on height { HNumberAnimation {} } } } diff --git a/src/gui/MainPane/AccountRoomsList.qml b/src/gui/MainPane/AccountRoomsList.qml index b929bda4..73fa50a6 100644 --- a/src/gui/MainPane/AccountRoomsList.qml +++ b/src/gui/MainPane/AccountRoomsList.qml @@ -1,20 +1,13 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 +import SortFilterProxyModel 0.2 import ".." import "../Base" HListView { id: mainPaneList - model: ModelStore.get("accounts") - // model: HSortFilterProxy { - // model: ModelStore.get("accounts") - // comparator: (a, b) => - // // Sort by display name or user ID - // (a.display_name || a.id).toLocaleLowerCase() < - // (b.display_name || b.id).toLocaleLowerCase() - // } delegate: AccountRoomsDelegate { width: mainPaneList.width @@ -22,9 +15,6 @@ HListView { } - readonly property string filter: toolBar.roomFilter - - function previous(activate=true) { decrementCurrentIndex() if (activate) activateLimiter.restart() @@ -58,7 +48,7 @@ HListView { } function toggleCollapseAccount() { - if (filter) return + if (mainPane.filter) return if (! currentItem) incrementCurrentIndex() diff --git a/src/gui/MainPane/MainPane.qml b/src/gui/MainPane/MainPane.qml index 6f030f3b..e764db85 100644 --- a/src/gui/MainPane/MainPane.qml +++ b/src/gui/MainPane/MainPane.qml @@ -11,9 +11,10 @@ HDrawer { minimumSize: theme.controls.avatar.size + theme.spacing * 2 - property bool hasFocus: toolBar.filterField.activeFocus - property alias mainPaneList: mainPaneList - property alias toolBar: toolBar + readonly property bool hasFocus: toolBar.filterField.activeFocus + readonly property alias mainPaneList: mainPaneList + readonly property alias toolBar: toolBar + property alias filter: toolBar.roomFilter function toggleFocus() { diff --git a/submodules/SortFilterProxyModel b/submodules/SortFilterProxyModel new file mode 160000 index 00000000..36befddf --- /dev/null +++ b/submodules/SortFilterProxyModel @@ -0,0 +1 @@ +Subproject commit 36befddf5d57faad990e72c88c5844794f274145