2023-10-19 19:21:31 +03:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import HelperWidgets as HelperWidgets
|
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
|
import StudioTheme as StudioTheme
|
2024-01-26 14:55:50 +02:00
|
|
|
import EffectComposerBackend
|
2023-10-19 19:21:31 +03:00
|
|
|
|
|
|
|
|
StudioControls.Dialog {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
title: qsTr("Save Effect")
|
|
|
|
|
|
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
|
modal: true
|
|
|
|
|
implicitWidth: 250
|
2023-11-09 14:34:42 +02:00
|
|
|
implicitHeight: 160
|
2023-10-19 19:21:31 +03:00
|
|
|
|
2024-01-26 11:38:16 +02:00
|
|
|
property bool clearOnClose: false // clear the effect composer after saving
|
2023-11-08 16:12:35 +02:00
|
|
|
|
2023-10-19 19:21:31 +03:00
|
|
|
onOpened: {
|
2024-01-26 14:55:50 +02:00
|
|
|
nameText.text = EffectComposerBackend.effectComposerModel.getUniqueEffectName()
|
2023-12-13 12:11:06 +02:00
|
|
|
nameText.selectAll()
|
2023-10-19 19:21:31 +03:00
|
|
|
nameText.forceActiveFocus()
|
2023-12-13 12:11:06 +02:00
|
|
|
emptyText.text = ""
|
2023-10-19 19:21:31 +03:00
|
|
|
}
|
|
|
|
|
|
2023-11-09 14:34:42 +02:00
|
|
|
contentItem: Item {
|
|
|
|
|
Column {
|
|
|
|
|
spacing: 2
|
2023-10-19 19:21:31 +03:00
|
|
|
|
2023-11-09 14:34:42 +02:00
|
|
|
Row {
|
|
|
|
|
id: row
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Effect name: ")
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
}
|
2023-10-19 19:21:31 +03:00
|
|
|
|
2023-11-09 14:34:42 +02:00
|
|
|
StudioControls.TextField {
|
|
|
|
|
id: nameText
|
|
|
|
|
|
|
|
|
|
actionIndicator.visible: false
|
|
|
|
|
translationIndicator.visible: false
|
|
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
|
let errMsg = ""
|
|
|
|
|
if (/[^A-Za-z0-9_]+/.test(text))
|
|
|
|
|
errMsg = qsTr("Name contains invalid characters.")
|
|
|
|
|
else if (!/^[A-Z]/.test(text))
|
|
|
|
|
errMsg = qsTr("Name must start with a capital letter")
|
|
|
|
|
else if (text.length < 3)
|
|
|
|
|
errMsg = qsTr("Name must have at least 3 characters")
|
|
|
|
|
else if (/\s/.test(text))
|
|
|
|
|
errMsg = qsTr("Name cannot contain white space")
|
|
|
|
|
|
|
|
|
|
emptyText.text = errMsg
|
|
|
|
|
btnSave.enabled = errMsg.length === 0
|
|
|
|
|
}
|
|
|
|
|
Keys.onEnterPressed: btnSave.onClicked()
|
|
|
|
|
Keys.onReturnPressed: btnSave.onClicked()
|
|
|
|
|
Keys.onEscapePressed: root.reject()
|
2023-10-19 19:21:31 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 14:34:42 +02:00
|
|
|
Text {
|
|
|
|
|
id: emptyText
|
2023-10-19 19:21:31 +03:00
|
|
|
|
2023-11-09 14:34:42 +02:00
|
|
|
color: StudioTheme.Values.themeError
|
|
|
|
|
anchors.right: row.right
|
|
|
|
|
}
|
2023-10-19 19:21:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
anchors.right: parent.right
|
2023-11-09 14:34:42 +02:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
spacing: 2
|
2023-10-19 19:21:31 +03:00
|
|
|
|
|
|
|
|
HelperWidgets.Button {
|
|
|
|
|
id: btnSave
|
|
|
|
|
|
|
|
|
|
text: qsTr("Save")
|
|
|
|
|
enabled: nameText.text !== ""
|
2023-11-08 16:12:35 +02:00
|
|
|
onClicked: {
|
2024-01-15 14:44:38 +02:00
|
|
|
if (!enabled) // needed since this event handler can be triggered from keyboard events
|
|
|
|
|
return
|
|
|
|
|
|
2024-01-26 14:55:50 +02:00
|
|
|
EffectComposerBackend.effectComposerModel.saveComposition(nameText.text)
|
2023-12-11 17:36:03 +02:00
|
|
|
|
|
|
|
|
if (root.clearOnClose) {
|
2024-03-13 03:32:08 +02:00
|
|
|
EffectComposerBackend.effectComposerModel.clear(true)
|
2023-12-11 17:36:03 +02:00
|
|
|
root.clearOnClose = false
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 16:48:34 +02:00
|
|
|
root.accept() // TODO: confirm before overriding effect with same name
|
2023-11-08 16:12:35 +02:00
|
|
|
}
|
2023-10-19 19:21:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelperWidgets.Button {
|
|
|
|
|
text: qsTr("Cancel")
|
2023-12-11 17:36:03 +02:00
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
if (root.clearOnClose) {
|
2024-01-26 14:55:50 +02:00
|
|
|
EffectComposerBackend.effectComposerModel.clear()
|
2023-12-11 17:36:03 +02:00
|
|
|
root.clearOnClose = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root.reject()
|
|
|
|
|
}
|
2023-10-19 19:21:31 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|