2018-07-12 01:44:41 +00:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
import QtQuick.Dialogs 1.2
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtQuick.Controls.Material 2.2
|
2018-02-23 14:39:14 +00:00
|
|
|
import QtGraphicalEffects 1.0
|
2018-07-07 09:38:20 +00:00
|
|
|
import Matrique 0.1
|
2018-02-23 14:39:14 +00:00
|
|
|
import "qrc:/qml/component"
|
2018-07-09 14:00:27 +00:00
|
|
|
import "qrc:/js/md.js" as Markdown
|
2018-02-23 14:39:14 +00:00
|
|
|
|
|
|
|
Item {
|
2018-07-07 09:38:20 +00:00
|
|
|
id: item
|
|
|
|
property var currentRoom
|
2018-03-05 11:11:55 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Pane {
|
2018-02-23 14:39:14 +00:00
|
|
|
anchors.fill: parent
|
2018-07-07 09:38:20 +00:00
|
|
|
padding: 0
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
background: Item {
|
|
|
|
anchors.fill: parent
|
2018-07-09 02:45:26 +00:00
|
|
|
visible: !currentRoom
|
2018-07-07 09:38:20 +00:00
|
|
|
Pane {
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Label {
|
|
|
|
z: 10
|
|
|
|
text: "Please choose a room."
|
|
|
|
anchors.centerIn: parent
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
2018-07-07 09:38:20 +00:00
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 0
|
|
|
|
|
2018-07-09 02:45:26 +00:00
|
|
|
visible: currentRoom
|
2018-07-07 09:38:20 +00:00
|
|
|
|
|
|
|
Pane {
|
|
|
|
z: 10
|
|
|
|
padding: 16
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 80
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 16
|
|
|
|
|
|
|
|
ImageStatus {
|
|
|
|
Layout.preferredWidth: parent.height
|
|
|
|
Layout.fillHeight: true
|
2018-07-09 02:45:26 +00:00
|
|
|
source: currentRoom && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : null
|
|
|
|
displayText: currentRoom ? currentRoom.displayName : ""
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
2018-07-07 09:38:20 +00:00
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
Label {
|
|
|
|
Layout.fillWidth: true
|
2018-07-09 02:45:26 +00:00
|
|
|
text: currentRoom ? currentRoom.displayName : ""
|
2018-07-07 09:38:20 +00:00
|
|
|
font.pointSize: 16
|
|
|
|
elide: Text.ElideRight
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
Layout.fillWidth: true
|
2018-07-09 02:45:26 +00:00
|
|
|
text: currentRoom ? currentRoom.topic : ""
|
2018-07-07 09:38:20 +00:00
|
|
|
elide: Text.ElideRight
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
ListView {
|
|
|
|
id: messageListView
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: 16
|
|
|
|
displayMarginBeginning: 40
|
|
|
|
displayMarginEnd: 40
|
|
|
|
verticalLayoutDirection: ListView.BottomToTop
|
2018-07-10 04:18:21 +00:00
|
|
|
maximumFlickVelocity: 1024
|
2018-07-12 06:40:51 +00:00
|
|
|
spacing: 8
|
2018-07-09 02:45:26 +00:00
|
|
|
|
2018-07-08 05:25:46 +00:00
|
|
|
model: MessageEventModel{
|
|
|
|
id: messageEventModel
|
|
|
|
room: currentRoom
|
2018-07-08 12:54:06 +00:00
|
|
|
|
2018-07-12 01:44:41 +00:00
|
|
|
onRoomChanged: {
|
|
|
|
if (room.timelineSize === 0) room.getPreviousContent(50)
|
|
|
|
}
|
2018-07-08 05:25:46 +00:00
|
|
|
}
|
2018-07-09 02:45:26 +00:00
|
|
|
|
2018-07-10 04:18:21 +00:00
|
|
|
delegate: MessageDelegate {}
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-09 06:16:32 +00:00
|
|
|
onAtYBeginningChanged: if (atYBeginning && currentRoom) currentRoom.getPreviousContent(50)
|
|
|
|
|
2018-07-10 04:18:21 +00:00
|
|
|
ScrollBar.vertical: ScrollBar {}
|
2018-07-08 12:54:06 +00:00
|
|
|
|
2018-07-09 05:36:28 +00:00
|
|
|
Behavior on contentY {
|
|
|
|
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
|
|
|
|
}
|
|
|
|
|
2018-07-12 01:44:41 +00:00
|
|
|
// Popup {
|
|
|
|
// id: loadingPopup
|
|
|
|
|
|
|
|
// x: item.x + (item.width - width) / 2
|
|
|
|
// y: 90
|
|
|
|
|
|
|
|
// modal: true
|
|
|
|
// focus: true
|
|
|
|
|
|
|
|
// closePolicy: Popup.CloseOnEscape
|
|
|
|
|
|
|
|
// BusyIndicator { running: true }
|
|
|
|
// }
|
|
|
|
|
2018-07-09 05:36:28 +00:00
|
|
|
RoundButton {
|
|
|
|
id: goTopFab
|
|
|
|
width: height
|
2018-07-09 14:00:27 +00:00
|
|
|
height: 64
|
|
|
|
visible: !parent.atYEnd
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-07-09 14:00:27 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
2018-07-09 05:36:28 +00:00
|
|
|
|
|
|
|
contentItem: MaterialIcon {
|
|
|
|
anchors.fill: parent
|
|
|
|
icon: "\ue313"
|
|
|
|
color: "white"
|
|
|
|
}
|
|
|
|
|
2018-07-10 04:18:21 +00:00
|
|
|
opacity: pressed ? 1 : hovered ? 0.7 : 0.4
|
2018-07-09 05:36:28 +00:00
|
|
|
Material.background: Qt.lighter(Material.accent)
|
|
|
|
|
|
|
|
onClicked: parent.positionViewAtBeginning()
|
|
|
|
|
|
|
|
Behavior on opacity {
|
2018-07-09 14:00:27 +00:00
|
|
|
PropertyAnimation { easing.type: Easing.Linear; duration: 200 }
|
2018-07-09 05:36:28 +00:00
|
|
|
}
|
2018-07-08 12:54:06 +00:00
|
|
|
}
|
2018-07-07 09:38:20 +00:00
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Pane {
|
|
|
|
z: 10
|
|
|
|
padding: 16
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 80
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
ItemDelegate {
|
|
|
|
Layout.preferredWidth: height
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
contentItem: MaterialIcon { icon: "\ue226" }
|
2018-07-10 06:34:17 +00:00
|
|
|
|
|
|
|
onClicked: fileDialog.visible = true
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
id: fileDialog
|
|
|
|
title: "Please choose a file"
|
|
|
|
folder: shortcuts.home
|
|
|
|
onAccepted: {
|
|
|
|
console.log("You chose: " + fileDialog.fileUrls)
|
|
|
|
matriqueController.uploadFile(fileDialog.fileUrls)
|
|
|
|
}
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
TextField {
|
2018-07-08 05:25:46 +00:00
|
|
|
id: inputField
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
placeholderText: "Send a Message"
|
|
|
|
leftPadding: 16
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
selectByMouse: true
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
|
|
|
}
|
2018-07-08 05:25:46 +00:00
|
|
|
|
|
|
|
Keys.onReturnPressed: {
|
2018-07-09 14:00:27 +00:00
|
|
|
postMessage(inputField.text)
|
2018-07-08 05:25:46 +00:00
|
|
|
inputField.text = ""
|
|
|
|
}
|
2018-07-09 14:00:27 +00:00
|
|
|
|
|
|
|
function postMessage(text) {
|
|
|
|
if (text.trim().length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(!currentRoom) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var PREFIX_ME = '/me '
|
2018-07-11 08:07:04 +00:00
|
|
|
var PREFIX_RAINBOW = '/rainbow '
|
|
|
|
var PREFIX_HTML = '/html '
|
|
|
|
var PREFIX_MARKDOWN = '/md '
|
|
|
|
|
2018-07-09 14:00:27 +00:00
|
|
|
if (text.indexOf(PREFIX_ME) === 0) {
|
|
|
|
text = text.substr(PREFIX_ME.length)
|
2018-07-11 08:07:04 +00:00
|
|
|
currentRoom.postMessage("m.emote", text)
|
|
|
|
return
|
2018-07-09 14:00:27 +00:00
|
|
|
}
|
2018-07-10 13:08:17 +00:00
|
|
|
if (text.indexOf(PREFIX_RAINBOW) === 0) {
|
|
|
|
text = text.substr(PREFIX_RAINBOW.length)
|
|
|
|
|
2018-07-11 08:07:04 +00:00
|
|
|
var parsedText = ""
|
|
|
|
var rainbowColor = ["#ee0000", "#ff7700", "#eeee00", "#00bb00", "#0000ee", "#dd00dd", "#880088"]
|
|
|
|
for (var i = 0; i < text.length; i++) {
|
|
|
|
parsedText = parsedText + "<font color='" + rainbowColor[i % 7] + "'>" + text.charAt(i) + "</font>"
|
|
|
|
}
|
|
|
|
currentRoom.postHtmlMessage(text, parsedText, "m.text")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (text.indexOf(PREFIX_HTML) === 0) {
|
|
|
|
text = text.substr(PREFIX_HTML.length)
|
|
|
|
var re = new RegExp("<.*?>")
|
|
|
|
var plainText = text.replace(re, "")
|
|
|
|
currentRoom.postHtmlMessage(plainText, text, "m.text")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (text.indexOf(PREFIX_MARKDOWN) === 0) {
|
|
|
|
text = text.substr(PREFIX_MARKDOWN.length)
|
2018-07-10 13:08:17 +00:00
|
|
|
var parsedText = Markdown.markdown_parser(text)
|
2018-07-11 08:07:04 +00:00
|
|
|
currentRoom.postHtmlMessage(text, parsedText, "m.text")
|
|
|
|
return
|
2018-07-10 13:08:17 +00:00
|
|
|
}
|
2018-07-09 14:00:27 +00:00
|
|
|
|
2018-07-11 08:07:04 +00:00
|
|
|
currentRoom.postMessage("m.text", text)
|
2018-07-09 14:00:27 +00:00
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
ItemDelegate {
|
|
|
|
Layout.preferredWidth: height
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
contentItem: MaterialIcon { icon: "\ue24e" }
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|