Add an unified room list view

This is off by default and can be enabled in the setting
This commit is contained in:
Carl Schwan
2020-11-23 17:41:56 +00:00
parent 72f62b01eb
commit 5d221b995a
4 changed files with 38 additions and 15 deletions

View File

@@ -52,10 +52,10 @@ Kirigami.ScrollablePage {
model: SortFilterRoomListModel { model: SortFilterRoomListModel {
id: sortFilterRoomListModel id: sortFilterRoomListModel
sourceModel: roomListModel sourceModel: roomListModel
roomSortOrder: SortFilterRoomListModel.Categories roomSortOrder: Config.mergeRoomList ? SortFilterRoomListModel.LastActivity : SortFilterRoomListModel.Categories
} }
section.property: sortFilterRoomListModel.filterText.length === 0 ? "category" : null section.property: sortFilterRoomListModel.filterText.length === 0 && !Config.mergeRoomList ? "category" : null
section.delegate: Kirigami.ListSectionHeader { section.delegate: Kirigami.ListSectionHeader {
id: sectionHeader id: sectionHeader
action: Kirigami.Action { action: Kirigami.Action {
@@ -80,8 +80,9 @@ Kirigami.ScrollablePage {
} }
delegate: Kirigami.SwipeListItem { delegate: Kirigami.SwipeListItem {
visible: model.categoryVisible || sortFilterRoomListModel.filterText.length > 0 property bool itemVisible: model.categoryVisible || sortFilterRoomListModel.filterText.length > 0 || Config.mergeRoomList
height: model.categoryVisible || sortFilterRoomListModel.filterText.length > 0 ? implicitHeight : 0 visible: itemVisible
height: itemVisible ? implicitHeight : 0
focus: true focus: true
action: Kirigami.Action { action: Kirigami.Action {
id: enterRoomAction id: enterRoomAction

View File

@@ -20,18 +20,20 @@ Kirigami.ScrollablePage {
id: showNotifications id: showNotifications
Kirigami.FormData.label: i18n("Show Notifications:") Kirigami.FormData.label: i18n("Show Notifications:")
checked: Config.showNotifications checked: Config.showNotifications
onToggled: Config.showNotifications = checked
} }
} QQC2.RadioButton {
id: mergeRoomList
footer: RowLayout { Kirigami.FormData.label: i18n("Rooms and private chats:")
QQC2.Button { text: i18n("Separated")
Layout.alignment: Qt.AlignRight checked: Config.mergeRoomList
Layout.margins: Kirigami.Units.smallSpacing onToggled: Config.mergeRoomList = true
text: i18n("Save") }
onClicked: { QQC2.RadioButton {
Config.showNotifications = showNotifications.checked; id: mergeRoomList
Config.save(); text: i18n("Intermixed")
} checked: !Config.mergeRoomList
onToggled: Config.mergeRoomList = false
} }
} }
} }

View File

@@ -15,6 +15,10 @@
<label>Show notifications</label> <label>Show notifications</label>
<default>true</default> <default>true</default>
</entry> </entry>
<entry name="MergeRoomList" type="bool">
<label>Merge Room Lists</label>
<default>false</default>
</entry>
</group> </group>
</kcfg> </kcfg>

View File

@@ -26,6 +26,7 @@ void SortFilterRoomListModel::setRoomSortOrder(SortFilterRoomListModel::RoomSort
setSortRole(RoomListModel::NameRole); setSortRole(RoomListModel::NameRole);
else if (sortOrder == SortFilterRoomListModel::LastActivity) else if (sortOrder == SortFilterRoomListModel::LastActivity)
setSortRole(RoomListModel::LastActiveTimeRole); setSortRole(RoomListModel::LastActiveTimeRole);
invalidate();
} }
SortFilterRoomListModel::RoomSortOrder SortFilterRoomListModel::roomSortOrder() const SortFilterRoomListModel::RoomSortOrder SortFilterRoomListModel::roomSortOrder() const
@@ -35,6 +36,21 @@ SortFilterRoomListModel::RoomSortOrder SortFilterRoomListModel::roomSortOrder()
bool SortFilterRoomListModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const bool SortFilterRoomListModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{ {
if (m_sortOrder == SortFilterRoomListModel::LastActivity) {
// display favorite rooms always on top
const auto categoryLeft = static_cast<RoomType::Types>(sourceModel()->data(source_left, RoomListModel::CategoryRole).toInt());
const auto categoryRight = static_cast<RoomType::Types>(sourceModel()->data(source_right, RoomListModel::CategoryRole).toInt());
if (categoryLeft == RoomType::Types::Favorite && categoryRight == RoomType::Types::Favorite) {
return sourceModel()->data(source_left, RoomListModel::LastActiveTimeRole).toDateTime() > sourceModel()->data(source_right, RoomListModel::LastActiveTimeRole).toDateTime();
} else if (categoryLeft == RoomType::Types::Favorite) {
return true;
} else if (categoryRight == RoomType::Types::Favorite) {
return false;
}
return sourceModel()->data(source_left, RoomListModel::LastActiveTimeRole).toDateTime() > sourceModel()->data(source_right, RoomListModel::LastActiveTimeRole).toDateTime();
}
if (m_sortOrder != SortFilterRoomListModel::Categories) if (m_sortOrder != SortFilterRoomListModel::Categories)
return QSortFilterProxyModel::lessThan(source_left, source_right); return QSortFilterProxyModel::lessThan(source_left, source_right);
if (sourceModel()->data(source_left, RoomListModel::CategoryRole) != sourceModel()->data(source_right, RoomListModel::CategoryRole)) if (sourceModel()->data(source_left, RoomListModel::CategoryRole) != sourceModel()->data(source_right, RoomListModel::CategoryRole))