C

Qt Quick Ultralite swipe_game Demo

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

import QtQuick 2.0
import StyleModule 1.0

/*
    This view displays the game's starting value and provides
    a switch to change the game mode. It will start the game automatically
    if the mode wasn't changes for specific amount of time.
*/

BaseView {
    id: root

    signal gameStarted()

    onVisibleChanged: {
        if (visible) {
            delayTimer.restart()
        } else {
            delayTimer.stop()
        }
    }

    Text {
        id: userHint

        anchors {
            top: parent.top
            topMargin: Style.marginDefault
            horizontalCenter: parent.horizontalCenter
        }
        font: Style.textFontSmall
        color: Style.colorLightText
        text: "longpress to stop"
    }

    Text {
        id: questionText

        anchors {
            top: userHint.bottom
            topMargin: Style.marginDefault
            horizontalCenter: parent.horizontalCenter
        }
        font: Style.textFontDefault
        color: Style.colorText
        text: "Start Value"
    }

    Text {
        id: startValue

        anchors.centerIn: parent
        font: Globals.isNumberMode() ? Style.textFontBig : Style.textFontDefault
        color: Style.colorText
        text: Globals.isNumberMode() ? Globals.gameStartNumber : Globals.gameStartCountry
    }

    LabeledSwitch {
        id: modeSwitch

        anchors {
            bottom: parent.bottom
            bottomMargin: Style.marginBig
            horizontalCenter: parent.horizontalCenter
        }
        text: "Mode"
        font: Style.textFontSmall
        checked: Globals.isNumberMode()

        onTriggered: {
            Globals.switchGameMode()
            delayTimer.restart()
        }
    }

    Timer {
        id: delayTimer

        interval: Style.gameStartDelay

        onTriggered: {
            Globals.requestNewValue()
            root.gameStarted()
        }
    }
}