Add ChatRoom.qml and clean up code.

square-messages
Black Hat 2018-03-15 17:10:27 +08:00
parent dcf7bed39a
commit cbd5974d55
8 changed files with 95 additions and 9 deletions

View File

@ -6,6 +6,7 @@
#include "matrix/controller.h"
#include "matrix/roomlistmodel.h"
#include "matrix/imageprovider.h"
#include "matrix/messageeventmodel.h"
using namespace QMatrixClient;
@ -26,6 +27,7 @@ int main(int argc, char *argv[])
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
qmlRegisterType<MessageEventModel>("Matrique", 0, 1, "MessageEventModel");
QQmlApplicationEngine engine;

View File

@ -4,6 +4,7 @@
#include <QObject>
#include "libqmatrixclient/connection.h"
#include "roomlistmodel.h"
namespace QMatrixClient {

View File

@ -1,12 +1,13 @@
#include "imageprovider.h"
#include "connection.h"
#include "jobs/mediathumbnailjob.h"
#include <QtCore/QWaitCondition>
#include <QtCore/QDebug>
#include <QMetaObject>
#include "jobs/mediathumbnailjob.h"
#include "connection.h"
using QMatrixClient::MediaThumbnailJob;
ImageProvider::ImageProvider(QObject *parent)

View File

@ -1,8 +1,9 @@
#include "matriqueroom.h"
#include "user.h"
#include "events/roommessageevent.h"
#include "user.h"
using namespace QMatrixClient;
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,

View File

@ -4,13 +4,14 @@
#include <QtCore/QDebug>
#include <QtQml> // for qmlRegisterType()
#include "connection.h"
#include "user.h"
#include "settings.h"
#include "events/roommemberevent.h"
#include "events/simplestateevents.h"
#include "events/redactionevent.h"
#include "connection.h"
#include "user.h"
#include "settings.h"
QHash<int, QByteArray> MessageEventModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();

View File

@ -1,10 +1,11 @@
#include "roomlistmodel.h"
#include <QtGui/QIcon>
#include "matriqueroom.h"
#include "connection.h"
#include "user.h"
#include <QtGui/QIcon>
RoomListModel::RoomListModel(QObject* parent)
: QAbstractListModel(parent)
{ }
@ -165,9 +166,11 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const
// return QIcon(":/irc-channel-parted.svg");
// }
if(room->avatarUrl().toString() != "") {
qInfo() << "Room avatar:" << room->avatarUrl();
return room->avatarUrl();
} else if(room->users().length() == 2) {
QMatrixClient::User* user = room->users().at(0);
qInfo() << "User avatar:" << user->avatarUrl();
return user->avatarUrl();
}
}

View File

@ -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()
}
}
}

View File

@ -15,5 +15,6 @@
<file>qml/form/DetailForm.qml</file>
<file>qml/form/ListForm.qml</file>
<file>qml/Contact.qml</file>
<file>qml/component/ChatRoom.qml</file>
</qresource>
</RCC>