Spectral/qml/form/RoomForm.qml

489 lines
16 KiB
QML
Raw Normal View History

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
import Matrique 0.1
import Matrique.Settings 0.1
import "../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 {
property var currentRoom: null
2018-03-05 11:11:55 +00:00
id: item
UserListModel {
id: userListModel
room: currentRoom
}
Drawer {
id: roomDrawer
width: Math.min(item.width * 0.7, 480)
height: item.height
2018-02-23 14:39:14 +00:00
edge: Qt.RightEdge
interactive: false
ToolButton {
contentItem: MaterialIcon { icon: "\ue5c4" }
onClicked: roomDrawer.close()
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 32
ImageStatus {
Layout.preferredWidth: 64
Layout.preferredHeight: 64
Layout.alignment: Qt.AlignHCenter
source: currentRoom && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : null
displayText: currentRoom ? currentRoom.displayName : ""
}
2018-02-23 14:39:14 +00:00
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: currentRoom && currentRoom.id ? currentRoom.id : ""
}
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: currentRoom && currentRoom.canonicalAlias ? currentRoom.canonicalAlias : "No Canonical Alias"
}
RowLayout {
Layout.fillWidth: true
TextField {
id: roomNameField
Layout.fillWidth: true
text: currentRoom && currentRoom.name ? currentRoom.name : ""
}
ItemDelegate {
Layout.preferredWidth: height
Layout.preferredHeight: parent.height
contentItem: MaterialIcon { icon: "\ue5ca" }
onClicked: currentRoom.setName(roomNameField.text)
}
}
RowLayout {
Layout.fillWidth: true
TextField {
id: roomTopicField
Layout.fillWidth: true
text: currentRoom && currentRoom.topic ? currentRoom.topic : ""
}
ItemDelegate {
Layout.preferredWidth: height
Layout.preferredHeight: parent.height
contentItem: MaterialIcon { icon: "\ue5ca" }
onClicked: currentRoom.setTopic(roomTopicField.text)
}
2018-02-23 14:39:14 +00:00
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
boundsBehavior: Flickable.DragOverBounds
delegate: ItemDelegate {
width: parent.width
height: 48
RowLayout {
anchors.fill: parent
anchors.margins: 8
2018-09-02 13:26:42 +00:00
spacing: 12
ImageStatus {
Layout.preferredWidth: height
Layout.fillHeight: true
source: avatar != "" ? "image://mxc/" + avatar : ""
displayText: name
}
Label {
Layout.fillWidth: true
text: name
}
}
}
model: userListModel
ScrollBar.vertical: ScrollBar {}
}
}
}
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
ColumnLayout {
anchors.fill: parent
spacing: 0
2018-07-09 02:45:26 +00:00
visible: currentRoom
Rectangle {
Layout.fillWidth: true
2018-09-02 13:26:42 +00:00
Layout.preferredHeight: 64
2018-09-02 13:26:42 +00:00
color: Material.accent
2018-02-23 14:39:14 +00:00
ItemDelegate {
anchors.fill: parent
onClicked: roomDrawer.open()
RowLayout {
anchors.fill: parent
2018-09-02 13:26:42 +00:00
anchors.margins: 12
2018-09-02 13:26:42 +00:00
spacing: 12
ImageStatus {
Layout.preferredWidth: height
Layout.fillHeight: true
source: currentRoom && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : null
displayText: currentRoom ? currentRoom.displayName : ""
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
2018-09-02 13:26:42 +00:00
visible: parent.width > 64
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: currentRoom ? currentRoom.displayName : ""
2018-09-02 13:26:42 +00:00
color: "white"
font.pointSize: 12
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
Label {
Layout.fillWidth: true
Layout.fillHeight: true
text: currentRoom ? currentRoom.topic : ""
2018-09-02 13:26:42 +00:00
color: "white"
elide: Text.ElideRight
wrapMode: Text.NoWrap
}
}
2018-02-23 14:39:14 +00:00
}
}
}
2018-08-04 16:15:58 +00:00
RowLayout {
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 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
2018-09-02 23:13:39 +00:00
clip: true
2018-08-04 16:15:58 +00:00
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
2018-09-04 06:58:41 +00:00
maximumFlickVelocity: 2048
2018-08-04 16:15:58 +00:00
model: MessageEventModel {
2018-08-04 16:15:58 +00:00
id: messageEventModel
room: currentRoom
2018-07-30 05:52:20 +00:00
}
2018-09-04 06:58:41 +00:00
delegate: ColumnLayout {
readonly property bool hidden: marks === EventStatus.Redacted || marks === EventStatus.Hidden
2018-09-04 06:58:41 +00:00
id: delegateColumn
width: parent.width
height: hidden ? -8 : undefined
2018-09-04 06:58:41 +00:00
2018-09-04 12:49:53 +00:00
clip: true
spacing: 8
2018-09-04 06:58:41 +00:00
Label {
Layout.alignment: Qt.AlignHCenter
2018-09-04 06:58:41 +00:00
visible: section !== aboveSection && !hidden
2018-09-04 06:58:41 +00:00
text: section
color: "white"
verticalAlignment: Text.AlignVCenter
leftPadding: 8
rightPadding: 8
topPadding: 4
bottomPadding: 4
2018-09-04 06:58:41 +00:00
background: Rectangle {
color: MSettings.darkTheme ? "#484848" : "grey"
}
2018-08-04 16:15:58 +00:00
}
2018-09-04 06:58:41 +00:00
Label {
Layout.alignment: Qt.AlignHCenter
2018-08-13 05:07:35 +00:00
visible: readMarker === true && index !== 0
2018-09-04 06:58:41 +00:00
text: "And Now"
color: "white"
verticalAlignment: Text.AlignVCenter
leftPadding: 8
rightPadding: 8
topPadding: 4
bottomPadding: 4
2018-08-13 05:07:35 +00:00
2018-09-04 06:58:41 +00:00
background: Rectangle {
color: MSettings.darkTheme ? "#484848" : "grey"
2018-08-13 05:07:35 +00:00
}
2018-09-04 06:58:41 +00:00
}
2018-08-13 05:07:35 +00:00
2018-09-04 06:58:41 +00:00
MessageDelegate {
visible: eventType === "notice" || eventType === "message" || eventType === "image" || eventType === "video" || eventType === "audio" || eventType === "file"
2018-08-13 05:07:35 +00:00
}
2018-09-04 06:58:41 +00:00
StateDelegate {
Layout.maximumWidth: messageListView.width * 0.8
visible: eventType === "emote" || eventType === "state"
}
}
2018-08-04 16:15:58 +00:00
ScrollBar.vertical: messageListViewScrollBar
2018-07-09 06:16:32 +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
2018-09-02 13:26:42 +00:00
width: 64
2018-08-04 16:15:58 +00:00
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
2018-09-02 13:26:42 +00:00
2018-08-04 16:15:58 +00:00
icon: "\ue313"
color: "white"
}
2018-09-02 13:26:42 +00:00
Material.background: Material.accent
2018-08-04 16:15:58 +00:00
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-02-23 14:39:14 +00:00
2018-09-02 13:26:42 +00:00
RowLayout {
Layout.fillWidth: true
2018-09-02 13:26:42 +00:00
Layout.preferredHeight: 48
Layout.margins: 16
2018-09-02 13:26:42 +00:00
spacing: 0
2018-09-02 13:26:42 +00:00
ItemDelegate {
Layout.preferredWidth: 48
Layout.preferredHeight: 48
2018-09-02 13:26:42 +00:00
contentItem: MaterialIcon { icon: "\ue226" }
2018-09-02 13:26:42 +00:00
onClicked: currentRoom.chooseAndUploadFile()
}
2018-09-02 13:26:42 +00:00
TextField {
property real progress: 0
2018-09-02 13:26:42 +00:00
id: inputField
Layout.fillWidth: true
Layout.preferredHeight: 48
placeholderText: "Send a Message"
leftPadding: 16
topPadding: 0
bottomPadding: 0
selectByMouse: true
text: currentRoom ? currentRoom.cachedInput : ""
onTextChanged: {
timeoutTimer.restart()
repeatTimer.start()
currentRoom.cachedInput = text
}
2018-09-02 13:26:42 +00:00
Keys.onReturnPressed: {
if (inputField.text) {
inputField.postMessage(inputField.text)
inputField.text = ""
}
}
2018-09-02 13:26:42 +00:00
background: Rectangle {
2018-09-02 23:13:39 +00:00
color: MSettings.darkTheme ? "#282828" : "#eaeaea"
2018-02-23 14:39:14 +00:00
}
2018-09-02 13:26:42 +00:00
ToolTip.visible: currentRoom && currentRoom.hasUsersTyping
ToolTip.text: currentRoom ? currentRoom.usersTyping : ""
2018-08-19 06:32:18 +00:00
2018-09-02 13:26:42 +00:00
Timer {
id: timeoutTimer
2018-09-02 13:26:42 +00:00
repeat: false
interval: 2000
onTriggered: {
repeatTimer.stop()
currentRoom.sendTypingNotification(false)
2018-07-17 06:14:48 +00:00
}
2018-09-02 13:26:42 +00:00
}
2018-07-09 14:00:27 +00:00
2018-09-02 13:26:42 +00:00
Timer {
id: repeatTimer
2018-08-20 14:40:36 +00:00
2018-09-02 13:26:42 +00:00
repeat: true
interval: 5000
triggeredOnStart: true
onTriggered: currentRoom.sendTypingNotification(true)
}
2018-07-09 14:00:27 +00:00
2018-09-02 13:26:42 +00:00
function postMessage(text) {
if (text.trim().length === 0) { return }
if(!currentRoom) { return }
2018-07-11 08:07:04 +00:00
2018-09-02 13:26:42 +00:00
var PREFIX_ME = '/me '
var PREFIX_NOTICE = '/notice '
var PREFIX_RAINBOW = '/rainbow '
var PREFIX_HTML = '/html '
var PREFIX_MARKDOWN = '/md '
2018-07-09 14:00:27 +00:00
2018-09-02 13:26:42 +00:00
if (text.indexOf(PREFIX_ME) === 0) {
text = text.substr(PREFIX_ME.length)
currentRoom.postMessage(text, RoomMessageEvent.Emote)
return
2018-07-09 14:00:27 +00:00
}
2018-09-02 13:26:42 +00:00
if (text.indexOf(PREFIX_NOTICE) === 0) {
text = text.substr(PREFIX_NOTICE.length)
currentRoom.postMessage(text, RoomMessageEvent.Notice)
return
}
if (text.indexOf(PREFIX_RAINBOW) === 0) {
text = text.substr(PREFIX_RAINBOW.length)
var parsedText = ""
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"]
for (var i = 0; i < text.length; i++) {
parsedText = parsedText + "<font color='" + rainbowColor[i % rainbowColor.length] + "'>" + text.charAt(i) + "</font>"
}
currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.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, RoomMessageEvent.Text)
return
}
if (text.indexOf(PREFIX_MARKDOWN) === 0) {
text = text.substr(PREFIX_MARKDOWN.length)
var parsedText = Markdown.markdown_parser(text)
currentRoom.postHtmlMessage(text, parsedText, RoomMessageEvent.Text)
return
}
currentRoom.postPlainText(text)
2018-02-23 14:39:14 +00:00
}
2018-09-02 13:26:42 +00:00
}
2018-02-23 14:39:14 +00:00
2018-09-02 13:26:42 +00:00
ItemDelegate {
id: emojiButton
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
Layout.preferredWidth: 48
Layout.preferredHeight: 48
2018-09-02 13:26:42 +00:00
contentItem: MaterialIcon { icon: "\ue24e" }
2018-09-02 23:13:39 +00:00
background: Rectangle { color: MSettings.darkTheme ? "#282828" : "#eaeaea" }
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.open()
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
EmojiPicker {
id: emojiPicker
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
parent: ApplicationWindow.overlay
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
x: window.width - 370
y: window.height - 440
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
width: 360
height: 360
2018-08-11 04:42:13 +00:00
2018-09-02 13:26:42 +00:00
textArea: inputField
2018-02-23 14:39:14 +00:00
}
}
}
}
}
onCurrentRoomChanged: if (currentRoom && currentRoom.timelineSize === 0) currentRoom.getPreviousContent(20)
2018-02-23 14:39:14 +00:00
}