Alter code structure && change room list filtering mechanics && add

sorting && init categoriy for rooms.
This commit is contained in:
Black Hat
2018-07-13 12:06:27 +08:00
parent a1941784eb
commit d44383545a
18 changed files with 146 additions and 142 deletions

View File

@@ -18,7 +18,7 @@ Page {
anchors.fill: parent
spacing: 0
ListForm {
RoomListForm {
id: roomListForm
Layout.fillHeight: true

View File

@@ -19,12 +19,9 @@ Item {
background: Item {
anchors.fill: parent
visible: !currentRoom
Pane {
anchors.fill: parent
}
Pane { anchors.fill: parent }
Label {
z: 10
text: "Please choose a room."
anchors.centerIn: parent
}
@@ -43,9 +40,7 @@ Item {
Layout.fillWidth: true
Layout.preferredHeight: 80
background: Rectangle {
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
}
background: Rectangle { color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
RowLayout {
anchors.fill: parent
@@ -97,14 +92,12 @@ Item {
id: messageEventModel
room: currentRoom
onRoomChanged: {
if (room.timelineSize === 0) room.getPreviousContent(50)
}
onRoomChanged: room.timelineSize === 0 ? room.getPreviousContent(50) : {}
}
delegate: MessageDelegate {}
onAtYBeginningChanged: if (atYBeginning && currentRoom) currentRoom.getPreviousContent(50)
onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(50) : {}
ScrollBar.vertical: ScrollBar {}
@@ -128,9 +121,7 @@ Item {
onClicked: parent.positionViewAtBeginning()
Behavior on opacity {
PropertyAnimation { easing.type: Easing.Linear; duration: 200 }
}
Behavior on opacity { NumberAnimation { duration: 200 } }
}
}
@@ -174,9 +165,7 @@ Item {
bottomPadding: 0
selectByMouse: true
background: Rectangle {
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
}
background: Rectangle { color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
Keys.onReturnPressed: {
if (inputField.text) {
@@ -240,9 +229,7 @@ Item {
contentItem: MaterialIcon { icon: "\ue24e" }
background: Rectangle {
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
}
background: Rectangle { color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
}
}
}

View File

@@ -5,93 +5,15 @@ import QtGraphicalEffects 1.0
import QtQuick.Controls.Material 2.2
import QtQml.Models 2.3
import Matrique 0.1
import SortFilterProxyModel 0.2
import "qrc:/qml/component"
Item {
property alias listModel: delegateModel.model
property alias listModel: roomListProxyModel.sourceModel
property alias currentIndex: listView.currentIndex
readonly property bool mini: width <= 80 // Used as an indicator of whether the listform should be displayed as "Mini mode".
DelegateModel {
id: delegateModel
groups: [
DelegateModelGroup {
name: "filterGroup"; includeByDefault: true
}
]
filterOnGroup: "filterGroup"
delegate: ItemDelegate {
width: parent.width
height: 80
onClicked: listView.currentIndex = index
ToolTip.visible: mini && hovered
ToolTip.text: name
contentItem: RowLayout {
anchors.fill: parent
anchors.margins: 16
spacing: 16
ImageStatus {
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar ? "image://mxc/" + avatar : ""
displayText: name
opaqueBackground: true
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
visible: parent.width > 80
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: {
if (name) {
return name;
}
if (alias) {
return alias;
}
return id
}
font.pointSize: 16
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: topic ? topic : "No topic yet."
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
}
}
}
function applyFilter(filterName){
var roomCount = listModel.rowCount();
for (var i = 0; i < roomCount; i++){
var roomName = listModel.roomAt(i).displayName;
if (roomName.toLowerCase().indexOf(filterName.toLowerCase()) !== -1) {
items.addGroups(i, 1, "filterGroup");
} else {items.removeGroups(i, 1, "filterGroup");}
}
}
}
ColumnLayout {
anchors.fill: parent
spacing: 0
@@ -146,10 +68,6 @@ Item {
}
}
}
onTextChanged: {
delegateModel.applyFilter(text);
}
}
}
@@ -173,11 +91,32 @@ Item {
}
}
SortFilterProxyModel {
id: roomListProxyModel
filters: RegExpFilter {
roleName: "name"
pattern: searchField.text
caseSensitivity: Qt.CaseInsensitive
}
proxyRoles: [
ExpressionRole { name: "isFavorite"; expression: category === "Favorites" },
ExpressionRole { name: "isLowPriority"; expression: category === "Low Priorities" }
]
sorters: [
RoleSorter { roleName: "isFavorite"; sortOrder: Qt.DescendingOrder },
RoleSorter { roleName: "isLowPriority" },
StringSorter { roleName: "name" }
]
}
ListView {
id: listView
width: parent.width
height: parent.height
model: roomListProxyModel
highlight: Rectangle {
color: Material.accent
opacity: 0.2
@@ -188,7 +127,71 @@ Item {
ScrollBar.vertical: ScrollBar { id: scrollBar }
model: delegateModel
delegate: ItemDelegate {
width: parent.width
height: 80
onClicked: listView.currentIndex = index
ToolTip.visible: mini && hovered
ToolTip.text: name
contentItem: RowLayout {
anchors.fill: parent
anchors.margins: 16
spacing: 16
ImageStatus {
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar ? "image://mxc/" + avatar : ""
displayText: name
opaqueBackground: true
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
visible: parent.width > 80
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: {
if (name) {
return name;
}
if (alias) {
return alias;
}
return id
}
font.pointSize: 16
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: topic ? topic : "No topic yet."
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
}
}
}
section.property: "category"
section.criteria: ViewSection.FullString
section.delegate: Rectangle {
width: parent.width
height: 16
}
}
}
}