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
|
2018-08-06 16:17:58 +00:00
|
|
|
property var currentRoom: null
|
2018-03-05 11:11:55 +00:00
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
Drawer {
|
|
|
|
id: roomDrawer
|
|
|
|
|
|
|
|
width: Math.min(item.width * 0.7, 480)
|
|
|
|
height: item.height
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
edge: Qt.RightEdge
|
|
|
|
interactive: false
|
|
|
|
|
|
|
|
ToolButton {
|
|
|
|
contentItem: MaterialIcon { icon: "\ue5c4" }
|
|
|
|
|
|
|
|
onClicked: roomDrawer.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
2018-07-07 09:38:20 +00:00
|
|
|
anchors.fill: parent
|
2018-08-09 11:58:19 +00:00
|
|
|
anchors.margins: 32
|
|
|
|
spacing: 16
|
|
|
|
|
|
|
|
ImageStatus {
|
|
|
|
width: 64
|
|
|
|
height: 64
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
|
|
|
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
|
|
|
Label {
|
2018-08-09 11:58:19 +00:00
|
|
|
width: parent.width
|
2018-08-10 10:58:53 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2018-08-09 11:58:19 +00:00
|
|
|
text: currentRoom && currentRoom.id ? currentRoom.id : ""
|
|
|
|
}
|
|
|
|
|
2018-08-10 10:58:53 +00:00
|
|
|
Label {
|
|
|
|
width: parent.width
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
text: currentRoom && currentRoom.canonicalAlias ? currentRoom.canonicalAlias : "No Canonical Alias"
|
|
|
|
}
|
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
RowLayout {
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: roomNameField
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: currentRoom && currentRoom.name ? currentRoom.name : ""
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemDelegate {
|
|
|
|
Layout.preferredWidth: height
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
contentItem: MaterialIcon { icon: "\ue5ca" }
|
|
|
|
|
|
|
|
onClicked: currentRoom.setName(roomNameField.text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: roomTopicField
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: currentRoom && currentRoom.topic ? currentRoom.topic : ""
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemDelegate {
|
|
|
|
Layout.preferredWidth: height
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
contentItem: MaterialIcon { icon: "\ue5ca" }
|
|
|
|
|
|
|
|
onClicked: currentRoom.setTopic(roomTopicField.text)
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
2018-07-07 09:38:20 +00:00
|
|
|
}
|
2018-08-09 11:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Pane {
|
|
|
|
anchors.fill: parent
|
|
|
|
padding: 0
|
|
|
|
|
|
|
|
background: Label {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: !currentRoom
|
|
|
|
text: "Please choose a room."
|
|
|
|
}
|
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
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
Rectangle {
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 80
|
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-08-10 10:58:53 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
onClicked: roomDrawer.open()
|
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
2018-08-09 11:58:19 +00:00
|
|
|
anchors.margins: 16
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
spacing: 16
|
|
|
|
|
|
|
|
ImageStatus {
|
2018-07-22 04:09:15 +00:00
|
|
|
Layout.preferredWidth: height
|
2018-07-07 09:38:20 +00:00
|
|
|
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
|
|
|
|
2018-08-10 10:58:53 +00:00
|
|
|
ColumnLayout {
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2018-08-10 10:58:53 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
|
|
|
visible: parent.width > 80
|
2018-07-07 09:38:20 +00:00
|
|
|
|
|
|
|
Label {
|
2018-08-10 10:58:53 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: 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 {
|
2018-08-10 10:58:53 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: 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-08-04 16:15:58 +00:00
|
|
|
RowLayout {
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.leftMargin: 16
|
2018-07-09 02:45:26 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
z: -10
|
2018-08-04 12:40:23 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
spacing: 0
|
2018-07-09 02:45:26 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
ListView {
|
|
|
|
id: messageListView
|
2018-02-23 14:39:14 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
displayMarginBeginning: 40
|
|
|
|
displayMarginEnd: 40
|
|
|
|
verticalLayoutDirection: ListView.BottomToTop
|
|
|
|
spacing: 8
|
2018-07-30 05:52:20 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
boundsBehavior: Flickable.DragOverBounds
|
|
|
|
|
|
|
|
model: MessageEventModel{
|
|
|
|
id: messageEventModel
|
|
|
|
room: currentRoom
|
2018-07-30 05:52:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 06:08:04 +00:00
|
|
|
delegate: Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: 8
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
readonly property bool sectionVisible: section !== aboveSection
|
|
|
|
|
|
|
|
width: parent.width * 0.8
|
|
|
|
visible: sectionVisible
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
spacing: 8
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
height:2
|
|
|
|
color: Material.accent
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: section
|
|
|
|
color: Material.accent
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
height:2
|
|
|
|
color: Material.accent
|
|
|
|
}
|
2018-08-04 16:15:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 06:08:04 +00:00
|
|
|
MessageDelegate {}
|
2018-07-29 16:00:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
ScrollBar.vertical: messageListViewScrollBar
|
2018-07-09 06:16:32 +00:00
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(20) : {}
|
2018-08-04 16:15:58 +00:00
|
|
|
onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {}
|
2018-07-08 12:54:06 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
RoundButton {
|
|
|
|
id: goTopFab
|
|
|
|
width: height
|
|
|
|
height: 64
|
|
|
|
visible: !parent.atYEnd
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
contentItem: MaterialIcon {
|
|
|
|
anchors.fill: parent
|
|
|
|
icon: "\ue313"
|
|
|
|
color: "white"
|
|
|
|
}
|
|
|
|
|
|
|
|
opacity: pressed ? 1 : hovered ? 0.7 : 0.4
|
|
|
|
Material.background: Qt.lighter(Material.accent)
|
|
|
|
|
|
|
|
onClicked: parent.positionViewAtBeginning()
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
Behavior on opacity { NumberAnimation { duration: 200 } }
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
ScrollBar {
|
|
|
|
id: messageListViewScrollBar
|
2018-07-09 05:36:28 +00:00
|
|
|
|
2018-08-04 16:15:58 +00:00
|
|
|
Layout.preferredWidth: 16
|
|
|
|
Layout.fillHeight: true
|
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 {
|
|
|
|
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
|
2018-07-15 08:02:26 +00:00
|
|
|
selectMultiple: false
|
2018-07-10 06:34:17 +00:00
|
|
|
onAccepted: {
|
2018-07-17 08:18:50 +00:00
|
|
|
currentRoom.uploadFile(fileUrl, fileUrl, matriqueController.getMIME(fileUrl))
|
2018-07-17 06:14:48 +00:00
|
|
|
var fileTransferProgressCallback = function(id, sent, total) {
|
2018-07-17 08:18:50 +00:00
|
|
|
if (id == fileUrl) { inputField.progress = sent / total }
|
2018-07-17 06:14:48 +00:00
|
|
|
}
|
|
|
|
var completedCallback = function(id, localFile, mxcUrl) {
|
2018-07-17 08:18:50 +00:00
|
|
|
if (id == fileUrl) {
|
2018-07-17 06:14:48 +00:00
|
|
|
matriqueController.postFile(currentRoom, localFile, mxcUrl)
|
|
|
|
inputField.progress = 0
|
|
|
|
currentRoom.fileTransferCompleted.disconnect(fileTransferProgressCallback)
|
|
|
|
currentRoom.fileTransferCompleted.disconnect(completedCallback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentRoom.fileTransferProgress.connect(fileTransferProgressCallback)
|
|
|
|
currentRoom.fileTransferCompleted.connect(completedCallback)
|
2018-07-10 06:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
TextField {
|
2018-07-17 06:14:48 +00:00
|
|
|
property real progress: 0
|
|
|
|
|
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
|
|
|
|
|
2018-07-29 16:00:41 +00:00
|
|
|
Keys.onReturnPressed: {
|
|
|
|
if (inputField.text) {
|
|
|
|
inputField.postMessage(inputField.text)
|
|
|
|
inputField.text = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 11:58:19 +00:00
|
|
|
background: Rectangle {
|
|
|
|
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
|
|
|
|
|
2018-07-17 06:14:48 +00:00
|
|
|
Rectangle {
|
2018-07-20 14:36:19 +00:00
|
|
|
z: 5
|
2018-07-17 06:14:48 +00:00
|
|
|
width: inputField.width * inputField.progress
|
|
|
|
height: parent.height
|
|
|
|
color: Material.accent
|
|
|
|
opacity: 0.4
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 14:00:27 +00:00
|
|
|
|
|
|
|
function postMessage(text) {
|
2018-07-12 11:40:16 +00:00
|
|
|
if (text.trim().length === 0) { return }
|
|
|
|
if(!currentRoom) { return }
|
2018-07-09 14:00:27 +00:00
|
|
|
|
|
|
|
var PREFIX_ME = '/me '
|
2018-07-12 11:40:16 +00:00
|
|
|
var PREFIX_NOTICE = '/notice '
|
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-08-04 12:40:23 +00:00
|
|
|
currentRoom.postMessage(text, RoomMessageEvent.Emote)
|
2018-07-11 08:07:04 +00:00
|
|
|
return
|
2018-07-09 14:00:27 +00:00
|
|
|
}
|
2018-07-12 11:40:16 +00:00
|
|
|
if (text.indexOf(PREFIX_NOTICE) === 0) {
|
|
|
|
text = text.substr(PREFIX_NOTICE.length)
|
2018-08-04 12:40:23 +00:00
|
|
|
currentRoom.postMessage(text, RoomMessageEvent.Notice)
|
2018-07-12 11:40:16 +00:00
|
|
|
return
|
|
|
|
}
|
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 = ""
|
2018-08-05 21:00:06 +00:00
|
|
|
var rainbowColor = ["#ff2b00", "#ff5500", "#ff8000", "#ffaa00", "#ffd500", "#ffff00", "#d4ff00", "#aaff00", "#80ff00", "#55ff00", "#2bff00", "#00ff00", "#00ff2b", "#00ff55", "#00ff80", "#00ffaa", "#00ffd5", "#00ffff", "#00d4ff", "#00aaff", "#007fff", "#0055ff", "#002bff", "#0000ff", "#2a00ff", "#5500ff", "#7f00ff", "#aa00ff", "#d400ff", "#ff00ff", "#ff00d4", "#ff00aa", "#ff0080", "#ff0055", "#ff002b", "#ff0000"]
|
2018-07-11 08:07:04 +00:00
|
|
|
for (var i = 0; i < text.length; i++) {
|
2018-08-05 21:00:06 +00:00
|
|
|
parsedText = parsedText + "<font color='" + rainbowColor[i % rainbowColor.length] + "'>" + text.charAt(i) + "</font>"
|
2018-07-11 08:07:04 +00:00
|
|
|
}
|
2018-08-04 12:40:23 +00:00
|
|
|
currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text)
|
2018-07-11 08:07:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (text.indexOf(PREFIX_HTML) === 0) {
|
|
|
|
text = text.substr(PREFIX_HTML.length)
|
|
|
|
var re = new RegExp("<.*?>")
|
|
|
|
var plainText = text.replace(re, "")
|
2018-08-04 12:40:23 +00:00
|
|
|
currentRoom.postHtmlMessage(plainText, text, RoomMessageEvent.Text)
|
2018-07-11 08:07:04 +00:00
|
|
|
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-08-04 12:40:23 +00:00
|
|
|
currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text)
|
2018-07-11 08:07:04 +00:00
|
|
|
return
|
2018-07-10 13:08:17 +00:00
|
|
|
}
|
2018-07-09 14:00:27 +00:00
|
|
|
|
2018-08-04 12:40:23 +00:00
|
|
|
currentRoom.postPlainText(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 {
|
2018-08-11 04:42:13 +00:00
|
|
|
id: emojiButton
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Layout.preferredWidth: height
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
contentItem: MaterialIcon { icon: "\ue24e" }
|
|
|
|
|
2018-07-13 04:06:27 +00:00
|
|
|
background: Rectangle { color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
|
2018-08-11 04:42:13 +00:00
|
|
|
|
|
|
|
onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.open()
|
|
|
|
|
|
|
|
EmojiPicker {
|
|
|
|
id: emojiPicker
|
|
|
|
|
|
|
|
parent: ApplicationWindow.overlay
|
|
|
|
|
|
|
|
x: window.width - 370
|
|
|
|
y: window.height - 440
|
|
|
|
|
|
|
|
width: 360
|
|
|
|
height: 360
|
|
|
|
|
|
|
|
textArea: inputField
|
|
|
|
}
|
2018-02-23 14:39:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|