forked from qt-creator/qt-creator
QmlDesigner: Remove old states editor QML source
Task-number: QDS-10037 Change-Id: I3fac32afa35940bd857df04ad5f1a0ba2695401e Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
a6d1b594a4
commit
d87e420b39
@@ -1,296 +0,0 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
import QtQuick 2.15
|
|
||||||
import QtQuick.Layouts 1.15
|
|
||||||
import QtQuickDesignerTheme 1.0
|
|
||||||
import HelperWidgets 2.0
|
|
||||||
import StudioControls 1.0 as StudioControls
|
|
||||||
import StudioTheme 1.0 as StudioTheme
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: myRoot
|
|
||||||
|
|
||||||
property bool isBaseState
|
|
||||||
property bool isCurrentState
|
|
||||||
property string delegateStateName
|
|
||||||
property string delegateStateImageSource
|
|
||||||
property bool delegateHasWhenCondition
|
|
||||||
property string delegateWhenConditionString
|
|
||||||
property bool hasAnnotation: checkAnnotation()
|
|
||||||
property int topAreaHeight
|
|
||||||
property int bottomAreaHeight
|
|
||||||
property int stateMargin
|
|
||||||
property int previewMargin
|
|
||||||
|
|
||||||
readonly property bool isDefaultState: isDefault
|
|
||||||
|
|
||||||
property int closeButtonMargin: 6
|
|
||||||
property int textFieldMargin: 4
|
|
||||||
|
|
||||||
property int scrollBarH: 0
|
|
||||||
property int listMargin: 0
|
|
||||||
|
|
||||||
function autoComplete(text, pos, explicitComplete, filter) {
|
|
||||||
var stringList = statesEditorModel.autoComplete(text, pos, explicitComplete)
|
|
||||||
return stringList
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkAnnotation() {
|
|
||||||
return statesEditorModel.hasAnnotation(internalNodeId)
|
|
||||||
}
|
|
||||||
|
|
||||||
color: isCurrentState ? StudioTheme.Values.themeInteraction
|
|
||||||
: StudioTheme.Values.themeControlBackgroundInteraction
|
|
||||||
MouseArea {
|
|
||||||
id: mouseArea
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
onClicked: {
|
|
||||||
focus = true
|
|
||||||
root.currentStateInternalId = internalNodeId
|
|
||||||
contextMenu.dismiss() // close potentially open context menu
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioControls.AbstractButton {
|
|
||||||
id: removeStateButton
|
|
||||||
|
|
||||||
buttonIcon: StudioTheme.Constants.closeCross
|
|
||||||
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: myRoot.closeButtonMargin
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.topMargin: myRoot.closeButtonMargin
|
|
||||||
|
|
||||||
visible: !isBaseState && isCurrentState
|
|
||||||
|
|
||||||
onClicked: {
|
|
||||||
if (isDefaultState)
|
|
||||||
statesEditorModel.resetDefaultState()
|
|
||||||
|
|
||||||
root.deleteState(internalNodeId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioControls.Menu {
|
|
||||||
id: contextMenu
|
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
|
||||||
enabled: !isBaseState
|
|
||||||
text: qsTr("Set when Condition")
|
|
||||||
onTriggered: {
|
|
||||||
bindingEditor.showWidget()
|
|
||||||
bindingEditor.text = delegateWhenConditionString
|
|
||||||
bindingEditor.prepareBindings()
|
|
||||||
bindingEditor.updateWindowName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
|
||||||
enabled: !isBaseState && delegateHasWhenCondition
|
|
||||||
text: qsTr("Reset when Condition")
|
|
||||||
onTriggered: {
|
|
||||||
statesEditorModel.resetWhenCondition(internalNodeId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
|
||||||
enabled: !isBaseState && !isDefaultState
|
|
||||||
text: qsTr("Set as Default")
|
|
||||||
onTriggered: {
|
|
||||||
statesEditorModel.setStateAsDefault(internalNodeId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
|
||||||
enabled: (!isBaseState && isDefaultState) || (isBaseState && modelHasDefaultState)
|
|
||||||
text: qsTr("Reset Default")
|
|
||||||
onTriggered: {
|
|
||||||
statesEditorModel.resetDefaultState()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClosed: {
|
|
||||||
stateNameField.actionIndicator.forceVisible = false
|
|
||||||
}
|
|
||||||
|
|
||||||
onOpened: {
|
|
||||||
hasAnnotation = checkAnnotation()
|
|
||||||
myRoot.delegateInteraction()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column {
|
|
||||||
id: column
|
|
||||||
|
|
||||||
anchors.margins: myRoot.stateMargin
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
width: myRoot.width - 2 * myRoot.stateMargin
|
|
||||||
height: myRoot.topAreaHeight
|
|
||||||
|
|
||||||
color: StudioTheme.Values.themeStateBackground
|
|
||||||
|
|
||||||
StudioControls.TextField {
|
|
||||||
id: stateNameField
|
|
||||||
|
|
||||||
property string oldValue
|
|
||||||
|
|
||||||
width: StudioTheme.Values.height * 5.5
|
|
||||||
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.topMargin: myRoot.textFieldMargin
|
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.leftMargin: myRoot.textFieldMargin
|
|
||||||
|
|
||||||
translationIndicatorVisible: false
|
|
||||||
readOnly: isBaseState
|
|
||||||
|
|
||||||
actionIndicator.icon.text: delegateHasWhenCondition
|
|
||||||
? StudioTheme.Constants.actionIconBinding
|
|
||||||
: StudioTheme.Constants.actionIcon
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
//QDS-5649:
|
|
||||||
Keys.priority: Keys.BeforeItem
|
|
||||||
Keys.onEscapePressed: function (event) {
|
|
||||||
event.accepted = true
|
|
||||||
stateNameField.text = myRoot.delegateStateName
|
|
||||||
stateNameField.focus = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
id: stateDefaultIndicator
|
|
||||||
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: myRoot.previewMargin
|
|
||||||
anchors.verticalCenter: stateNameField.verticalCenter
|
|
||||||
|
|
||||||
color: StudioTheme.Values.themeTextColor
|
|
||||||
font.italic: true
|
|
||||||
font.pixelSize: StudioTheme.Values.myFontSize
|
|
||||||
font.family: StudioTheme.Constants.font
|
|
||||||
|
|
||||||
visible: isDefaultState || (isBaseState && !modelHasDefaultState)
|
|
||||||
|
|
||||||
text: qsTr("Default")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle { // separator
|
|
||||||
width: column.width
|
|
||||||
height: 2
|
|
||||||
color: StudioTheme.Values.themeStateSeparator
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: stateImageArea
|
|
||||||
width: myRoot.width - 2 * myRoot.stateMargin
|
|
||||||
height: myRoot.bottomAreaHeight
|
|
||||||
color: StudioTheme.Values.themeStateBackground
|
|
||||||
|
|
||||||
Image {
|
|
||||||
anchors.fill: stateImageBackground
|
|
||||||
source: "images/checkers.png"
|
|
||||||
fillMode: Image.Tile
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: stateImageBackground
|
|
||||||
anchors.centerIn: parent
|
|
||||||
width: Math.round(stateImage.paintedWidth) + 2 * StudioTheme.Values.border
|
|
||||||
height: Math.round(stateImage.paintedHeight) + 2 * StudioTheme.Values.border
|
|
||||||
color: "transparent"
|
|
||||||
border.width: StudioTheme.Values.border
|
|
||||||
border.color: StudioTheme.Values.themeStatePreviewOutline
|
|
||||||
}
|
|
||||||
|
|
||||||
Image {
|
|
||||||
id: stateImage
|
|
||||||
anchors.margins: myRoot.previewMargin
|
|
||||||
anchors.centerIn: parent
|
|
||||||
anchors.fill: parent
|
|
||||||
source: delegateStateImageSource
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
mipmap: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BindingEditor {
|
|
||||||
id: bindingEditor
|
|
||||||
|
|
||||||
property string newWhenCondition
|
|
||||||
|
|
||||||
property Timer timer: Timer {
|
|
||||||
id: timer
|
|
||||||
running: false
|
|
||||||
interval: 50
|
|
||||||
repeat: false
|
|
||||||
onTriggered: statesEditorModel.setWhenCondition(internalNodeId, bindingEditor.newWhenCondition)
|
|
||||||
}
|
|
||||||
|
|
||||||
stateModelNodeProperty: statesEditorModel.stateModelNode()
|
|
||||||
stateNameProperty: myRoot.delegateStateName
|
|
||||||
|
|
||||||
onRejected: {
|
|
||||||
hideWidget()
|
|
||||||
}
|
|
||||||
onAccepted: {
|
|
||||||
bindingEditor.newWhenCondition = bindingEditor.text.trim()
|
|
||||||
timer.start()
|
|
||||||
hideWidget()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,159 +0,0 @@
|
|||||||
// Copyright (C) 2020 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
import QtQuick 2.15
|
|
||||||
import QtQuick.Controls 2.15
|
|
||||||
import QtQuickDesignerTheme 1.0
|
|
||||||
import Qt.labs.qmlmodels 1.0
|
|
||||||
import HelperWidgets 2.0
|
|
||||||
import StudioControls 1.0 as StudioControls
|
|
||||||
import StudioTheme 1.0 as StudioTheme
|
|
||||||
|
|
||||||
FocusScope {
|
|
||||||
id: root
|
|
||||||
|
|
||||||
readonly property int delegateTopAreaHeight: StudioTheme.Values.height + 8
|
|
||||||
readonly property int delegateBottomAreaHeight: delegateHeight - 2 * delegateStateMargin - delegateTopAreaHeight - 2
|
|
||||||
readonly property int delegateStateMargin: 16
|
|
||||||
readonly property int delegatePreviewMargin: 10
|
|
||||||
readonly property int effectiveHeight: root.height < 130 ? 89 : Math.min(root.height, 287)
|
|
||||||
|
|
||||||
readonly property int scrollBarH: statesListView.ScrollBar.horizontal.scrollBarVisible ? StudioTheme.Values.scrollBarThickness : 0
|
|
||||||
readonly property int listMargin: 10
|
|
||||||
readonly property int delegateWidth: 264
|
|
||||||
readonly property int delegateHeight: Math.max(effectiveHeight - scrollBarH - 2 * listMargin, 69)
|
|
||||||
readonly property int innerSpacing: 2
|
|
||||||
|
|
||||||
property int currentStateInternalId: 0
|
|
||||||
|
|
||||||
signal createNewState
|
|
||||||
signal deleteState(int internalNodeId)
|
|
||||||
signal duplicateCurrentState
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: statesEditorModel
|
|
||||||
function onChangedToState(n) { root.currentStateInternalId = n }
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
id: background
|
|
||||||
anchors.fill: parent
|
|
||||||
color: StudioTheme.Values.themePanelBackground
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractButton {
|
|
||||||
id: addStateButton
|
|
||||||
|
|
||||||
buttonIcon: StudioTheme.Constants.plus
|
|
||||||
iconFont: StudioTheme.Constants.iconFont
|
|
||||||
iconSize: StudioTheme.Values.myIconFontSize
|
|
||||||
tooltip: qsTr("Add a new state.")
|
|
||||||
visible: canAddNewStates
|
|
||||||
anchors.right: parent.right
|
|
||||||
anchors.rightMargin: 4
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.bottomMargin: statesListView.contentWidth - statesListView.contentX - root.delegateWidth / 2 > statesListView.width ? scrollBarH + 5 : -35
|
|
||||||
width: 35
|
|
||||||
height: 35
|
|
||||||
|
|
||||||
Behavior on anchors.bottomMargin {
|
|
||||||
PropertyAnimation {
|
|
||||||
duration: 700
|
|
||||||
easing.type: Easing.InOutBack
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClicked: root.createNewState()
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView {
|
|
||||||
id: statesListView
|
|
||||||
|
|
||||||
clip: true
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.topMargin: listMargin
|
|
||||||
anchors.leftMargin: listMargin
|
|
||||||
anchors.rightMargin: listMargin
|
|
||||||
|
|
||||||
model: statesEditorModel
|
|
||||||
orientation: ListView.Horizontal
|
|
||||||
spacing: root.innerSpacing
|
|
||||||
|
|
||||||
property int prevCount: 0
|
|
||||||
onCountChanged: {
|
|
||||||
if (count > prevCount)
|
|
||||||
Qt.callLater(statesListView.positionViewAtEnd)
|
|
||||||
prevCount = count
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate: DelegateChooser {
|
|
||||||
role: "type"
|
|
||||||
|
|
||||||
DelegateChoice {
|
|
||||||
roleValue: "state"
|
|
||||||
|
|
||||||
StatesDelegate {
|
|
||||||
width: root.delegateWidth
|
|
||||||
height: root.delegateHeight
|
|
||||||
anchors.verticalCenter: parent ? parent.verticalCenter : undefined
|
|
||||||
anchors.verticalCenterOffset: -.5 * (scrollBarH + listMargin)
|
|
||||||
isBaseState: 0 === internalNodeId
|
|
||||||
isCurrentState: root.currentStateInternalId === internalNodeId
|
|
||||||
delegateStateName: stateName
|
|
||||||
delegateStateImageSource: stateImageSource
|
|
||||||
delegateHasWhenCondition: hasWhenCondition
|
|
||||||
delegateWhenConditionString: whenConditionString
|
|
||||||
|
|
||||||
topAreaHeight: root.delegateTopAreaHeight
|
|
||||||
bottomAreaHeight: root.delegateBottomAreaHeight
|
|
||||||
stateMargin: root.delegateStateMargin
|
|
||||||
previewMargin: root.delegatePreviewMargin
|
|
||||||
scrollBarH: root.scrollBarH
|
|
||||||
listMargin: root.listMargin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DelegateChoice {
|
|
||||||
roleValue: "add"
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
visible: canAddNewStates
|
|
||||||
|
|
||||||
width: root.delegateWidth
|
|
||||||
height: root.delegateHeight
|
|
||||||
anchors.verticalCenter: parent ? parent.verticalCenter : undefined
|
|
||||||
anchors.verticalCenterOffset: -.5 * (scrollBarH + listMargin)
|
|
||||||
color: Qt.lighter(StudioTheme.Values.themeControlBackgroundInteraction, addState.containsMouse ? 1.5 : 1)
|
|
||||||
|
|
||||||
ToolTip.text: qsTr("Add a new state.")
|
|
||||||
ToolTip.visible: addState.containsMouse
|
|
||||||
ToolTip.delay: 1000
|
|
||||||
|
|
||||||
Rectangle { // inner rect
|
|
||||||
width: parent.width - 30
|
|
||||||
height: parent.height - 30
|
|
||||||
anchors.centerIn: parent
|
|
||||||
color: StudioTheme.Values.themeStateBackground
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: "+"
|
|
||||||
anchors.centerIn: parent
|
|
||||||
anchors.verticalCenterOffset: -(5 + (font.pixelSize - 35) / 9)
|
|
||||||
font.pixelSize: parent.height * .5
|
|
||||||
color: Qt.lighter(StudioTheme.Values.themeControlBackgroundInteraction, addState.containsMouse ? 1.5 : 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
id: addState
|
|
||||||
hoverEnabled: true
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: root.createNewState()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollBar.horizontal: HorizontalScrollBar {}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 80 B |
Before Width: | Height: | Size: 80 B After Width: | Height: | Size: 80 B |
Reference in New Issue
Block a user