Files

77 lines
2.3 KiB
QML
Raw Permalink Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Flora
Dialog {
id: root
property string dialogTitle: qsTr("Имя")
property string actionLabel: qsTr("OK")
property string initialText: ""
property string errorText: ""
signal confirmed(string text)
title: dialogTitle
modal: true
width: 400
anchors.centerIn: parent
closePolicy: Dialog.NoAutoClose
standardButtons: Dialog.NoButton
background: Rectangle { color: Theme.surface; border.color: Theme.borderStrong; radius: 10 }
ColumnLayout {
anchors.fill: parent
spacing: 12
Label { text: dialogTitle; font.bold: true; color: Theme.text; font.pixelSize: 14 }
TextField {
id: nameField
Layout.fillWidth: true
placeholderText: qsTr("Введите имя…")
placeholderTextColor: Theme.textFaint
color: Theme.text
text: root.initialText
selectByMouse: true
inputMethodHints: Qt.ImhNoPredictiveText
background: Rectangle { color: Theme.bgAlt; border.color: nameField.activeFocus ? Theme.accent : Theme.border; radius: 6 }
Component.onCompleted: { forceActiveFocus(); selectAll() }
onAccepted: root.tryConfirm()
onTextChanged: root.errorText = ""
}
Label {
id: errorLabel
Layout.fillWidth: true
visible: root.errorText.length > 0
color: Theme.errorText
wrapMode: Text.Wrap
text: root.errorText
font.pixelSize: 11
padding: 6
background: Rectangle { visible: root.errorText.length>0; color: Theme.errorBg; radius: 6 }
}
RowLayout {
Layout.fillWidth: true
Item { Layout.fillWidth: true }
Button { text: qsTr("Отмена"); onClicked: root.reject() }
Button {
text: root.actionLabel
enabled: nameField.text.trim().length > 0
highlighted: true
onClicked: root.tryConfirm()
}
}
}
function tryConfirm() {
const n = nameField.text.trim()
if (n.length === 0) { root.errorText = qsTr("Имя не может быть пустым."); return }
root.confirmed(n)
root.accept()
}
}