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 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 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 } } } onAccepted: { if (editId === "") { btnController.addButton(labelF.text, iconCombo.currentText, typeCombo.currentText, urlF.text, successF.text, errorF.text, colorF.text) } else { btnController.updateButton(editId, labelF.text, iconCombo.currentText, typeCombo.currentText, urlF.text, successF.text, errorF.text, colorF.text) } } }