2014-05-22 13:20:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-08-28 16:10:50 +02:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2016-01-15 14:59:14 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-05-22 13:20:02 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:59:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-05-22 13:20:02 +02:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:59:14 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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
|
|
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
color: baseColor
|
|
|
|
|
|
2014-05-22 14:20:46 +02:00
|
|
|
property bool isBaseState
|
2014-05-22 13:20:02 +02:00
|
|
|
property bool isCurrentState
|
2015-02-20 18:06:13 +01:00
|
|
|
property color baseColor
|
2014-05-22 13:20:02 +02:00
|
|
|
property string delegateStateName
|
|
|
|
|
property string delegateStateImageSource
|
|
|
|
|
property int delegateStateImageSize
|
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
|
|
|
|
|
property int columnSpacing
|
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
|
|
|
|
|
property int highlightBorderWidth: 2
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
signal delegateInteraction
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2014-07-03 13:08:12 +02:00
|
|
|
acceptedButtons: Qt.LeftButton
|
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
|
|
|
|
|
myRoot.delegateInteraction()
|
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: {
|
2020-07-03 16:17:54 +02:00
|
|
|
myRoot.delegateInteraction()
|
2020-03-16 18:31:07 +01:00
|
|
|
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()
|
|
|
|
|
}
|
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-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Rectangle {
|
|
|
|
|
anchors.margins: (isDefaultState || (isBaseState && !modelHasDefaultState)) ? -myRoot.highlightBorderWidth : 0
|
|
|
|
|
anchors.fill: column
|
2021-03-02 13:35:07 +01:00
|
|
|
color: StudioTheme.Values.themeStateSeparator
|
2020-08-28 16:10:50 +02:00
|
|
|
border.color: StudioTheme.Values.themeStateDefaultHighlight
|
|
|
|
|
border.width: (isDefaultState || (isBaseState && !modelHasDefaultState)) ? myRoot.highlightBorderWidth : 0
|
|
|
|
|
}
|
2020-07-03 16:17:54 +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
|
|
|
|
|
spacing: expanded ? myRoot.columnSpacing : 0
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
Rectangle {
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2020-08-28 16:10:50 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
visible: (isDefaultState || (isBaseState && !modelHasDefaultState))
|
|
|
|
|
|
|
|
|
|
text: qsTr("Default")
|
|
|
|
|
}
|
2014-05-22 13:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 19:41:09 +01:00
|
|
|
|
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
|
|
|
visible: expanded
|
|
|
|
|
|
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
|
|
|
|
|
sourceSize.width: delegateStateImageSize
|
|
|
|
|
sourceSize.height: delegateStateImageSize
|
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
|
}
|
|
|
|
|
}
|
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()
|
|
|
|
|
|
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
|
|
|
}
|