matrixion/resources/qml/pages/UserSettingsPage.qml

297 lines
12 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
2022-01-09 02:28:03 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
2023-06-19 22:24:31 +03:00
2023-06-19 21:45:57 +03:00
pragma ComponentBehavior: Bound
2022-01-09 08:56:02 +03:00
import ".."
2023-10-01 22:49:47 +03:00
import "../dialogs"
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import im.nheko
2022-01-09 02:28:03 +03:00
Rectangle {
id: userSettingsDialog
2022-06-11 11:05:24 +03:00
property int collapsePoint: 600
2022-01-11 06:12:42 +03:00
property bool collapsed: width < collapsePoint
2023-10-31 05:11:03 +03:00
color: palette.window
2022-01-09 02:28:03 +03:00
ScrollView {
id: scroll
ScrollBar.horizontal.visible: false
anchors.fill: parent
2023-10-31 05:11:03 +03:00
anchors.topMargin: (collapsed ? backButton.height : 0) + Nheko.paddingLarge
bottomPadding: Nheko.paddingLarge
2022-01-09 02:28:03 +03:00
contentWidth: availableWidth
2023-10-31 05:11:03 +03:00
leftPadding: collapsed ? Nheko.paddingMedium : Nheko.paddingLarge
2022-01-09 02:28:03 +03:00
2022-02-19 23:47:19 +03:00
ColumnLayout {
2022-01-09 02:28:03 +03:00
id: grid
anchors.fill: parent
2023-10-31 05:11:03 +03:00
anchors.leftMargin: userSettingsDialog.collapsed ? 0 : (userSettingsDialog.width - userSettingsDialog.collapsePoint) * 0.4 + Nheko.paddingLarge
2022-01-11 06:12:42 +03:00
anchors.rightMargin: anchors.leftMargin
2023-10-31 05:11:03 +03:00
spacing: Nheko.paddingMedium
width: scroll.availableWidth
2023-06-09 20:38:58 +03:00
2022-01-09 02:28:03 +03:00
Repeater {
model: UserSettingsModel
2022-02-19 23:47:19 +03:00
delegate: GridLayout {
2022-01-09 02:28:03 +03:00
id: r
2023-10-31 05:11:03 +03:00
required property var model
columns: collapsed ? 1 : 2
rows: collapsed ? 2 : 1
width: scroll.availableWidth
2022-01-09 02:28:03 +03:00
Label {
Layout.alignment: Qt.AlignLeft
//Layout.column: 0
Layout.columnSpan: (model.type == UserSettingsModel.SectionTitle && !userSettingsDialog.collapsed) ? 2 : 1
2023-10-31 05:11:03 +03:00
Layout.fillWidth: true
2022-01-09 02:28:03 +03:00
//Layout.row: model.index
//Layout.minimumWidth: implicitWidth
2022-01-09 02:28:03 +03:00
Layout.leftMargin: model.type == UserSettingsModel.SectionTitle ? 0 : Nheko.paddingMedium
Layout.topMargin: model.type == UserSettingsModel.SectionTitle ? Nheko.paddingLarge : 0
2023-10-31 05:11:03 +03:00
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: model.description ?? ""
ToolTip.visible: hovered.hovered && model.description
color: palette.text
2022-01-11 06:12:42 +03:00
font.pointSize: 1.1 * fontMetrics.font.pointSize
2023-10-31 05:11:03 +03:00
text: model.name
wrapMode: Text.Wrap
2022-01-09 02:28:03 +03:00
HoverHandler {
id: hovered
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
enabled: model.description ?? false
}
}
DelegateChooser {
id: chooser
Layout.alignment: Qt.AlignRight
Layout.columnSpan: (model.type == UserSettingsModel.SectionTitle && !userSettingsDialog.collapsed) ? 2 : 1
2023-10-31 05:11:03 +03:00
Layout.fillWidth: model.type == UserSettingsModel.SectionTitle || model.type == UserSettingsModel.Options || model.type == UserSettingsModel.Number
Layout.maximumWidth: model.type == UserSettingsModel.SectionTitle ? Number.POSITIVE_INFINITY : 400
2022-01-09 02:28:03 +03:00
Layout.preferredHeight: child.height
2023-06-09 20:38:58 +03:00
Layout.preferredWidth: child.implicitWidth
2022-01-09 02:28:03 +03:00
Layout.rightMargin: model.type == UserSettingsModel.SectionTitle ? 0 : Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
roleValue: model.type
2022-01-09 02:28:03 +03:00
DelegateChoice {
roleValue: UserSettingsModel.Toggle
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
ToggleButton {
checked: model.value
enabled: model.enabled
2023-10-31 05:11:03 +03:00
onCheckedChanged: model.value = checked
2022-01-09 02:28:03 +03:00
}
}
DelegateChoice {
roleValue: UserSettingsModel.Options
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
ComboBox {
anchors.right: parent.right
2022-01-09 02:28:03 +03:00
currentIndex: r.model.value
2023-10-31 05:11:03 +03:00
implicitContentWidthPolicy: ComboBox.WidestTextWhenCompleted
model: r.model.values
2023-06-09 20:38:58 +03:00
width: Math.min(implicitWidth, scroll.availableWidth - Nheko.paddingMedium)
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onCurrentIndexChanged: r.model.value = currentIndex
2023-10-31 05:11:03 +03:00
WheelHandler {
} // suppress scrolling changing values
2022-01-09 02:28:03 +03:00
}
}
DelegateChoice {
roleValue: UserSettingsModel.Integer
2022-01-09 02:28:03 +03:00
SpinBox {
anchors.right: parent.right
2023-10-31 05:11:03 +03:00
editable: true
2022-01-09 02:28:03 +03:00
from: model.valueLowerBound
stepSize: model.valueStep
2023-10-31 05:11:03 +03:00
to: model.valueUpperBound
2022-01-09 02:28:03 +03:00
value: model.value
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onValueChanged: model.value = value
2023-10-31 05:11:03 +03:00
WheelHandler {
} // suppress scrolling changing values
}
}
DelegateChoice {
roleValue: UserSettingsModel.Double
SpinBox {
id: spinbox
readonly property int decimals: 2
2023-10-31 05:11:03 +03:00
readonly property double div: 100
property real realValue: value / div
anchors.right: parent.right
2023-10-31 05:11:03 +03:00
editable: true
from: model.valueLowerBound * div
stepSize: model.valueStep * div
2023-10-31 05:11:03 +03:00
textFromValue: function (value, locale) {
return Number(value / spinbox.div).toLocaleString(locale, 'f', spinbox.decimals);
}
to: model.valueUpperBound * div
value: model.value * div
2023-10-31 05:11:03 +03:00
valueFromText: function (text, locale) {
return Number.fromLocaleString(locale, text) * spinbox.div;
}
2023-10-31 05:11:03 +03:00
validator: DoubleValidator {
bottom: Math.min(spinbox.from / spinbox.div, spinbox.to / spinbox.div)
top: Math.max(spinbox.from / spinbox.div, spinbox.to / spinbox.div)
}
2023-10-31 05:11:03 +03:00
onValueChanged: model.value = value / div
2023-10-31 05:11:03 +03:00
WheelHandler {
} // suppress scrolling changing values
2022-01-09 02:28:03 +03:00
}
}
DelegateChoice {
roleValue: UserSettingsModel.ReadOnlyText
2023-10-31 05:11:03 +03:00
TextEdit {
color: palette.text
readOnly: true
2023-10-31 05:11:03 +03:00
text: model.value
textFormat: Text.PlainText
2022-01-09 02:28:03 +03:00
}
}
DelegateChoice {
roleValue: UserSettingsModel.SectionTitle
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
Item {
height: fontMetrics.lineSpacing
2023-10-31 05:11:03 +03:00
width: grid.width
2022-01-09 02:28:03 +03:00
Rectangle {
anchors.left: parent.left
anchors.right: parent.right
2023-10-31 05:11:03 +03:00
anchors.top: parent.top
anchors.topMargin: Nheko.paddingSmall
color: palette.buttonText
2022-01-09 02:28:03 +03:00
height: 1
}
}
}
DelegateChoice {
roleValue: UserSettingsModel.KeyStatus
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
Text {
color: model.good ? "green" : Nheko.theme.error
text: model.value ? qsTr("CACHED") : qsTr("NOT CACHED")
}
}
DelegateChoice {
roleValue: UserSettingsModel.SessionKeyImportExport
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
RowLayout {
Button {
text: qsTr("IMPORT")
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onClicked: UserSettingsModel.importSessionKeys()
}
Button {
text: qsTr("EXPORT")
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onClicked: UserSettingsModel.exportSessionKeys()
}
}
}
DelegateChoice {
roleValue: UserSettingsModel.XSignKeysRequestDownload
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
RowLayout {
Button {
text: qsTr("DOWNLOAD")
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onClicked: UserSettingsModel.downloadCrossSigningSecrets()
}
Button {
text: qsTr("REQUEST")
2023-10-31 05:11:03 +03:00
2022-01-09 02:28:03 +03:00
onClicked: UserSettingsModel.requestCrossSigningSecrets()
}
}
}
DelegateChoice {
roleValue: UserSettingsModel.ConfigureHiddenEvents
2023-10-31 05:11:03 +03:00
Button {
text: qsTr("CONFIGURE")
2023-10-31 05:11:03 +03:00
onClicked: {
var dialog = hiddenEventsDialog.createObject();
dialog.show();
destroyOnClose(dialog);
}
Component {
id: hiddenEventsDialog
2023-10-31 05:11:03 +03:00
HiddenEventsDialog {
}
}
}
}
DelegateChoice {
roleValue: UserSettingsModel.ManageIgnoredUsers
2023-10-31 05:11:03 +03:00
Button {
text: qsTr("MANAGE")
2023-10-31 05:11:03 +03:00
onClicked: {
var dialog = ignoredUsersDialog.createObject();
dialog.show();
destroyOnClose(dialog);
}
Component {
id: ignoredUsersDialog
2023-10-31 05:11:03 +03:00
IgnoredUsers {
}
}
}
}
2022-01-09 02:28:03 +03:00
DelegateChoice {
Text {
text: model.value
}
}
}
}
}
}
}
ImageButton {
id: backButton
2023-10-31 05:11:03 +03:00
ToolTip.text: qsTr("Back")
ToolTip.visible: hovered
2022-01-09 02:28:03 +03:00
anchors.left: parent.left
anchors.margins: Nheko.paddingMedium
2023-10-31 05:11:03 +03:00
anchors.top: parent.top
2022-01-09 02:28:03 +03:00
height: Nheko.avatarSize
image: ":/icons/icons/ui/angle-arrow-left.svg"
2023-10-31 05:11:03 +03:00
width: Nheko.avatarSize
2022-01-09 02:28:03 +03:00
onClicked: mainWindow.pop()
}
}