summaryrefslogtreecommitdiffstats
path: root/examples/studio3d/simpleqml/main.qml
blob: ed0278ea7409432276a2a2942071ad11364826b3 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:BSD$
** 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
** 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.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.0
import QtStudio3D.OpenGL 2.4
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.0

Rectangle {
    id: root
    color: "lightGray"

    MessageDialog {
        id: errorDialog
    }

    Studio3D {
        id: s3d
        focus: true
        anchors.margins: 60
        anchors.fill: parent
        property string textValue: "hello world"

        ViewerSettings {
            id: viewerSettings
        }

        Presentation {
            id: s3dpres
            source: "qrc:/presentation/barrel.uia"
            onCustomSignalEmitted: customSignalName.text = Date.now() + ": " + name
            onSlideEntered: slideEnter.text = "Entered slide " + name + "(index " + index + ") on " + elementPath
            onSlideExited: slideExit.text = "Exited slide " + name + "(index " + index + ") on " + elementPath

            DataInput {
                name: "di_text"
                value: s3d.textValue
            }

            SceneElement {
                id: sceneElementForScene
                elementPath: "Scene" // could also refer to a Component node instead
                onCurrentSlideIndexChanged: console.log("Current slide index for 'Scene': " + currentSlideIndex)
                onCurrentSlideNameChanged: console.log("Current slide name for 'Scene': " + currentSlideName)
            }

            // Exercise Element a bit. This is no different from using the
            // functions on Presentations, just avoids the need to specify the
            // name/path repeatedly.
            Element {
                id: barrelRef
                elementPath: "Barrel" // or Scene.Layer.Barrel but as long as it's unique the name's good enough
            }
        }
        ignoredEvents: mouseEvCb.checked ? Studio3D.EnableAllEvents : (Studio3D.IgnoreMouseEvents | Studio3D.IgnoreWheelEvents)
        onRunningChanged: console.log("running: " + s3d.running)
        onPresentationReady: console.log("presentationReady")
        onErrorChanged: {
            if (s3d.error !== "") {
                errorDialog.text = s3d.error;
                errorDialog.open();
            }
        }

        property int frameCount: 0
        onFrameUpdate: frameCount += 1

        Timer {
            running: true
            repeat: true
            interval: 1000
            onTriggered: {
                fpsCount.text = "~" + s3d.frameCount + " FPS";
                s3d.frameCount = 0;
            }
        }

        Timer {
            interval: 2000
            running: true
            repeat: true
        }

        NumberAnimation on opacity {
            id: opacityAnimation
            from: 1
            to: 0
            duration: 5000
            running: false
            onStopped: s3d.opacity = 1
        }
    }

    Window {
        id: w
        visible: false
        width: 500
        height: 500
        Item {
            id: wroot
            anchors.fill: parent
        }
        title: "Second window"
    }

    RowLayout {
        Button {
            text: "Move to other window"
            onClicked: {
                w.visible = true;
                if (s3d.parent === wroot) s3d.parent = root; else s3d.parent = wroot;
            }
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Open barrel without background"
            onClicked: s3dpres.source = "qrc:/presentation/barrel_no_background.uip"
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Animate opacity"
            onClicked: opacityAnimation.running = true
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Reload"
            onClicked: {
                var src = s3dpres.source
                s3dpres.source = ""
                s3dpres.source = src
            }
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Open"
            onClicked: openDialog.open()
            focusPolicy: Qt.NoFocus
        }
        CheckBox {
            id: mouseEvCb
            text: "Let mouse events through"
            checked: true
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Toggle camera"
            property bool eyeball: true
            onClicked: {
                eyeball = !eyeball
                s3dpres.setAttribute("Scene.Layer.Camera", "eyeball", eyeball)
            }
            focusPolicy: Qt.NoFocus
        }
        Button {
            text: "Send new data input value"
            property int invocationCount: 0
            onClicked: s3d.textValue = "Data input value " + (++invocationCount)
            focusPolicy: Qt.NoFocus
        }
    }

    Text {
        id: fpsCount
        text: "0 FPS"
        anchors.bottom: parent.bottom
        anchors.left: parent.left
    }
    Text {
        id: customSignalName
        anchors.bottom: parent.bottom
        anchors.left: fpsCount.right
        anchors.leftMargin: 8
    }
    Text {
        id: slideEnter
        anchors.bottom: parent.bottom
        anchors.left: customSignalName.right
        anchors.leftMargin: 8
    }
    Text {
        id: slideExit
        anchors.bottom: parent.bottom
        anchors.left: slideEnter.right
        anchors.leftMargin: 8
    }
    Button {
        id: nextSlideByIndex
        text: "Next slide (via pres., wrap)"
        anchors.left: parent.left
        anchors.bottom: fpsCount.top
        onClicked: s3dpres.goToSlide("Scene", true, true)
        focusPolicy: Qt.NoFocus
    }
    Button {
        id: seekBtn
        text: "Seek to 5 seconds (via pres.)"
        anchors.left: nextSlideByIndex.right
        anchors.bottom: fpsCount.top
        onClicked: s3dpres.goToTime("Scene", 5)
        focusPolicy: Qt.NoFocus
    }
    Button {
        id: nextSlideViaSceneElement
        text: "Next slide (via SceneElement, no wrap)"
        anchors.left: seekBtn.right
        anchors.bottom: fpsCount.top
        onClicked: sceneElementForScene.currentSlideIndex += 1
        focusPolicy: Qt.NoFocus
    }
    Button {
        id: seekBtn2
        text: "Seek to 5 seconds (via SceneElement)"
        anchors.left: nextSlideViaSceneElement.right
        anchors.bottom: fpsCount.top
        onClicked: sceneElementForScene.goToTime(5)
        focusPolicy: Qt.NoFocus
    }

    Button {
        id: profTogBtn
        text: "Toggle render stats"
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        focusPolicy: Qt.NoFocus
        onClicked: viewerSettings.showRenderStats = !viewerSettings.showRenderStats
    }
    Slider {
        id: profUiScale
        width: profTogBtn.width
        anchors.right: profTogBtn.left
        anchors.bottom: parent.bottom
        from: 50
        to: 400
        value: 100
        focusPolicy: Qt.NoFocus
    }

    FileDialog {
        id: openDialog
        fileMode: FileDialog.OpenFile
        nameFilters: ["UIP files (*.uip)", "UIA files (*.uia)", "All files (*)"]
        onAccepted: s3dpres.source = file
    }
}