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

155 lines
5.0 KiB
QML

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Dialog {
id: editorDialog
modal: true
title: editId === "" ? "Новая кнопка" : "Редактирование"
anchors.centerIn: parent
standardButtons: Dialog.Ok | Dialog.Cancel
property string editId: ""
function openForCreate() {
editId = ""
labelF.text = ""
urlF.text = ""
successF.text = ""
errorF.text = "Ошибка"
colorF.text = "#7b007b"
iconCombo.model = btnController.listIcons()
iconCombo.currentIndex = 0
typeCombo.currentIndex = 0
holdSwitch.checked = true
holdSlider.value = 800
open()
}
function openForEdit(o) {
editId = o.btnId
labelF.text = o.label
urlF.text = o.actionUrl
successF.text = o.successText
errorF.text = o.errorText
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
open()
}
ColumnLayout {
anchors.fill: parent
spacing: 6
TextField {
id: labelF
Layout.fillWidth: true
placeholderText: "Подпись"
}
RowLayout {
Layout.fillWidth: true
Text { text: "Иконка:"; color: settingsContainer.darkMode ? "white" : "black" }
ComboBox {
id: iconCombo
Layout.fillWidth: true
model: btnController.listIcons()
}
Button {
text: "\u21BB"
onClicked: iconCombo.model = btnController.listIcons()
}
}
RowLayout {
Layout.fillWidth: true
Text { text: "Метод:"; color: settingsContainer.darkMode ? "white" : "black" }
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: "Текст ошибки"
}
RowLayout {
Layout.fillWidth: true
Text { text: "Цвет:"; color: settingsContainer.darkMode ? "white" : "black" }
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: settingsContainer.darkMode ? "white" : "black" }
Switch {
id: holdSwitch
checked: true
}
Text {
text: holdSwitch.checked ? "Удержание" : "Клик"
color: settingsContainer.darkMode ? "#cccccc" : "#444444"
}
Item { Layout.fillWidth: true }
}
RowLayout {
Layout.fillWidth: true
visible: holdSwitch.checked
Text {
text: "Длительность: " + Math.round(holdSlider.value) + " мс"
color: settingsContainer.darkMode ? "white" : "black"
Layout.preferredWidth: 180
}
Slider {
id: holdSlider
Layout.fillWidth: true
from: 200; to: 3000; stepSize: 50
value: 800
}
}
}
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, colorF.text,
mode, hold)
} else {
btnController.updateButton(editId, labelF.text, iconCombo.currentText,
typeCombo.currentText, urlF.text,
successF.text, errorF.text, colorF.text,
mode, hold)
}
}
}