IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Coffee Machine Example

A Qt Quick application with a state-based custom user interface.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Coffee Machine Example

Image non disponible

The coffee machine application lets you choose a type of coffee on the left side of the main screen. After selection, the app displays what the coffee blend will contain (ratio coffee/hot milk/milk foam). This can be modified with two sliders. When the brew has been started, the app shows an animated display of the brewing process, then returns to the start screen.

First the start screen Animationflowform is displayed, showing a sidebar with several types of coffee, and an empty cup on the right screen.

Selecting a coffee type - for example, cappuccino - triggers animation1 and animation2 in CoffeeButton.qml. On the right side, you will see the coffee blend you selected.

 
Sélectionnez
    MouseArea {
        anchors.fill: parent
        onClicked: root.clicked()
        onPressed: {
            glow.visible = true
            animation1.start()
            animation2.start()
        }
    }

It also triggers cappuccinoButton.onClicked(), which sets the default mix for the coffee type selected:

 
Sélectionnez
    cappuccinoButton.onClicked: {
        sideBar.currentCoffee = qsTr("Cappucino")
        sideBar.currentMilk = 7
        sideBar.currentCoffeeAmount = 3.5
        sideBar.coffeeSelected()
    }
Image non disponible

sideBar.coffeeSelected() sets applicationFlow.state to "selection"

If you click "Brew me a cup", choosingCoffee.brewButtonSelection.onClicked is triggered:

 
Sélectionnez
    choosingCoffee.brewButtonSelection.onClicked: {
        applicationFlow.state = "settings"
        applicationFlow.choosingCoffee.milkSlider.value = applicationFlow.choosingCoffee.sideBar.currentMilk
        applicationFlow.choosingCoffee.sugarSlider.value = 2
    }

On the right side of the screen, you will see two sliders, one for the amount of milk, and one for sugar. They will have default values, but can be modified by the user.

Image non disponible

If you click on Brew, choosingCoffee.brewButton.onClicked() is triggered, which displays a screen with the message "Please insert cup into tray".

 
Sélectionnez
    choosingCoffee.brewButton.onClicked: {
        applicationFlow.state = "empty cup"
    }
Image non disponible

Clicking on Continue starts the brewing of the coffee type you selected.

 
Sélectionnez
    emptyCup.continueButton.onClicked: {
        applicationFlow.state = "brewing"
        brewing.coffeeName = choosingCoffee.sideBar.currentCoffee
        brewing.start()
    }

The brewing process is defined as follows in Brewing.qml:

 
Sélectionnez
BrewingForm {
    id: root
    function start() {
        animation.start()
    }

    signal finished()

    SequentialAnimation {
        id: animation
        PauseAnimation {
            duration: 1500
        }
        PropertyAction {
            target: root
            property: "state"
            value: "coffee"
        }
        PauseAnimation {
            duration: 1500
        }
        PropertyAction {
            target: root
            property: "state"
            value: "milk"
        }
        PauseAnimation {
            duration: 1500
        }
        ScriptAction {
            script: root.finished()
        }
    }

    Behavior on cup.coffeeAmount {
        PropertyAnimation {

        }
    }

    Behavior on cup.milkAmount {
        PropertyAnimation {
        }
    }
}

After completion, the application returns to the start screen.

Example project

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+