Split HPasswordPopup into HPopup, HOkCancelPopup

This commit is contained in:
miruka 2019-09-08 12:17:42 -04:00
parent aefb314999
commit aae26672de
3 changed files with 113 additions and 87 deletions

View File

@ -0,0 +1,29 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
HPopup {
onAboutToShow: okClicked = false
property alias label: label
property bool okClicked: false
box.enterButtonTarget: "ok"
box.buttonModel: [
{ name: "ok", text: qsTr("OK"), iconName: "ok" },
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
box.buttonCallbacks: ({
ok: button => { okClicked = true; popup.close() },
cancel: button => { okClicked = false; popup.close() },
})
HLabel {
id: label
wrapMode: Text.Wrap
Layout.fillWidth: true
}
}

View File

@ -3,27 +3,23 @@ import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../SidePane"
Popup {
HOkCancelPopup {
id: popup
anchors.centerIn: Overlay.overlay
modal: true
padding: 0
onAboutToShow: {
okClicked = false
acceptedPassword = ""
passwordValid = null
okClicked = false
errorMessage.text = ""
}
onOpened: passwordField.forceActiveFocus()
property bool validateWhileTyping: false
property string acceptedPassword: ""
property var passwordValid: null
property bool okClicked: false
property alias label: popupLabel
property alias field: passwordField
@ -35,29 +31,7 @@ Popup {
}
enter: Transition {
HNumberAnimation { property: "scale"; from: 0; to: 1; overshoot: 4 }
}
exit: Transition {
HNumberAnimation { property: "scale"; to: 0 }
}
background: Rectangle {
color: theme.controls.popup.background
}
contentItem: HBox {
id: box
implicitWidth: theme.minimumSupportedWidthPlusSpacing
enterButtonTarget: "ok"
buttonModel: [
{ name: "ok", text: qsTr("OK"), iconName: "ok",
enabled: passwordField.text &&
(validateWhileTyping ? passwordValid : true) },
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
buttonCallbacks: ({
box.buttonCallbacks: ({
ok: button => {
let password = passwordField.text
okClicked = true
@ -82,13 +56,6 @@ Popup {
})
HLabel {
id: popupLabel
wrapMode: Text.Wrap
Layout.fillWidth: true
}
HRowLayout {
spacing: box.horizontalSpacing
@ -129,5 +96,4 @@ Popup {
Layout.fillWidth: true
}
}
}

31
src/qml/Base/HPopup.qml Normal file
View File

@ -0,0 +1,31 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
Popup {
id: popup
anchors.centerIn: Overlay.overlay
modal: true
padding: 0
default property alias boxData: box.body
property alias box: box
enter: Transition {
HNumberAnimation { property: "scale"; from: 0; to: 1; overshoot: 4 }
}
exit: Transition {
HNumberAnimation { property: "scale"; to: 0 }
}
background: Rectangle {
color: theme.controls.popup.background
}
contentItem: HBox {
id: box
implicitWidth: theme.minimumSupportedWidthPlusSpacing
}
}