Move popups to their own folder

This commit is contained in:
miruka
2019-09-09 08:57:38 -04:00
parent 6b26aa6d0b
commit c38cc9d3df
6 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,49 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
HPopup {
id: popup
onAboutToShow: okClicked = false
signal ok()
signal cancel()
property alias summary: summary
property alias details: details
property bool okClicked: false
property string okText: qsTr("OK")
property bool okEnabled: true
box.clickButtonOnEnter: "ok"
box.buttonModel: [
{ name: "ok", text: okText, iconName: "ok", enabled: okEnabled},
{ name: "cancel", text: qsTr("Cancel"), iconName: "cancel" },
]
box.buttonCallbacks: ({
ok: button => { okClicked = true; popup.ok(); popup.close() },
cancel: button => { okClicked = false; popup.cancel(); popup.close() },
})
HLabel {
id: summary
wrapMode: Text.Wrap
font.bold: true
visible: Boolean(text)
Layout.fillWidth: true
}
HLabel {
id: details
wrapMode: Text.Wrap
visible: Boolean(text)
Layout.fillWidth: true
}
}

View File

@@ -0,0 +1,17 @@
import QtQuick 2.12
BoxPopup {
summary.text: qsTr("Clear this room's messages?")
details.text: qsTr(
"The messages will only be removed on your side. " +
"They will be available again after you restart the application."
)
okText: qsTr("Clear")
box.focusButton: "ok"
onOk: py.callClientCoro(userId, "clear_events", [roomId])
property string userId: ""
property string roomId: ""
}

View File

@@ -0,0 +1,102 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
BoxPopup {
id: popup
okEnabled: Boolean(passwordField.text)
onAboutToShow: {
okClicked = false
acceptedPassword = ""
passwordValid = null
errorMessage.text = ""
}
onOpened: passwordField.forceActiveFocus()
property bool validateWhileTyping: false
property string acceptedPassword: ""
property var passwordValid: null
property alias field: passwordField
function verifyPassword(pass, callback) {
// Can be reimplemented when using this component.
// Pass to the callback true on success, false on invalid password, or
// a [error message, translated] array for any other error.
callback(true)
}
box.buttonCallbacks: ({
ok: button => {
let password = passwordField.text
okClicked = true
button.loading = true
verifyPassword(password, result => {
if (result === true) {
passwordValid = true
popup.acceptedPassword = password
popup.close()
} else if (result === false) {
passwordValid = false
} else {
let [msg, translated] = result
errorMessage.text = translated ? msg : qsTr(msg)
}
button.loading = false
})
},
cancel: button => { popup.close() },
})
HRowLayout {
spacing: box.horizontalSpacing
HTextField {
id: passwordField
placeholderText: qsTr("Passphrase")
echoMode: TextInput.Password
focus: true
error: passwordValid === false
onTextChanged: passwordValid =
validateWhileTyping ? verifyPassword(text) : null
Layout.fillWidth: true
}
HIcon {
visible: Layout.preferredWidth > 0
svgName: passwordValid ? "ok" : "cancel"
colorize: passwordValid ?
theme.colors.positiveBackground :
theme.colors.negativeBackground
Layout.preferredWidth:
passwordValid == null ||
(validateWhileTyping && ! okClicked && ! passwordValid) ?
0 :implicitWidth
Behavior on Layout.preferredWidth { HNumberAnimation {} }
}
}
HLabel {
id: errorMessage
wrapMode: Text.Wrap
color: theme.colors.errorText
visible: Layout.maximumHeight > 0
Layout.maximumHeight: text ? implicitHeight : 0
Behavior on Layout.maximumHeight { HNumberAnimation {} }
Layout.fillWidth: true
}
}