2022-12-19 11:35:21 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2023-01-04 08:52:22 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-12-19 11:35:21 +02:00
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import HelperWidgets as HelperWidgets
|
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
|
import StudioTheme as StudioTheme
|
2023-03-07 16:51:02 +01:00
|
|
|
import AssetsLibraryBackend
|
2022-12-19 11:35:21 +02:00
|
|
|
|
|
|
|
|
Dialog {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
title: qsTr("Create New Effect")
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
|
modal: true
|
|
|
|
|
|
|
|
|
|
required property string dirPath
|
|
|
|
|
readonly property int __maxPath: 32
|
|
|
|
|
|
2023-03-07 16:51:02 +01:00
|
|
|
property var rootView: AssetsLibraryBackend.rootView
|
|
|
|
|
|
2022-12-19 11:35:21 +02:00
|
|
|
ErrorDialog {
|
|
|
|
|
id: creationFailedDialog
|
|
|
|
|
title: qsTr("Could not create effect")
|
|
|
|
|
message: qsTr("An error occurred while trying to create the effect.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentItem: Column {
|
|
|
|
|
spacing: 2
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Effect name: ")
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.TextField {
|
|
|
|
|
id: effectName
|
|
|
|
|
|
|
|
|
|
actionIndicator.visible: false
|
|
|
|
|
translationIndicator.visible: false
|
|
|
|
|
|
|
|
|
|
Keys.onEnterPressed: btnCreate.onClicked()
|
|
|
|
|
Keys.onReturnPressed: btnCreate.onClicked()
|
2023-02-09 18:42:51 +02:00
|
|
|
Keys.onEscapePressed: root.reject()
|
|
|
|
|
|
2023-01-20 14:54:36 +02:00
|
|
|
onTextChanged: {
|
|
|
|
|
let validator = /^[A-Z]\w{2,}[A-Za-z0-9_]*$/
|
|
|
|
|
txtNameValidatorMsg.visible = text.length > 0 && !validator.test(text)
|
|
|
|
|
btnCreate.enabled = !txtNameValidatorMsg.visible
|
|
|
|
|
}
|
2022-12-19 11:35:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Effect name cannot be empty.")
|
|
|
|
|
color: "#ff0000"
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
visible: effectName.text === ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Effect path is too long.")
|
|
|
|
|
color: "#ff0000"
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
visible: effectName.text.length > root.__maxPath
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 14:54:36 +02:00
|
|
|
Text {
|
|
|
|
|
id: txtNameValidatorMsg
|
|
|
|
|
text: qsTr('The name must start with a capital letter, ' +
|
|
|
|
|
'contain at least three characters, ' +
|
|
|
|
|
'and cannot have any special characters.')
|
|
|
|
|
color: "#ff0000"
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
wrapMode: "WordWrap"
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-19 11:35:21 +02:00
|
|
|
Item { // spacer
|
|
|
|
|
width: 1
|
|
|
|
|
height: 20
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
|
|
HelperWidgets.Button {
|
|
|
|
|
id: btnCreate
|
|
|
|
|
|
|
|
|
|
text: qsTr("Create")
|
|
|
|
|
enabled: effectName.text !== ""
|
|
|
|
|
&& effectName.length >=3
|
|
|
|
|
&& effectName.text.length <= root.__maxPath
|
|
|
|
|
onClicked: {
|
2023-03-07 16:51:02 +01:00
|
|
|
const path = AssetsLibraryBackend.rootView.getUniqueEffectPath(root.dirPath, effectName.text)
|
|
|
|
|
if (AssetsLibraryBackend.rootView.createNewEffect(path))
|
2022-12-19 11:35:21 +02:00
|
|
|
root.accept()
|
|
|
|
|
else
|
|
|
|
|
creationFailedDialog.open()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HelperWidgets.Button {
|
|
|
|
|
text: qsTr("Cancel")
|
|
|
|
|
onClicked: root.reject()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpened: {
|
2023-03-07 16:51:02 +01:00
|
|
|
const path = AssetsLibraryBackend.rootView.getUniqueEffectPath(root.dirPath, "Effect01")
|
2022-12-19 11:35:21 +02:00
|
|
|
effectName.text = path.split('/').pop().replace(".qep", '')
|
|
|
|
|
effectName.selectAll()
|
|
|
|
|
effectName.forceActiveFocus()
|
|
|
|
|
}
|
|
|
|
|
}
|