matrixion/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml

158 lines
4.8 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import ".."
2023-10-26 17:43:09 +03:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import im.nheko
ApplicationWindow {
id: allowedDialog
property var roomSettings
color: palette.window
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2023-10-31 05:11:03 +03:00
height: 680
minimumHeight: 450
minimumWidth: 340
modality: Qt.NonModal
title: qsTr("Allowed rooms settings")
2023-10-31 05:11:03 +03:00
width: 450
footer: DialogButtonBox {
id: dbb
standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
onAccepted: {
roomSettings.applyAllowedFromModel();
allowedDialog.close();
}
onRejected: allowedDialog.close()
}
Shortcut {
sequence: StandardKey.Cancel
2023-10-31 05:11:03 +03:00
onActivated: roomSettingsDialog.close()
}
ColumnLayout {
anchors.fill: parent
2023-10-31 05:11:03 +03:00
anchors.margins: Nheko.paddingMedium
spacing: 0
MatrixText {
2023-10-31 05:11:03 +03:00
Layout.bottomMargin: Nheko.paddingMedium
Layout.fillHeight: false
2023-10-31 05:11:03 +03:00
Layout.fillWidth: true
color: palette.text
2023-10-31 05:11:03 +03:00
font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1)
text: qsTr("List of rooms that allow access to this room. Anyone who is in any of those rooms can join this room.")
}
ListView {
id: view
2023-10-31 05:11:03 +03:00
Layout.fillHeight: true
Layout.fillWidth: true
cacheBuffer: 50
clip: true
model: roomSettings.allowedRoomsModel
spacing: 4
delegate: RowLayout {
anchors.left: parent.left
anchors.right: parent.right
ColumnLayout {
Layout.fillWidth: true
2023-10-31 05:11:03 +03:00
Text {
Layout.fillWidth: true
color: palette.text
2023-10-31 05:11:03 +03:00
text: model.name
textFormat: Text.PlainText
}
Text {
Layout.fillWidth: true
color: palette.buttonText
2023-10-31 05:11:03 +03:00
text: model.isParent ? qsTr("Parent community") : qsTr("Other room")
textFormat: Text.PlainText
}
}
ToggleButton {
Layout.alignment: Qt.AlignRight
2023-10-31 05:11:03 +03:00
checked: model.allowed
onCheckedChanged: model.allowed = checked
}
}
}
2023-10-31 05:11:03 +03:00
Column {
id: roomEntryCompleter
2023-10-31 05:11:03 +03:00
Layout.fillWidth: true
spacing: 1
z: 5
Completer {
id: roomCompleter
avatarHeight: Nheko.avatarSize / 2
avatarWidth: Nheko.avatarSize / 2
2023-10-31 05:11:03 +03:00
bottomToTop: true
centerRowContent: false
2023-10-31 05:11:03 +03:00
completerName: "room"
fullWidth: true
roomId: allowedDialog.roomSettings.roomId
rowMargin: 2
rowSpacing: 2
2023-10-31 05:11:03 +03:00
visible: roomEntry.text.length > 0
width: parent.width
}
MatrixTextField {
id: roomEntry
2023-10-31 05:11:03 +03:00
color: palette.text
placeholderText: qsTr("Enter additional rooms not in the list yet...")
2023-10-31 05:11:03 +03:00
width: parent.width
Keys.onPressed: {
if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) {
event.accepted = true;
roomCompleter.up();
} else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) {
event.accepted = true;
if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier))
2023-10-31 05:11:03 +03:00
roomCompleter.up();
else
2023-10-31 05:11:03 +03:00
roomCompleter.down();
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
roomCompleter.finishCompletion();
event.accepted = true;
}
}
2023-10-31 05:11:03 +03:00
onTextEdited: {
roomCompleter.completer.searchString = text;
}
}
}
Connections {
function onCompletionSelected(id) {
console.log("selected: " + id);
roomSettings.allowedRoomsModel.addRoom(id);
roomEntry.clear();
}
function onCountChanged() {
if (roomCompleter.count > 0 && (roomCompleter.currentIndex < 0 || roomCompleter.currentIndex >= roomCompleter.count))
2023-10-31 05:11:03 +03:00
roomCompleter.currentIndex = 0;
}
target: roomCompleter
}
}
}