lockscreen: Refactor and cleanup keypad

This commit is contained in:
Devin Lin 2022-10-27 20:37:31 -04:00
parent f4b15f922f
commit 11aaad0546

View file

@ -46,6 +46,7 @@ Rectangle {
PlasmaCore.Units.smallSpacing * 2 + Qt.inputMethod.keyboardRectangle.height + passwordBar.implicitHeight); PlasmaCore.Units.smallSpacing * 2 + Qt.inputMethod.keyboardRectangle.height + passwordBar.implicitHeight);
} }
} }
Behavior on implicitHeight { Behavior on implicitHeight {
NumberAnimation { NumberAnimation {
duration: Kirigami.Units.longDuration duration: Kirigami.Units.longDuration
@ -103,92 +104,90 @@ Rectangle {
spacing: PlasmaCore.Units.gridUnit spacing: PlasmaCore.Units.gridUnit
GridLayout { GridLayout {
property string thePw id: grid
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.leftMargin: PlasmaCore.Units.gridUnit * 0.5 Layout.leftMargin: PlasmaCore.Units.gridUnit * 0.5
Layout.rightMargin: PlasmaCore.Units.gridUnit * 0.5 Layout.rightMargin: PlasmaCore.Units.gridUnit * 0.5
Layout.maximumWidth: PlasmaCore.Units.gridUnit * 22 Layout.maximumWidth: PlasmaCore.Units.gridUnit * 22
Layout.maximumHeight: PlasmaCore.Units.gridUnit * 12.5 Layout.maximumHeight: PlasmaCore.Units.gridUnit * 12.5
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
columns: 4 columns: 4
readonly property real keyRadius: 5
// numpad keys // numpad keys
Repeater { Repeater {
model: ["1", "2", "3", "R", "4", "5", "6", "0", "7", "8", "9", "E"] model: ["1", "2", "3", "R", "4", "5", "6", "0", "7", "8", "9", "E"]
delegate: Item { delegate: AbstractButton {
id: button
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
visible: modelData.length > 0
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
RectangularGlow { background: Rectangle {
anchors.topMargin: 1
anchors.fill: keyRect
cornerRadius: keyRect.radius * 2
cached: true
glowRadius: 2
spread: 0.2
color: keypadRoot.dropShadowColor
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1)
}
Rectangle {
id: keyRect id: keyRect
anchors.centerIn: parent radius: grid.keyRadius
width: parent.width color: button.pressed ? keypadRoot.buttonPressedColor : keypadRoot.buttonColor
height: parent.height
radius: 5
color: keypadRoot.buttonColor
visible: modelData.length > 0 RectangularGlow {
opacity: (Math.sin(2*((Math.PI / 2) * keypadRoot.swipeProgress + 1.5 * Math.PI)) + 1) anchors.topMargin: 1
AbstractButton {
anchors.fill: parent anchors.fill: parent
onPressedChanged: {
if (pressed) {
MobileShell.Haptics.buttonVibrate();
parent.color = keypadRoot.buttonPressedColor;
} else {
parent.color = keypadRoot.buttonColor;
}
}
onClicked: { z: -1
if (modelData === "R") { cornerRadius: keyRect.radius * 2
passwordBar.backspace(); cached: true
} else if (modelData === "E") { glowRadius: 2
passwordBar.enter(); spread: 0.2
} else { color: button.pressed ? keypadRoot.buttonPressedColor : keypadRoot.dropShadowColor
passwordBar.keyPress(modelData);
}
}
onPressAndHold: {
if (modelData === "R") {
MobileShell.Haptics.buttonVibrate();
passwordBar.clear();
}
}
} }
} }
PlasmaComponents.Label { onPressedChanged: {
visible: modelData !== "R" && modelData !== "E" if (pressed) {
text: modelData MobileShell.Haptics.buttonVibrate();
anchors.centerIn: parent }
font.pointSize: 18
font.weight: Font.Light
color: keypadRoot.buttonTextColor
} }
PlasmaCore.IconItem { onClicked: {
visible: modelData === "R" if (modelData === "R") {
anchors.centerIn: parent passwordBar.backspace();
source: "edit-clear" } else if (modelData === "E") {
passwordBar.enter();
} else {
passwordBar.keyPress(modelData);
}
}
onPressAndHold: {
if (modelData === "R") {
MobileShell.Haptics.buttonVibrate();
passwordBar.clear();
}
} }
PlasmaCore.IconItem { contentItem: Item {
visible: modelData === "E" PlasmaComponents.Label {
anchors.centerIn: parent visible: modelData !== "R" && modelData !== "E"
source: "go-next" text: modelData
anchors.centerIn: parent
font.pointSize: 18
font.weight: Font.Light
color: keypadRoot.buttonTextColor
}
PlasmaCore.IconItem {
visible: modelData === "R"
anchors.centerIn: parent
source: "edit-clear"
}
PlasmaCore.IconItem {
visible: modelData === "E"
anchors.centerIn: parent
source: "go-next"
}
} }
} }
} }