2020-07-13 06:14:24 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
|
|
|
|
AutoDirectionLayout {
|
2020-07-14 08:44:20 +10:00
|
|
|
id: root
|
2020-07-13 06:14:24 +10:00
|
|
|
|
2020-07-13 08:48:07 +10:00
|
|
|
property int defaultLevel: 0
|
2020-07-14 08:44:20 +10:00
|
|
|
property int maximumLevel: 100
|
2020-07-13 06:14:24 +10:00
|
|
|
|
2020-07-13 08:48:07 +10:00
|
|
|
readonly property alias changed: field.changed
|
2020-07-14 08:44:20 +10:00
|
|
|
|
2020-07-14 09:21:50 +10:00
|
|
|
readonly property int uncappedLevel: parseInt(field.text || "0", 10)
|
|
|
|
readonly property int level: Math.min(maximumLevel, uncappedLevel)
|
2020-07-13 08:48:34 +10:00
|
|
|
readonly property alias fieldFocused: field.activeFocus
|
|
|
|
|
2020-07-14 08:44:20 +10:00
|
|
|
readonly property bool fieldOverMaximum:
|
|
|
|
parseInt(field.text || "0", 10) > maximumLevel
|
|
|
|
|
2020-07-13 08:48:34 +10:00
|
|
|
signal accepted()
|
2020-07-13 06:14:24 +10:00
|
|
|
|
|
|
|
function reset() { field.reset() }
|
|
|
|
|
|
|
|
|
|
|
|
rowSpacing: theme.spacing
|
2020-07-17 08:17:44 +10:00
|
|
|
onActiveFocusChanged: if (activeFocus) field.forceActiveFocus()
|
2020-07-13 06:14:24 +10:00
|
|
|
|
|
|
|
HSpacer {}
|
|
|
|
|
|
|
|
HTextField {
|
|
|
|
id: field
|
|
|
|
|
|
|
|
radius: 0
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
2020-07-14 08:44:20 +10:00
|
|
|
validator: IntValidator { top: root.maximumLevel }
|
2020-07-13 06:14:24 +10:00
|
|
|
inputMethodHints: Qt.ImhFormattedNumbersOnly
|
2020-07-14 09:21:50 +10:00
|
|
|
maximumLength: root.level < 0 ? 16 : 3
|
2020-07-14 08:44:20 +10:00
|
|
|
defaultText: String(root.defaultLevel)
|
|
|
|
error: root.fieldOverMaximum
|
2020-07-13 06:14:24 +10:00
|
|
|
|
2020-07-14 08:44:20 +10:00
|
|
|
onAccepted: root.accepted()
|
2020-07-13 06:14:24 +10:00
|
|
|
onActiveFocusChanged:
|
2020-07-14 08:44:20 +10:00
|
|
|
if (! activeFocus && fieldOverMaximum) text = root.maximumLevel
|
2020-07-13 06:14:24 +10:00
|
|
|
|
|
|
|
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")
|
2020-07-14 09:21:50 +10:00
|
|
|
checked: root.uncappedLevel < 50
|
2020-07-13 06:14:24 +10:00
|
|
|
uncheckable: false
|
|
|
|
onClicked: field.text = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
HButton {
|
|
|
|
height: parent.height
|
|
|
|
icon.name: "user-power-50"
|
|
|
|
toolTip.text: qsTr("Moderator")
|
2020-07-14 09:21:50 +10:00
|
|
|
checked: root.uncappedLevel >= 50 && root.uncappedLevel < 100
|
2020-07-13 06:14:24 +10:00
|
|
|
uncheckable: false
|
|
|
|
onClicked: field.text = 50
|
|
|
|
}
|
|
|
|
|
|
|
|
HButton {
|
|
|
|
height: parent.height
|
|
|
|
icon.name: "user-power-100"
|
|
|
|
toolTip.text: qsTr("Admin")
|
2020-07-14 09:21:50 +10:00
|
|
|
checked: root.uncappedLevel >= 100
|
2020-07-13 06:14:24 +10:00
|
|
|
uncheckable: false
|
|
|
|
onClicked: field.text = 100
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HSpacer {}
|
|
|
|
}
|