Files
Button/qml/settings/ButtonEditorDialog.qml
T
2026-07-13 06:04:04 +03:00

209 lines
6.7 KiB
QML

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Dialog {
id: editorDialog
modal: true
parent: Overlay.overlay
title: editId === "" ? "Новая кнопка" : "Редактирование"
anchors.centerIn: parent
width: Math.min(520, parent ? parent.width * 0.95 : 520)
height: Math.min(560, parent ? parent.height * 0.9 : 560)
standardButtons: Dialog.Ok | Dialog.Cancel
readonly property color panelBg: "#161628"
readonly property color panelFg: "#ffffff"
readonly property color controlBg: "#2a2a40"
palette.button: controlBg
palette.buttonText: panelFg
palette.window: panelBg
palette.windowText: panelFg
palette.text: panelFg
palette.base: "#222236"
palette.highlight: "#4a4a70"
palette.highlightedText: panelFg
background: Rectangle {
color: panelBg
radius: 4
}
property string editId: ""
property bool responseCheckWasEnabled: false
function openForCreate() {
editId = ""
labelF.text = ""
urlF.text = ""
successF.text = ""
errorF.text = "Ошибка"
pendingF.text = "..."
colorF.text = "#7b007b"
iconCombo.model = btnController.listIcons()
iconCombo.currentIndex = 0
typeCombo.currentIndex = 0
holdSwitch.checked = true
holdSlider.value = 800
responseCheckSwitch.checked = false
responseCheckWasEnabled = false
open()
}
function openForEdit(o) {
editId = o.btnId
labelF.text = o.label
urlF.text = o.actionUrl
successF.text = o.successText
errorF.text = o.errorText
pendingF.text = o.pendingText || "..."
colorF.text = o.btnColor || "#7b007b"
iconCombo.model = btnController.listIcons()
var ip = o.iconPath || ""
var fname = ip
var slash = ip.lastIndexOf("/")
if (slash >= 0) fname = ip.substring(slash + 1)
var idx = iconCombo.model.indexOf(fname)
iconCombo.currentIndex = idx >= 0 ? idx : 0
typeCombo.currentIndex = (o.actionType === "http_post") ? 1 : 0
holdSwitch.checked = (o.triggerMode !== "click")
holdSlider.value = (o.holdMs && o.holdMs > 0) ? o.holdMs : 800
responseCheckSwitch.checked = !!o.responseCheckEnabled
responseCheckWasEnabled = responseCheckSwitch.checked
open()
}
contentItem: ScrollView {
id: scroll
clip: true
ScrollBar.vertical.policy: ScrollBar.AsNeeded
ColumnLayout {
width: scroll.availableWidth
spacing: 6
TextField {
id: labelF
Layout.fillWidth: true
placeholderText: "Подпись"
}
RowLayout {
Layout.fillWidth: true
Text { text: "Иконка:"; color: editorDialog.panelFg }
ComboBox {
id: iconCombo
Layout.fillWidth: true
model: btnController.listIcons()
}
Button {
text: "\u21BB"
onClicked: iconCombo.model = btnController.listIcons()
}
}
RowLayout {
Layout.fillWidth: true
Text { text: "Метод:"; color: editorDialog.panelFg }
ComboBox {
id: typeCombo
model: ["http_get", "http_post"]
}
}
TextField {
id: urlF
Layout.fillWidth: true
placeholderText: "URL"
}
TextField {
id: successF
Layout.fillWidth: true
placeholderText: "Текст успеха"
}
TextField {
id: errorF
Layout.fillWidth: true
placeholderText: "Текст ошибки"
}
TextField {
id: pendingF
Layout.fillWidth: true
placeholderText: "Текст ожидания"
}
RowLayout {
Layout.fillWidth: true
Text { text: "Цвет:"; color: editorDialog.panelFg }
TextField {
id: colorF
Layout.fillWidth: true
placeholderText: "#7b007b"
}
Rectangle {
width: 28; height: 28; radius: 14
color: colorF.text || "#7b007b"
border.color: "#80ffffff"; border.width: 1
}
}
RowLayout {
Layout.fillWidth: true
Text { text: "Срабатывание:"; color: editorDialog.panelFg }
Switch {
id: holdSwitch
checked: true
}
Text {
text: holdSwitch.checked ? "Удержание" : "Клик"
color: "#cccccc"
}
Item { Layout.fillWidth: true }
}
RowLayout {
Layout.fillWidth: true
visible: holdSwitch.checked
Text {
text: "Длительность: " + Math.round(holdSlider.value) + " мс"
color: editorDialog.panelFg
Layout.preferredWidth: 180
}
Slider {
id: holdSlider
Layout.fillWidth: true
from: 200; to: 3000; stepSize: 50
value: 800
}
}
RowLayout {
Layout.fillWidth: true
Text { text: "Расширенная проверка:"; color: editorDialog.panelFg }
Switch { id: responseCheckSwitch }
Text {
Layout.fillWidth: true
text: "Правила JSON — в веб-конфигураторе"
color: "#cccccc"
font.pixelSize: 11
wrapMode: Text.WordWrap
}
}
}
}
onAccepted: {
var mode = holdSwitch.checked ? "hold" : "click"
var hold = Math.round(holdSlider.value)
if (editId === "") {
btnController.addButton(labelF.text, iconCombo.currentText,
typeCombo.currentText, urlF.text,
successF.text, errorF.text, pendingF.text,
colorF.text, mode, hold)
} else {
btnController.updateButton(editId, labelF.text, iconCombo.currentText,
typeCombo.currentText, urlF.text,
successF.text, errorF.text, pendingF.text,
colorF.text, mode, hold)
if (responseCheckSwitch.checked !== responseCheckWasEnabled)
btnController.setResponseCheckEnabled(editId, responseCheckSwitch.checked)
}
}
}