You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nheko/resources/qml/InviteDialog.qml

155 lines
4.1 KiB

4 years ago
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import im.nheko 1.0
ApplicationWindow {
id: inviteDialogRoot
property string roomId
property string roomName
4 years ago
property InviteesModel invitees
function addInvite() {
4 years ago
if (inviteeEntry.text.match("@.+?:.{3,}")) {
4 years ago
invitees.addUser(inviteeEntry.text);
inviteeEntry.clear();
}
}
function cleanUpAndClose() {
if (inviteeEntry.text.match("@.+?:.{3,}"))
addInvite();
4 years ago
invitees.accept();
close();
}
title: qsTr("Invite users to ") + roomName
x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
height: 380
width: 340
Shortcut {
sequence: "Ctrl+Enter"
onActivated: cleanUpAndClose()
}
Shortcut {
sequence: StandardKey.Cancel
onActivated: inviteDialogRoot.close()
}
ColumnLayout {
anchors.fill: parent
anchors.margins: Nheko.paddingMedium
spacing: Nheko.paddingMedium
Label {
text: qsTr("User ID to invite")
Layout.fillWidth: true
}
RowLayout {
spacing: Nheko.paddingMedium
MatrixTextField {
id: inviteeEntry
backgroundColor: Nheko.colors.window
placeholderText: qsTr("@joe:matrix.org", "Example user id. The name 'joe' can be localized however you want.")
Layout.fillWidth: true
4 years ago
onAccepted: {
4 years ago
if (text !== "")
4 years ago
addInvite();
4 years ago
4 years ago
}
Component.onCompleted: forceActiveFocus()
Keys.onShortcutOverride: event.accepted = ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && (event.modifiers & Qt.ControlModifier))
4 years ago
Keys.onPressed: {
4 years ago
if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && (event.modifiers === Qt.ControlModifier))
4 years ago
cleanUpAndClose();
4 years ago
4 years ago
}
}
Button {
4 years ago
text: qsTr("Add")
enabled: inviteeEntry.text.match("@.+?:.{3,}")
onClicked: addInvite()
}
4 years ago
}
ListView {
id: inviteesList
Layout.fillWidth: true
Layout.fillHeight: true
model: invitees
4 years ago
delegate: RowLayout {
spacing: Nheko.paddingMedium
4 years ago
Avatar {
width: Nheko.avatarSize
height: Nheko.avatarSize
4 years ago
userid: model.mxid
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: model.displayName
onClicked: TimelineManager.timeline.openUserProfile(model.mxid)
}
ColumnLayout {
spacing: Nheko.paddingSmall
4 years ago
Label {
text: model.displayName
4 years ago
color: TimelineManager.userColor(model ? model.mxid : "", Nheko.colors.window)
4 years ago
font.pointSize: 12
}
Label {
text: model.mxid
4 years ago
color: Nheko.colors.buttonText
4 years ago
font.pointSize: 10
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
}
4 years ago
4 years ago
}
4 years ago
}
4 years ago
}
4 years ago
}
footer: DialogButtonBox {
id: buttons
Button {
text: qsTr("Invite")
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
enabled: invitees.count > 0
onClicked: cleanUpAndClose()
}
Button {
text: qsTr("Cancel")
DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole
4 years ago
onClicked: inviteDialogRoot.close()
}
4 years ago
}
4 years ago
}