blob: 15314ae33703f34a718bdac1d1f76bb2e470bba1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 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 {}
}
}
|