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