2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 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
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
import QtQuick 2.15
|
2020-08-28 16:10:50 +02:00
|
|
|
import QtQuick.Layouts 1.15
|
2017-03-07 16:06:02 +01:00
|
|
|
import QtQuickDesignerTheme 1.0
|
2020-07-03 16:17:54 +02:00
|
|
|
import HelperWidgets 2.0
|
|
|
|
|
import StudioControls 1.0 as StudioControls
|
|
|
|
|
import StudioTheme 1.0 as StudioTheme
|
2014-05-22 13:20:02 +02:00
|
|
|
|
|
|
|
|
Rectangle {
|
2020-07-03 16:17:54 +02:00
|
|
|
id: myRoot
|
|
|
|
|
|
2014-05-22 14:20:46 +02:00
|
|
|
property bool isBaseState
|
2014-05-22 13:20:02 +02:00
|
|
|
property bool isCurrentState
|
|
|
|
|
property string delegateStateName
|
|
|
|
|
property string delegateStateImageSource
|
2016-09-19 17:17:13 +02:00
|
|
|
property bool delegateHasWhenCondition
|
|
|
|
|
property string delegateWhenConditionString
|
2020-07-28 17:03:35 +02:00
|
|
|
property bool hasAnnotation: checkAnnotation()
|
2020-08-28 16:10:50 +02:00
|
|
|
property int topAreaHeight
|
|
|
|
|
property int bottomAreaHeight
|
|
|
|
|
property int stateMargin
|
|
|
|
|
property int previewMargin
|
2020-07-28 17:03:35 +02:00
|
|
|
|
2020-03-06 15:48:45 +01:00
|
|
|
readonly property bool isDefaultState: isDefault
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
property int closeButtonMargin: 6
|
|
|
|
|
property int textFieldMargin: 4
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2021-12-15 11:56:24 +02:00
|
|
|
property int scrollBarH: 0
|
|
|
|
|
property int listMargin: 0
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2016-12-21 14:25:32 +01:00
|
|
|
function autoComplete(text, pos, explicitComplete, filter) {
|
2016-09-19 17:17:13 +02:00
|
|
|
var stringList = statesEditorModel.autoComplete(text, pos, explicitComplete)
|
|
|
|
|
return stringList
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 17:03:35 +02:00
|
|
|
function checkAnnotation() {
|
|
|
|
|
return statesEditorModel.hasAnnotation(internalNodeId)
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 11:56:24 +02:00
|
|
|
color: isCurrentState ? StudioTheme.Values.themeInteraction
|
|
|
|
|
: StudioTheme.Values.themeControlBackgroundInteraction
|
2014-05-22 13:20:02 +02:00
|
|
|
MouseArea {
|
2020-07-03 16:17:54 +02:00
|
|
|
id: mouseArea
|
2014-05-22 13:20:02 +02:00
|
|
|
anchors.fill: parent
|
2021-12-15 11:56:24 +02:00
|
|
|
|
2014-05-22 14:20:46 +02:00
|
|
|
onClicked: {
|
2014-07-03 13:08:12 +02:00
|
|
|
focus = true
|
|
|
|
|
root.currentStateInternalId = internalNodeId
|
2020-07-03 16:17:54 +02:00
|
|
|
contextMenu.dismiss() // close potentially open context menu
|
2014-05-22 14:20:46 +02:00
|
|
|
}
|
2014-05-22 13:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.AbstractButton {
|
2014-05-22 13:20:02 +02:00
|
|
|
id: removeStateButton
|
2020-08-28 16:10:50 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
buttonIcon: StudioTheme.Constants.closeCross
|
2020-08-28 16:10:50 +02:00
|
|
|
|
2014-05-22 13:20:02 +02:00
|
|
|
anchors.right: parent.right
|
2020-08-28 16:10:50 +02:00
|
|
|
anchors.rightMargin: myRoot.closeButtonMargin
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: myRoot.closeButtonMargin
|
|
|
|
|
|
|
|
|
|
visible: !isBaseState && isCurrentState
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2020-03-16 18:31:07 +01:00
|
|
|
onClicked: {
|
|
|
|
|
if (isDefaultState)
|
|
|
|
|
statesEditorModel.resetDefaultState()
|
|
|
|
|
|
|
|
|
|
root.deleteState(internalNodeId)
|
|
|
|
|
}
|
2014-05-22 13:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.Menu {
|
|
|
|
|
id: contextMenu
|
2016-09-19 17:17:13 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: !isBaseState
|
|
|
|
|
text: qsTr("Set when Condition")
|
|
|
|
|
onTriggered: {
|
|
|
|
|
bindingEditor.showWidget()
|
|
|
|
|
bindingEditor.text = delegateWhenConditionString
|
|
|
|
|
bindingEditor.prepareBindings()
|
2021-09-10 18:06:26 +02:00
|
|
|
bindingEditor.updateWindowName()
|
2020-07-03 16:17:54 +02:00
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: !isBaseState && delegateHasWhenCondition
|
|
|
|
|
text: qsTr("Reset when Condition")
|
|
|
|
|
onTriggered: {
|
|
|
|
|
statesEditorModel.resetWhenCondition(internalNodeId)
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
2020-07-03 16:17:54 +02:00
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: !isBaseState && !isDefaultState
|
|
|
|
|
text: qsTr("Set as Default")
|
|
|
|
|
onTriggered: {
|
|
|
|
|
statesEditorModel.setStateAsDefault(internalNodeId)
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
2020-07-03 16:17:54 +02:00
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: (!isBaseState && isDefaultState) || (isBaseState && modelHasDefaultState)
|
|
|
|
|
text: qsTr("Reset Default")
|
|
|
|
|
onTriggered: {
|
|
|
|
|
statesEditorModel.resetDefaultState()
|
2020-03-06 15:48:45 +01:00
|
|
|
}
|
2020-07-03 16:17:54 +02:00
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
|
2020-07-28 17:03:35 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: !isBaseState
|
|
|
|
|
text: (hasAnnotation ? qsTr("Edit Annotation")
|
|
|
|
|
: qsTr("Add Annotation"))
|
|
|
|
|
onTriggered: {
|
|
|
|
|
statesEditorModel.setAnnotation(internalNodeId)
|
|
|
|
|
hasAnnotation = checkAnnotation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
enabled: !isBaseState && hasAnnotation
|
|
|
|
|
text: qsTr("Remove Annotation")
|
|
|
|
|
onTriggered: {
|
|
|
|
|
statesEditorModel.removeAnnotation(internalNodeId)
|
|
|
|
|
hasAnnotation = checkAnnotation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
onClosed: {
|
|
|
|
|
stateNameField.actionIndicator.forceVisible = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpened: {
|
2020-07-28 17:03:35 +02:00
|
|
|
hasAnnotation = checkAnnotation()
|
2020-07-03 16:17:54 +02:00
|
|
|
myRoot.delegateInteraction()
|
2020-03-06 15:48:45 +01:00
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Column {
|
|
|
|
|
id: column
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
anchors.margins: myRoot.stateMargin
|
|
|
|
|
anchors.fill: parent
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Rectangle {
|
|
|
|
|
width: myRoot.width - 2 * myRoot.stateMargin
|
|
|
|
|
height: myRoot.topAreaHeight
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
color: StudioTheme.Values.themeStateBackground
|
2014-06-06 14:38:52 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
StudioControls.TextField {
|
|
|
|
|
id: stateNameField
|
2014-06-06 14:38:52 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
property string oldValue
|
2019-03-19 14:48:22 +01:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
width: StudioTheme.Values.height * 5.5
|
2014-05-22 14:20:46 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: myRoot.textFieldMargin
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.leftMargin: myRoot.textFieldMargin
|
2019-03-19 14:48:22 +01:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
translationIndicatorVisible: false
|
|
|
|
|
readOnly: isBaseState
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
actionIndicator.icon.text: delegateHasWhenCondition
|
|
|
|
|
? StudioTheme.Constants.actionIconBinding
|
|
|
|
|
: StudioTheme.Constants.actionIcon
|
2014-05-22 13:20:02 +02:00
|
|
|
|
2016-07-01 18:36:58 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
actionIndicator.onClicked: {
|
|
|
|
|
stateNameField.actionIndicator.forceVisible = true
|
|
|
|
|
contextMenu.popup()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onEditChanged: {
|
|
|
|
|
if (contextMenu.open && stateNameField.edit)
|
|
|
|
|
contextMenu.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
|
|
|
if (activeFocus)
|
|
|
|
|
root.currentStateInternalId = internalNodeId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onEditingFinished: {
|
|
|
|
|
if (stateNameField.oldValue === stateNameField.text)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
stateNameField.oldValue = stateNameField.text
|
|
|
|
|
|
|
|
|
|
if (stateNameField.text !== myRoot.delegateStateName)
|
|
|
|
|
statesEditorModel.renameState(internalNodeId, stateNameField.text)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
text = myRoot.delegateStateName
|
|
|
|
|
}
|
2021-12-02 16:11:08 +01:00
|
|
|
|
|
|
|
|
//QDS-5649:
|
|
|
|
|
Keys.priority: Keys.BeforeItem
|
|
|
|
|
Keys.onEscapePressed: function (event) {
|
|
|
|
|
event.accepted = true
|
|
|
|
|
stateNameField.text = myRoot.delegateStateName
|
|
|
|
|
stateNameField.focus = false
|
|
|
|
|
}
|
2020-08-28 16:10:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
id: stateDefaultIndicator
|
|
|
|
|
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: myRoot.previewMargin
|
|
|
|
|
anchors.verticalCenter: stateNameField.verticalCenter
|
|
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
color: StudioTheme.Values.themeTextColor
|
2020-08-28 16:10:50 +02:00
|
|
|
font.italic: true
|
|
|
|
|
font.pixelSize: StudioTheme.Values.myFontSize
|
|
|
|
|
font.family: StudioTheme.Constants.font
|
|
|
|
|
|
2021-12-10 11:47:04 +02:00
|
|
|
visible: isDefaultState || (isBaseState && !modelHasDefaultState)
|
2020-08-28 16:10:50 +02:00
|
|
|
|
|
|
|
|
text: qsTr("Default")
|
|
|
|
|
}
|
2014-05-22 13:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-17 16:22:45 +02:00
|
|
|
Rectangle { // separator
|
|
|
|
|
width: column.width
|
2021-12-15 11:56:24 +02:00
|
|
|
height: 2
|
2022-01-17 16:22:45 +02:00
|
|
|
color: StudioTheme.Values.themeStateSeparator
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Rectangle {
|
|
|
|
|
id: stateImageArea
|
|
|
|
|
width: myRoot.width - 2 * myRoot.stateMargin
|
|
|
|
|
height: myRoot.bottomAreaHeight
|
2021-03-02 13:35:07 +01:00
|
|
|
color: StudioTheme.Values.themeStateBackground
|
2020-08-28 16:10:50 +02:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
Image {
|
|
|
|
|
anchors.fill: stateImageBackground
|
|
|
|
|
source: "images/checkers.png"
|
|
|
|
|
fillMode: Image.Tile
|
|
|
|
|
}
|
2020-08-28 16:10:50 +02:00
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
Rectangle {
|
|
|
|
|
id: stateImageBackground
|
2020-08-28 16:10:50 +02:00
|
|
|
anchors.centerIn: parent
|
|
|
|
|
width: Math.round(stateImage.paintedWidth) + 2 * StudioTheme.Values.border
|
|
|
|
|
height: Math.round(stateImage.paintedHeight) + 2 * StudioTheme.Values.border
|
2021-03-02 13:35:07 +01:00
|
|
|
color: "transparent"
|
|
|
|
|
border.width: StudioTheme.Values.border
|
|
|
|
|
border.color: StudioTheme.Values.themeStatePreviewOutline
|
2020-08-28 16:10:50 +02:00
|
|
|
}
|
2021-03-02 13:35:07 +01:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Image {
|
|
|
|
|
id: stateImage
|
|
|
|
|
anchors.margins: myRoot.previewMargin
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
source: delegateStateImageSource
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2022-04-13 13:27:03 +02:00
|
|
|
mipmap: true
|
2020-08-28 16:10:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-20 19:41:09 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-09 14:19:10 +02:00
|
|
|
BindingEditor {
|
2020-08-28 16:10:50 +02:00
|
|
|
id: bindingEditor
|
|
|
|
|
|
2019-08-09 14:19:10 +02:00
|
|
|
property string newWhenCondition
|
2017-01-11 09:35:59 +01:00
|
|
|
|
2019-08-09 14:19:10 +02:00
|
|
|
property Timer timer: Timer {
|
|
|
|
|
id: timer
|
|
|
|
|
running: false
|
|
|
|
|
interval: 50
|
|
|
|
|
repeat: false
|
|
|
|
|
onTriggered: statesEditorModel.setWhenCondition(internalNodeId, bindingEditor.newWhenCondition)
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-12 17:06:06 +01:00
|
|
|
stateModelNodeProperty: statesEditorModel.stateModelNode()
|
2021-09-10 18:06:26 +02:00
|
|
|
stateNameProperty: myRoot.delegateStateName
|
2019-11-12 17:06:06 +01:00
|
|
|
|
2019-08-09 14:19:10 +02:00
|
|
|
onRejected: {
|
|
|
|
|
hideWidget()
|
|
|
|
|
}
|
|
|
|
|
onAccepted: {
|
|
|
|
|
bindingEditor.newWhenCondition = bindingEditor.text.trim()
|
|
|
|
|
timer.start()
|
|
|
|
|
hideWidget()
|
|
|
|
|
}
|
2016-09-19 17:17:13 +02:00
|
|
|
}
|
2014-05-22 13:20:02 +02:00
|
|
|
}
|