Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI chat display item. Closed #104 #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions application/qml/desktop/ChatTitle.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import QtQuick 2.0
import QtQuick.Layouts 1.12

Row {
spacing: 7

ContactItem {
width: 44
height: 47
border.color: constants.greenColor
horizontalAlignment: Text.AlignHCenter
text: recipientName[0]
}

ContactItem {
width: 420
height: 17
text: recipientName
anchors {
top: parent.top
topMargin: 13
}
}
}
3 changes: 3 additions & 0 deletions application/qml/desktop/ContactBackgroundItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import QtQuick 2.13
import QtGraphicalEffects 1.12

Rectangle {
id: root
signal leftClicked()

RadialGradient {
anchors.fill: parent
Expand All @@ -15,5 +17,6 @@ Rectangle {
id: targetArea
anchors.fill: parent
hoverEnabled: true
onClicked: root.leftClicked()
}
}
100 changes: 78 additions & 22 deletions application/qml/desktop/HomePage.qml
Original file line number Diff line number Diff line change
@@ -1,50 +1,106 @@
import QtQuick 2.0
import QtQuick.Controls 2.0
import elevons.team 1.0
import QtQuick.Layouts 1.12

Page {
id:root
width: parent.width
height: parent.height
property string recipientID
property string recipientName

Component.onCompleted: Messenger.requestUserList()

Timer {
interval: 60000
running: true
repeat: true
onTriggered: Messenger.requestUserList()
onTriggered : Messenger.requestUserList()
}

Timer {
interval: 6000
running: true
repeat: true
onTriggered : Messenger.requestMessageList()
}

header: ToolBar {
position: ToolBar.Header
GridLayout {
anchors.fill: parent
columns: 2
rows: 3

Button {
height: parent.height
anchors.right: parent.right
text: qsTr("Sign out")
Rectangle {
id:searchField
width: 500
height: 82
Layout.row: 1
Layout.column: 1
Button {
height: parent.height
anchors.left: parent.left
text: qsTr("Sign out")

onClicked: Messenger.signOut()
onClicked: Messenger.signOut()

background: Rectangle {
color: parent.pressed ? "grey" : "skyblue"
background: Rectangle {
color: parent.pressed ? "grey" : "skyblue"
}
}
}
}

Component.onCompleted: Messenger.requestUserList()
ListView {
width: searchField.width
Layout.rowSpan: 2
Layout.row: 2
Layout.column: 1
Layout.fillHeight: true
model: ModelProvider.contactModel
clip: true
spacing: 1
delegate: ContactDelegate {
onLeftClicked: {
recipientID = model.id
recipientName = model.name
}
}
}

Rectangle {
Layout.row: 1
Layout.column: 2
Layout.fillWidth: true
height: searchField.height

ChatTitle {
anchors {
left: parent.left
leftMargin: 24
verticalCenter: parent.verticalCenter
}
}
}

MessageList {
Layout.row: 2
Layout.column: 2
Layout.fillWidth: true
Layout.fillHeight: true

model: ModelProvider.messageList
}

NewMessageForm {
Layout.row: 3
Layout.column: 2
Layout.illWidth: true
Layout.fillHeight: true

ListView {
width: 500
anchors {
top: parent.top
bottom: parent.bottom
}
model: ModelProvider.contactModel
clip: true
spacing: 1
delegate: ContactDelegate { }
}

footer: Label {
text: qsTr("Your ID: %1").arg(Messenger.userId)
}
}

36 changes: 12 additions & 24 deletions application/qml/desktop/NewMessageForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,11 @@ import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import elevons.team 1.0

GridLayout {
columns: 2
rows: 2

TextField {
id: recipientField
font.pixelSize: 11
placeholderText: qsTr("Enter recipient id...")
placeholderTextColor: "#00B4AB"
selectByMouse: true
Layout.fillWidth: true
}

RoundButton {
radius: 5
text: qsTr("Send message")
enabled: recipientField.text !== "" && typingArea.message !== ""
onClicked: {
Messenger.sendMessage(recipientField.text, typingArea.message)
typingArea.clear()
}
}

RowLayout {
TypingArea {
id: typingArea
height: 60
width: parent.width
width: parent.width - button.width
pointSize: 11
placeholderTextColor: "#00B4AB"
borderColor: "#21be2b"
Expand All @@ -38,6 +16,16 @@ GridLayout {
Layout.row: 1
}

RoundButton {
id: button
radius: 5
text: qsTr("Send message")
enabled: typingArea.message !== ""
onClicked: {
Messenger.sendMessage(recipientID, typingArea.message)
typingArea.clear()
}
}
}


1 change: 1 addition & 0 deletions application/qml/desktop/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
<file>MessageDelegate.qml</file>
<file>ContactDelegate.qml</file>
<file>ContactBackgroundItem.qml</file>
<file>ChatTitle.qml</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion application/src/messagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ QVariant MessageModel::data(const QModelIndex &index, int role) const
case TextRole:
return m_messageList[index.row()].text;
case Timestamp:
return m_messageList[index.row()].timestamp;
return (m_messageList[index.row()].timestamp.toLocalTime()).toString();
default:
return QVariant();
}
Expand Down
4 changes: 2 additions & 2 deletions application/src/messenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void Messenger::sendMessage(const QString &recipientId, const QString &text)
m_requester->sendRequest(Requester::POST, Requester::SEND_MESSAGE, jsonData);
}

void Messenger::requestMessageList(const QString &recipientId) const
void Messenger::requestMessageList()
{
QVariantMap jsonData;
jsonData["sender"] = UuidManager::getId();
jsonData["recipient"] = recipientId;
jsonData["recipient"] = userId();

m_requester->sendRequest(Requester::GET, Requester::REQUEST_MESSAGE_LIST, jsonData);
}
Expand Down
2 changes: 1 addition & 1 deletion application/src/messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Messenger : public QObject
Q_INVOKABLE void signUp(const QString &name);
Q_INVOKABLE void signOut();
Q_INVOKABLE void sendMessage(const QString &recipientId, const QString &text);
Q_INVOKABLE void requestMessageList(const QString &recipientId) const;
Q_INVOKABLE void requestMessageList();
Q_INVOKABLE void requestUserList();

QString userId() const;
Expand Down