diff --git a/.gitmodules b/.gitmodules
index 1cf9b31..e69de29 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +0,0 @@
-[submodule "matrix/libqmatrixclient"]
- path = matrix/libqmatrixclient
- url = https://github.com/QMatrixClient/libqmatrixclient
diff --git a/matrique.pro b/matrique.pro
index 7e3795f..aede152 100644
--- a/matrique.pro
+++ b/matrique.pro
@@ -1,7 +1,9 @@
QT += quick
CONFIG += c++14
+CONFIG += object_parallel_to_source
-include(matrix/libqmatrixclient/libqmatrixclient.pri)
+include(include/SortFilterProxyModel/SortFilterProxyModel.pri)
+include(include/libqmatrixclient/libqmatrixclient.pri)
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
@@ -14,12 +16,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
-SOURCES += main.cpp \
- matrix/controller.cpp \
- matrix/roomlistmodel.cpp \
- matrix/imageprovider.cpp \
- matrix/messageeventmodel.cpp \
- matrix/imageproviderconnection.cpp
+SOURCES += src/main.cpp \
+ src/controller.cpp \
+ src/roomlistmodel.cpp \
+ src/imageprovider.cpp \
+ src/messageeventmodel.cpp \
+ src/imageproviderconnection.cpp
RESOURCES += \
res.qrc
@@ -51,8 +53,8 @@ DISTFILES += \
qml/js/md.js
HEADERS += \
- matrix/controller.h \
- matrix/roomlistmodel.h \
- matrix/imageprovider.h \
- matrix/messageeventmodel.h \
- matrix/imageproviderconnection.h
+ src/controller.h \
+ src/roomlistmodel.h \
+ src/imageprovider.h \
+ src/messageeventmodel.h \
+ src/imageproviderconnection.h
diff --git a/matrix/libqmatrixclient b/matrix/libqmatrixclient
deleted file mode 160000
index e66cae5..0000000
--- a/matrix/libqmatrixclient
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e66cae5fd3e74c5839804e560332e5690709931a
diff --git a/qml/Room.qml b/qml/Room.qml
index 93bbe6a..6926d82 100644
--- a/qml/Room.qml
+++ b/qml/Room.qml
@@ -18,7 +18,7 @@ Page {
anchors.fill: parent
spacing: 0
- ListForm {
+ RoomListForm {
id: roomListForm
Layout.fillHeight: true
diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml
index 52c26ac..6bb8065 100644
--- a/qml/form/RoomForm.qml
+++ b/qml/form/RoomForm.qml
@@ -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" }
}
}
}
diff --git a/qml/form/ListForm.qml b/qml/form/RoomListForm.qml
similarity index 52%
rename from qml/form/ListForm.qml
rename to qml/form/RoomListForm.qml
index 3800c6c..1a21b63 100644
--- a/qml/form/ListForm.qml
+++ b/qml/form/RoomListForm.qml
@@ -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
+ }
}
}
}
diff --git a/res.qrc b/res.qrc
index ec127a4..ce52fb9 100644
--- a/res.qrc
+++ b/res.qrc
@@ -12,7 +12,6 @@
qml/form/RoomForm.qml
qml/Room.qml
qml/form/DetailForm.qml
- qml/form/ListForm.qml
qml/component/SideNavButton.qml
qml/component/MaterialIcon.qml
asset/img/icon.png
@@ -24,5 +23,6 @@
qml/component/DownloadableContent.qml
qml/component/FileBubble.qml
qml/component/AvatarContainer.qml
+ qml/form/RoomListForm.qml
diff --git a/matrix/controller.cpp b/src/controller.cpp
similarity index 100%
rename from matrix/controller.cpp
rename to src/controller.cpp
diff --git a/matrix/controller.h b/src/controller.h
similarity index 100%
rename from matrix/controller.h
rename to src/controller.h
diff --git a/matrix/imageprovider.cpp b/src/imageprovider.cpp
similarity index 100%
rename from matrix/imageprovider.cpp
rename to src/imageprovider.cpp
diff --git a/matrix/imageprovider.h b/src/imageprovider.h
similarity index 100%
rename from matrix/imageprovider.h
rename to src/imageprovider.h
diff --git a/matrix/imageproviderconnection.cpp b/src/imageproviderconnection.cpp
similarity index 100%
rename from matrix/imageproviderconnection.cpp
rename to src/imageproviderconnection.cpp
diff --git a/matrix/imageproviderconnection.h b/src/imageproviderconnection.h
similarity index 100%
rename from matrix/imageproviderconnection.h
rename to src/imageproviderconnection.h
diff --git a/main.cpp b/src/main.cpp
similarity index 90%
rename from main.cpp
rename to src/main.cpp
index cf8d5fa..62ee158 100644
--- a/main.cpp
+++ b/src/main.cpp
@@ -3,10 +3,10 @@
#include
#include
-#include "matrix/controller.h"
-#include "matrix/imageprovider.h"
-#include "matrix/messageeventmodel.h"
-#include "matrix/roomlistmodel.h"
+#include "controller.h"
+#include "imageprovider.h"
+#include "messageeventmodel.h"
+#include "roomlistmodel.h"
#include "room.h"
using namespace QMatrixClient;
diff --git a/matrix/messageeventmodel.cpp b/src/messageeventmodel.cpp
similarity index 100%
rename from matrix/messageeventmodel.cpp
rename to src/messageeventmodel.cpp
diff --git a/matrix/messageeventmodel.h b/src/messageeventmodel.h
similarity index 100%
rename from matrix/messageeventmodel.h
rename to src/messageeventmodel.h
diff --git a/matrix/roomlistmodel.cpp b/src/roomlistmodel.cpp
similarity index 77%
rename from matrix/roomlistmodel.cpp
rename to src/roomlistmodel.cpp
index e5d346b..a238e38 100644
--- a/matrix/roomlistmodel.cpp
+++ b/src/roomlistmodel.cpp
@@ -17,11 +17,12 @@ void RoomListModel::setConnection(QMatrixClient::Connection* connection) {
m_connection = connection;
connect(connection, &Connection::loggedOut, this,
[=] { setConnection(connection); });
-// connect(connection, &Connection::invitedRoom, this,
-// &RoomListModel::updateRoom);
-// connect(connection, &Connection::joinedRoom, this,
-// &RoomListModel::updateRoom);
-// connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom);
+ // connect(connection, &Connection::invitedRoom, this,
+ // &RoomListModel::updateRoom);
+ // connect(connection, &Connection::joinedRoom, this,
+ // &RoomListModel::updateRoom);
+ // connect(connection, &Connection::leftRoom, this,
+ // &RoomListModel::updateRoom);
connect(connection, &Connection::aboutToDeleteRoom, this,
&RoomListModel::deleteRoom);
@@ -61,22 +62,27 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
return QVariant();
}
QMatrixClient::Room* room = m_rooms.at(index.row());
- if (role == Qt::DisplayRole) {
+ if (role == NameRole) {
return room->displayName();
}
- if (role == Qt::ForegroundRole) {
- if (room->highlightCount() > 0) return QBrush(QColor("orange"));
- return QVariant();
- }
- if (role == Qt::DecorationRole) {
+ if (role == AvatarRole) {
if (room->avatarUrl().toString() != "") {
return room->avatarUrl();
}
return QVariant();
}
- if (role == Qt::StatusTipRole) {
+ if (role == TopicRole) {
return room->topic();
}
+ if (role == CategoryRole) {
+ if (room->isFavourite()) return "Favorites";
+ if (room->isLowPriority()) return "Low Priorities";
+ return "Rooms";
+ }
+ if (role == HighlightRole) {
+ if (room->highlightCount() > 0) return QBrush(QColor("orange"));
+ return QVariant();
+ }
return QVariant();
}
@@ -92,8 +98,10 @@ void RoomListModel::unreadMessagesChanged(QMatrixClient::Room* room) {
QHash RoomListModel::roleNames() const {
QHash roles;
- roles[Qt::DisplayRole] = "name";
- roles[Qt::DecorationRole] = "avatar";
- roles[Qt::StatusTipRole] = "topic";
+ roles[NameRole] = "name";
+ roles[AvatarRole] = "avatar";
+ roles[TopicRole] = "topic";
+ roles[CategoryRole] = "category";
+ roles[HighlightRole] = "highlight";
return roles;
}
diff --git a/matrix/roomlistmodel.h b/src/roomlistmodel.h
similarity index 90%
rename from matrix/roomlistmodel.h
rename to src/roomlistmodel.h
index f476471..1ccc46d 100644
--- a/matrix/roomlistmodel.h
+++ b/src/roomlistmodel.h
@@ -11,6 +11,14 @@ class RoomListModel : public QAbstractListModel {
setConnection)
public:
+ enum EventRoles {
+ NameRole = Qt::UserRole + 1,
+ AvatarRole,
+ TopicRole,
+ CategoryRole,
+ HighlightRole,
+ };
+
RoomListModel(QObject* parent = 0);
virtual ~RoomListModel();