Debian Codegraph @

au4/src/projectscene/qml/Audacity/ProjectScene/trackspanel/AddNewTrackPopup.qml

raw
1 import QtQuick
2 import QtQuick.Layouts
3
4 import Muse.Ui
5 import Muse.UiComponents
6
7 import Audacity.ProjectScene
8
9
10 StyledPopupView {
11 id: root
12 objectName: "AddNewTrackPanel"
13
14 contentWidth: content.width
15 contentHeight: content.height
16
17 modal: true
18
19 property alias popupAnchorItem: root.anchorItem
20
21 signal createTracks(type : int, quantity: int)
22
23 QtObject {
24 id: prv
25 property int type: TrackType.MONO
26 property string numberOfTracksPrompt: numberOfTracksText
27 readonly property string numberOfTracksText: qsTrc("projectscene", "Number of tracks")
28 property int numberOfTracks: numberOfTracksValidator.bottom
29 property bool validNumberOfTracks: true
30 }
31
32 ColumnLayout {
33 id: content
34
35 spacing: 12
36
37 RadioButtonGroup {
38 id: trackType
39
40 width: parent.width
41 height: 64
42
43 readonly property int navigationRowStart: 0
44 readonly property int navigationRowEnd: navigationRowStart + count
45
46 model: [
47 { iconCode: IconCode.MICROPHONE, text: qsTrc("projectscene", "Mono"), value: TrackType.MONO },
48 { iconCode: IconCode.MICROPHONE, text: qsTrc("projectscene", "Stereo"), value: TrackType.STEREO },
49 { iconCode: IconCode.LOOP_IN, text: qsTrc("projectscene", "Label"), value: TrackType.LABEL },
50 ]
51
52 delegate: FlatRadioButton {
53 width: 97
54 height: 64
55
56 Column {
57 anchors.centerIn: parent
58 height: childrenRect.height
59 spacing: 8
60
61 StyledIconLabel {
62 anchors.horizontalCenter: parent.horizontalCenter
63 iconCode: modelData.iconCode
64 }
65
66 StyledTextLabel {
67 anchors.horizontalCenter: parent.horizontalCenter
68 text: modelData.text
69 }
70 }
71
72 checked: prv.type === modelData.value
73 onToggled: {
74 prv.type = modelData.value
75 }
76 }
77 }
78
79 StyledTextLabel {
80 id: numberOfTracksLabel
81
82 Layout.alignment: Qt.AlignHCenter
83 verticalAlignment: Text.AlignVCenter
84 horizontalAlignment: Text.AlignHCenter
85
86 text: prv.numberOfTracksText
87 font.family: ui.theme.bodyFont.family
88 }
89
90 RowLayout {
91
92 Layout.alignment: Qt.AlignHCenter
93
94 FlatButton {
95 id: subtract
96
97 Layout.preferredWidth: 28
98 Layout.preferredHeight: 28
99
100 text: "-"
101
102 onClicked: {
103 if (prv.numberOfTracks === "") {
104 input.focus = false
105 return
106 }
107
108 var value = Number(prv.numberOfTracks)
109 if (value > numberOfTracksValidator.top) {
110 prv.numberOfTracks = numberOfTracksValidator.top
111 } else if (value > numberOfTracksValidator.bottom) {
112 prv.numberOfTracks = value - 1
113 }
114
115 input.focus = false
116 }
117 }
118
119 TextInputField {
120 id: input
121
122 Layout.preferredWidth: 79
123 Layout.preferredHeight: 28
124
125 clip: true
126
127 currentText: prv.numberOfTracks
128 textHorizontalAlignment: Qt.AlignHCenter
129 textVerticalAlignment: Qt.AlignVCenter
130
131 validator: IntValidator {
132 id: numberOfTracksValidator
133 bottom: 1
134 top: 25
135 }
136
137 onTextEditingFinished: function(newTextValue) {
138 var value = Number(newTextValue)
139 prv.numberOfTracks = value
140 }
141 }
142
143 FlatButton {
144 id: add
145
146 Layout.preferredWidth: 28
147 Layout.preferredHeight: 28
148
149 text: "+"
150
151 onClicked: {
152 if (prv.numberOfTracks === "") {
153 input.focus = false
154 return
155 }
156
157 var value = Number(prv.numberOfTracks)
158 if (value < numberOfTracksValidator.bottom) {
159 prv.numberOfTracks = numberOfTracksValidator.bottom
160 } else if (value < numberOfTracksValidator.top) {
161 prv.numberOfTracks = value + 1
162 }
163
164 input.focus = false
165 }
166 }
167 }
168
169 SeparatorLine {}
170
171 FlatButton {
172 id: create
173
174 height: 28
175 Layout.fillWidth: true
176
177 text: qsTrc("projectscene", "Create")
178 accentButton: true
179 enabled: prv.validNumberOfTracks
180
181 onClicked: {
182 input.focus = false
183 root.createTracks(prv.type, Number(prv.numberOfTracks))
184 }
185 }
186 }
187 }