qmlFrontend/qml/qmlFrontend/main.qml
author unc0rr
Sat, 21 Nov 2015 17:07:06 +0300
branchqmlfrontend
changeset 11423 e045dc60c37e
parent 11415 05cf35103206
child 11424 86c13e5662f1
permissions -rw-r--r--
- Warnings/errors message box - Send JOIN_ROOM on double click on rooms list - Some small iprovements more

import QtQuick 2.0
import Hedgewars.Engine 1.0

Rectangle {
    id: pages
    width: 800
    height: 600

    property variant pagesList  : [
        "First"
        , "LocalGame"
        , "GameConfig"
        , "Connect"
        , "LobbyPage"
    ];

    property string  currentPage : "First";

    Repeater {
        model: pagesList;

        delegate: Loader {
            active: false
            asynchronous: true
            anchors.fill: parent
            visible: (currentPage === modelData)
            source: "%1.qml".arg(modelData)
            onVisibleChanged:      loadIfNotLoaded();
            Component.onCompleted: loadIfNotLoaded();

            function loadIfNotLoaded ()
            {
                if (visible && !active)
                    active = true;
            }
        }
    }

    Rectangle {
        id: warningsBox
        y: parent.height - height
        width: parent.width - 120
        height: 80
        anchors.horizontalCenter: parent.horizontalCenter
        color: "#7e3232"
        border.color: "#d3ec2d"
        visible: false
        z: 2

        function showMessage(message) {
            msgBox.text = message
            visible = true
        }

        Text {
            id: msgBox
            x: 0
            y: 0
            height: parent.height
            font.pixelSize: 12
            wrapMode: Text.Wrap
        }
        HWButton {
            id: closeButton
            x: parent.width - width
            y: 0
            width: 40
            height: 40
            onClicked: warningsBox.visible = false
        }
    }

    Connections {
        target: HWEngine
        onNetConnected: currentPage = "LobbyPage";
        onNetDisconnected: currentPage = "First";
        onWarningMessage: warningsBox.showMessage(message);
        onErrorMessage: warningsBox.showMessage(message);
    }
}