main.qml 10.4 KB
Newer Older
Tomi Korpipää's avatar
Tomi Korpipää committed
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
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt 3D Studio Demos.
**
** $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$
**
****************************************************************************/

51
import QtQuick 2.9
Laszlo Agocs's avatar
Laszlo Agocs committed
52
import QtStudio3D 2.0
Tomi Korpipää's avatar
Tomi Korpipää committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
import QtQuick.Controls 2.1

Item {
    id: mainview

    focus: true

    property bool startupAnimation: true
    property bool allowSelection: true

    property int contentIndex: 1
    property int previousContentIndex: 0
    property int maxContentIndex: 5

    property int selectedMenuIndex: 0
    property int maxMenuIndex: 5

70 71 72 73 74 75 76 77 78 79 80 81 82
    property bool useMetric: true
    property bool redTheme: true

    property string esc: "On"
    property string trafficSigns: "Recognition"
    property string autoHighBeam: "On"
    property string hdLampDelay: "20 seconds"
    property string auxHeater: "On"
    property string parkHeater: "Time 2"
    property string chimesPark: "Off"
    property string chimesInfo: "Off"
    property string chimesWarning: "On"

Tomi Korpipää's avatar
Tomi Korpipää committed
83 84 85
    Studio3D {
        id: studio3D
        width: parent.width
86
        height: parent.height
Tomi Korpipää's avatar
Tomi Korpipää committed
87 88 89
        anchors.verticalCenter: parent.verticalCenter

        ViewerSettings {
90
            scaleMode: ViewerSettings.ScaleModeFit
Tomi Korpipää's avatar
Tomi Korpipää committed
91 92 93 94 95 96 97 98 99 100 101
        }

        Presentation {
            id: cluster
            source: "qrc:/presentation/mainPresentation.uia"

            onSlideEntered: {
                if (name === "Base")
                    startupAnimation = false;
            }

102
            DataInput {
Tomi Korpipää's avatar
Tomi Korpipää committed
103
                id: mainScene
104
                name: "mainSlide"
Tomi Korpipää's avatar
Tomi Korpipää committed
105 106
            }

107
            DataInput {
Tomi Korpipää's avatar
Tomi Korpipää committed
108
                id: carScene
109
                name: "carSlide"
Tomi Korpipää's avatar
Tomi Korpipää committed
110 111
            }

112 113
            DataInput {
                name: "tacho"
114
                value: simuData.rpm
Tomi Korpipää's avatar
Tomi Korpipää committed
115 116
            }

117 118
            DataInput {
                name: "tachoText"
119
                value: (simuData.rpm / 1000.0).toFixed(1)
Tomi Korpipää's avatar
Tomi Korpipää committed
120 121
            }

122 123
            DataInput {
                name: "speed"
124
                value: simuData.speed
Tomi Korpipää's avatar
Tomi Korpipää committed
125 126
            }

127 128
            DataInput {
                name: "speedText"
129
                value: useMetric ? simuData.speed.toFixed(0) : (simuData.speed / 1.625).toFixed(0)
Tomi Korpipää's avatar
Tomi Korpipää committed
130 131
            }

132 133
            DataInput {
                name: "colorSlide"
134
                value: redTheme ? "red" : "blue"
135 136
            }

137 138
            DataInput {
                name: "speedUnitSlide"
139
                value: useMetric ? "kph" : "mph"
140 141
            }

142 143 144
            DataInput {
                name: "displayColor"
                value: redTheme ? Qt.vector3d(0.855, 0.14, 0.144) : Qt.vector3d(0.08, 0.08, 1.0)
145 146
            }

Tomi Korpipää's avatar
Tomi Korpipää committed
147 148 149 150 151 152
            SubPresentationSettings {
                qmlStreams: [
                    QmlStream {
                        presentationId: "navigationStream"
                        Loader {
                            id: contentStream
Tomi Korpipää's avatar
Tomi Korpipää committed
153 154 155 156
                            active: false
                            visible: active
                            source: ""
                            asynchronous: true
Tomi Korpipää's avatar
Tomi Korpipää committed
157 158 159 160 161
                        }
                    }
                ]
            }
        }
162

163 164 165 166 167
        onPresentationReady: {
            indicatorPane.visible = true;
            content.visible = true;
        }

168 169
        // Hack. We need to draw something in QML in each frame to minimize the jamming of
        // Studio3D content.
170
        property bool direction: false
171
        onFrameUpdate: {
172 173
            direction = !direction;
            if (direction)
174
                studio3D.x += 0.1;
175
            else
176
                studio3D.x -= 0.1;
177
        }
Tomi Korpipää's avatar
Tomi Korpipää committed
178

Tomi Korpipää's avatar
Tomi Korpipää committed
179 180 181 182 183 184
    }

    OverlayContainer {
        id: indicatorPane
        scale: mainview.width / 2560
        anchors.centerIn: mainview
185
        visible: false
Tomi Korpipää's avatar
Tomi Korpipää committed
186 187 188 189 190 191 192
    }

    Loader {
        id: content
        scale: mainview.width / 2560
        source: "qrc:/SettingsContainer.qml"
        anchors.centerIn: parent
193
        visible: false
Tomi Korpipää's avatar
Tomi Korpipää committed
194 195 196
    }

    Keys.onRightPressed: {
197
        userActivity();
Tomi Korpipää's avatar
Tomi Korpipää committed
198 199 200 201
        menuSelect(true);
    }

    Keys.onLeftPressed: {
202
        userActivity();
Tomi Korpipää's avatar
Tomi Korpipää committed
203 204 205 206
        menuSelect(false);
    }

    Keys.onUpPressed: {
207
        userActivity();
Tomi Korpipää's avatar
Tomi Korpipää committed
208 209 210 211 212 213
        selectedMenuIndex--;
        if (selectedMenuIndex < 0)
            selectedMenuIndex = 0;
    }

    Keys.onDownPressed: {
214
        userActivity();
Tomi Korpipää's avatar
Tomi Korpipää committed
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
        selectedMenuIndex++;
        if (selectedMenuIndex > maxMenuIndex)
            selectedMenuIndex = maxMenuIndex;
    }

    // Simulated speed and rpm data
    SimuData {
        id: simuData

        onTimeChanged: {
            indicatorPane.time.text = time;
        }
    }

    function menuSelect(next) {
        if (!allowSelection)
            return;

        previousContentIndex = contentIndex;

        // settings - navigation - music - call - car
        if (next)
            contentIndex++;
        else
            contentIndex--;

        if (contentIndex > maxContentIndex)
            contentIndex = 1;
        else if (contentIndex < 1)
            contentIndex = maxContentIndex;

        selectContent(contentIndex);
    }

    function selectContent(index) {
        if (previousContentIndex === index)
            return;

        selectedMenuIndex = 0;
        indicatorPane.select(index);
        contentStream.source = "";
        contentStream.active = false;

        if (previousContentIndex === 2) { // from Navigation
            allowSelection = false;
            selectionTimer.start();
261
            mainScene.setValue("ToBase");
Tomi Korpipää's avatar
Tomi Korpipää committed
262 263 264
        } else if (previousContentIndex === 5) { // from Car
            allowSelection = false;
            selectionTimer.start();
265
            carScene.setValue("FadeOut");
Tomi Korpipää's avatar
Tomi Korpipää committed
266 267 268 269 270 271 272 273 274 275
        }

        switch (index) {
        case 1: // Settings
            content.source = "qrc:/SettingsContainer.qml";
            break;
        case 2: // Navigation
            allowSelection = false;
            selectionTimer.start();
            content.source = "";
276
            mainScene.setValue("ToNavigation");
Tomi Korpipää's avatar
Tomi Korpipää committed
277 278 279 280 281 282 283 284 285 286 287 288 289
            contentStream.source = "qrc:/Navigation.qml";
            contentStream.active = true;
            break;
        case 3: // Music
            content.source = "qrc:/MusicContainer.qml";
            break;
        case 4: // Call
            content.source = "qrc:/ContactsContainer.qml";
            break;
        case 5: // Car
            allowSelection = false;
            selectionTimer.start();
            content.source = "";
290
            carScene.setValue("FadeIn");
Tomi Korpipää's avatar
Tomi Korpipää committed
291 292 293 294
            break;
        }
    }

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    // Trigger this to stop automatic demoing mode and/or
    // keep it from not starting.
    function userActivity() {
        automaticDemoDelay.restart();
        if (automaticDemoingTimer.running)
            automaticDemoingTimer.stop();
    }

    Timer {
        id: automaticDemoDelay
        // Non-interactivity delay
        interval: 60000
        repeat: false
        running: true
        onTriggered: {
            automaticDemoingTimer.start();
        }
    }

    Timer {
        id: automaticDemoingTimer
        interval: 8000
        repeat: true
        running: false
        triggeredOnStart: true
        onTriggered: {
            // Switch mode automatically when triggered
            mainview.menuSelect(true);
        }
    }

Tomi Korpipää's avatar
Tomi Korpipää committed
326 327 328 329 330
    Timer {
        id: selectionTimer
        interval: 1000
        onTriggered: allowSelection = true;
    }
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

    Image {
        id: automaticIcon
        readonly property bool show: automaticDemoingTimer.running
        property real iconOpacity: 0
        anchors.top: parent.top
        anchors.topMargin: 16
        anchors.left: parent.left
        anchors.leftMargin: 16
        source: "qrc:/icons/automatic.png"
        width: 48
        height: 24
        opacity: show ? iconOpacity : 0
        SequentialAnimation on iconOpacity {
            running: automaticIcon.show
            loops: Animation.Infinite
            alwaysRunToEnd: true
            NumberAnimation {
                to: 0.2
                duration: 1000
                easing.type: Easing.InOutQuad
            }
            NumberAnimation {
                to: 0
                duration: 1000
                easing.type: Easing.InOutQuad
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        z: 100
        onPressed: {
            // Record user activity and pass event further
            userActivity();
            mouse.accepted = false;
        }
    }
Tomi Korpipää's avatar
Tomi Korpipää committed
370
}