Add ChatRoom.qml and clean up code.
This commit is contained in:
parent
dcf7bed39a
commit
cbd5974d55
2
main.cpp
2
main.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include "matrix/controller.h"
|
#include "matrix/controller.h"
|
||||||
#include "matrix/roomlistmodel.h"
|
#include "matrix/roomlistmodel.h"
|
||||||
#include "matrix/imageprovider.h"
|
#include "matrix/imageprovider.h"
|
||||||
|
#include "matrix/messageeventmodel.h"
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
||||||
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
|
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
|
||||||
|
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "libqmatrixclient/connection.h"
|
||||||
|
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
namespace QMatrixClient {
|
namespace QMatrixClient {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#include "imageprovider.h"
|
#include "imageprovider.h"
|
||||||
|
|
||||||
#include "connection.h"
|
|
||||||
#include "jobs/mediathumbnailjob.h"
|
|
||||||
|
|
||||||
#include <QtCore/QWaitCondition>
|
#include <QtCore/QWaitCondition>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
|
|
||||||
|
#include "jobs/mediathumbnailjob.h"
|
||||||
|
|
||||||
|
#include "connection.h"
|
||||||
|
|
||||||
using QMatrixClient::MediaThumbnailJob;
|
using QMatrixClient::MediaThumbnailJob;
|
||||||
|
|
||||||
ImageProvider::ImageProvider(QObject *parent)
|
ImageProvider::ImageProvider(QObject *parent)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "matriqueroom.h"
|
#include "matriqueroom.h"
|
||||||
|
|
||||||
#include "user.h"
|
|
||||||
#include "events/roommessageevent.h"
|
#include "events/roommessageevent.h"
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
|
||||||
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,
|
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtQml> // for qmlRegisterType()
|
#include <QtQml> // for qmlRegisterType()
|
||||||
|
|
||||||
#include "connection.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "events/roommemberevent.h"
|
#include "events/roommemberevent.h"
|
||||||
#include "events/simplestateevents.h"
|
#include "events/simplestateevents.h"
|
||||||
#include "events/redactionevent.h"
|
#include "events/redactionevent.h"
|
||||||
|
|
||||||
|
#include "connection.h"
|
||||||
|
#include "user.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
QHash<int, QByteArray> MessageEventModel::roleNames() const
|
QHash<int, QByteArray> MessageEventModel::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
|
#include <QtGui/QIcon>
|
||||||
|
|
||||||
#include "matriqueroom.h"
|
#include "matriqueroom.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
|
|
||||||
#include <QtGui/QIcon>
|
|
||||||
|
|
||||||
RoomListModel::RoomListModel(QObject* parent)
|
RoomListModel::RoomListModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{ }
|
{ }
|
||||||
|
@ -165,9 +166,11 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const
|
||||||
// return QIcon(":/irc-channel-parted.svg");
|
// return QIcon(":/irc-channel-parted.svg");
|
||||||
// }
|
// }
|
||||||
if(room->avatarUrl().toString() != "") {
|
if(room->avatarUrl().toString() != "") {
|
||||||
|
qInfo() << "Room avatar:" << room->avatarUrl();
|
||||||
return room->avatarUrl();
|
return room->avatarUrl();
|
||||||
} else if(room->users().length() == 2) {
|
} else if(room->users().length() == 2) {
|
||||||
QMatrixClient::User* user = room->users().at(0);
|
QMatrixClient::User* user = room->users().at(0);
|
||||||
|
qInfo() << "User avatar:" << user->avatarUrl();
|
||||||
return user->avatarUrl();
|
return user->avatarUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
import QtQuick 2.10
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property Connection currentConnection: null
|
||||||
|
property var currentRoom: null
|
||||||
|
|
||||||
|
function setRoom(room) {
|
||||||
|
currentRoom = room
|
||||||
|
messageModel.changeRoom(room)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setConnection(conn) {
|
||||||
|
currentConnection = conn
|
||||||
|
messageModel.setConnection(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendLine(text) {
|
||||||
|
if(!currentRoom || !currentConnection) return
|
||||||
|
currentConnection.postMessage(currentRoom, "m.text", text)
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: chatView
|
||||||
|
anchors.fill: parent
|
||||||
|
flickableDirection: Flickable.VerticalFlick
|
||||||
|
verticalLayoutDirection: ListView.BottomToTop
|
||||||
|
model: MessageEventModel { id: messageModel }
|
||||||
|
|
||||||
|
delegate: Row {
|
||||||
|
id: message
|
||||||
|
width: parent.width
|
||||||
|
spacing: 8
|
||||||
|
|
||||||
|
Label {
|
||||||
|
id: timelabel
|
||||||
|
text: time.toLocaleTimeString("hh:mm:ss")
|
||||||
|
color: "grey"
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
width: 64
|
||||||
|
elide: Text.ElideRight
|
||||||
|
text: eventType == "message" ? author : "***"
|
||||||
|
color: eventType == "message" ? "grey" : "lightgrey"
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
text: content
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
width: parent.width - (x - parent.x) - spacing
|
||||||
|
color: eventType == "message" ? "black" : "lightgrey"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
property: "date"
|
||||||
|
labelPositioning: ViewSection.CurrentLabelAtStart
|
||||||
|
delegate: Rectangle {
|
||||||
|
width: parent.width
|
||||||
|
height: childrenRect.height
|
||||||
|
Label {
|
||||||
|
width: parent.width
|
||||||
|
text: section.toLocaleString(Qt.locale())
|
||||||
|
color: "grey"
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onAtYBeginningChanged: {
|
||||||
|
if(currentRoom && atYBeginning) currentRoom.getPreviousContent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
res.qrc
1
res.qrc
|
@ -15,5 +15,6 @@
|
||||||
<file>qml/form/DetailForm.qml</file>
|
<file>qml/form/DetailForm.qml</file>
|
||||||
<file>qml/form/ListForm.qml</file>
|
<file>qml/form/ListForm.qml</file>
|
||||||
<file>qml/Contact.qml</file>
|
<file>qml/Contact.qml</file>
|
||||||
|
<file>qml/component/ChatRoom.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in New Issue