moment/src/gui/Base/PowerLevelControl.qml

88 lines
2.2 KiB
QML
Raw Normal View History

// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Layouts 1.12
AutoDirectionLayout {
id: root
property int defaultLevel: 0
property int maximumLevel: 100
readonly property alias changed: field.changed
readonly property int level:
Math.min(maximumLevel, parseInt(field.text || "0", 10))
readonly property alias fieldFocused: field.activeFocus
readonly property bool fieldOverMaximum:
parseInt(field.text || "0", 10) > maximumLevel
signal accepted()
function reset() { field.reset() }
rowSpacing: theme.spacing
HSpacer {}
HTextField {
id: field
radius: 0
horizontalAlignment: Qt.AlignHCenter
validator: IntValidator { top: root.maximumLevel }
inputMethodHints: Qt.ImhFormattedNumbersOnly
maximumLength: root.level < 0 ? 16 : String(root.maximumLevel).length
defaultText: String(root.defaultLevel)
error: root.fieldOverMaximum
onAccepted: root.accepted()
onActiveFocusChanged:
if (! activeFocus && fieldOverMaximum) text = root.maximumLevel
Layout.minimumWidth:
mainUI.fontMetrics.boundingRect("-999").width +
leftPadding +
rightPadding
Layout.alignment: Qt.AlignCenter
}
Row {
Layout.preferredHeight: field.height
Layout.alignment: Qt.AlignCenter
HButton {
height: parent.height
icon.name: "user-power-default"
2020-07-13 09:28:40 +10:00
toolTip.text: qsTr("Limited")
checked: root.level < 50
uncheckable: false
onClicked: field.text = 0
}
HButton {
height: parent.height
icon.name: "user-power-50"
toolTip.text: qsTr("Moderator")
checked: root.level >= 50 && root.level < 100
uncheckable: false
onClicked: field.text = 50
}
HButton {
height: parent.height
icon.name: "user-power-100"
toolTip.text: qsTr("Admin")
checked: root.level >= 100
uncheckable: false
onClicked: field.text = 100
}
}
HSpacer {}
}