matrixion/qml/dialogs/CreateDirect.qml

122 lines
3.6 KiB
QML
Raw Permalink Normal View History

2022-03-26 19:28:44 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
2022-03-26 19:28:44 +03:00
import QtQuick 2.15
import QtQuick.Window 2.13
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.3
import QtQml.Models 2.15
import im.nheko
2022-03-26 19:28:44 +03:00
ApplicationWindow {
id: createDirectRoot
2022-04-16 03:13:01 +03:00
property bool otherUserHasE2ee: profile ? profile.deviceList.rowCount() > 0 : true
property var profile
2022-04-16 03:13:01 +03:00
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
minimumHeight: layout.implicitHeight + footer.implicitHeight + Nheko.paddingLarge * 2
minimumWidth: Math.max(footer.implicitWidth, layout.implicitWidth)
modality: Qt.NonModal
2022-04-16 03:13:01 +03:00
title: qsTr("Create Direct Chat")
footer: DialogButtonBox {
standardButtons: DialogButtonBox.Cancel
onAccepted: {
profile.startChat(encryption.checked);
createDirectRoot.close();
}
onRejected: createDirectRoot.close()
Button {
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
enabled: userID.isValidMxid
text: "Start Direct Chat"
}
}
onVisibilityChanged: {
userID.forceActiveFocus();
}
2022-03-27 23:32:29 +03:00
Shortcut {
sequence: StandardKey.Cancel
2022-04-16 03:13:01 +03:00
onActivated: createDirectRoot.close()
}
2022-03-26 19:28:44 +03:00
ColumnLayout {
id: layout
anchors.fill: parent
anchors.margins: Nheko.paddingLarge
2022-04-16 03:13:01 +03:00
spacing: userID.height / 4
2022-03-26 19:28:44 +03:00
GridLayout {
Layout.fillWidth: true
2022-04-16 03:13:01 +03:00
columnSpacing: Nheko.paddingMedium
2022-03-26 19:28:44 +03:00
columns: 2
rowSpacing: Nheko.paddingSmall
2022-04-16 03:13:01 +03:00
rows: 2
2022-03-26 19:28:44 +03:00
Avatar {
Layout.alignment: Qt.AlignLeft
2022-04-16 03:13:01 +03:00
Layout.preferredHeight: Nheko.avatarSize
Layout.preferredWidth: Nheko.avatarSize
Layout.rowSpan: 2
displayName: profile ? profile.displayName : ""
2022-03-26 19:28:44 +03:00
enabled: false
2022-04-16 03:13:01 +03:00
url: profile ? profile.avatarUrl.replace("mxc://", "image://MxcImage/") : null
userid: profile ? profile.userid : ""
2022-03-26 19:28:44 +03:00
}
Label {
Layout.fillWidth: true
2022-04-11 05:18:16 +03:00
color: TimelineManager.userColor(userID.text, timelineRoot.palette.window)
2022-03-26 19:28:44 +03:00
font.pointSize: fontMetrics.font.pointSize
2022-04-16 03:13:01 +03:00
text: profile ? profile.displayName : ""
2022-03-26 19:28:44 +03:00
}
Label {
Layout.fillWidth: true
2022-04-15 06:53:41 +03:00
color: timelineRoot.palette.placeholderText
2022-03-26 19:28:44 +03:00
font.pointSize: fontMetrics.font.pointSize * 0.9
2022-04-16 03:13:01 +03:00
text: userID.text
2022-03-26 19:28:44 +03:00
}
}
MatrixTextField {
id: userID
2022-04-16 03:13:01 +03:00
property bool isValidMxid: text.match("@.+?:.{3,}")
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
focus: true
label: qsTr("User to invite")
placeholderText: qsTr("@user:server.tld")
2022-04-16 03:13:01 +03:00
onTextChanged: {
2022-04-16 03:13:01 +03:00
if (isValidMxid) {
profile = TimelineManager.getGlobalUserProfile(text);
} else
profile = null;
}
}
2022-03-26 19:28:44 +03:00
RowLayout {
Layout.fillWidth: true
2022-04-16 03:13:01 +03:00
2022-03-26 19:28:44 +03:00
Label {
Layout.alignment: Qt.AlignLeft
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.text
2022-04-16 03:13:01 +03:00
text: qsTr("Encryption")
2022-03-26 19:28:44 +03:00
}
ToggleButton {
id: encryption
2022-04-16 03:13:01 +03:00
Layout.alignment: Qt.AlignRight
checked: otherUserHasE2ee
2022-03-26 19:28:44 +03:00
}
}
2022-04-16 03:13:01 +03:00
Item {
Layout.fillHeight: true
}
2022-03-26 19:28:44 +03:00
}
}