import QtQuick 2.11

Item  {
    id: root
    property bool isFirst : false;
    //width: 200
    //height: 200
    //color: "blue"
    //anchors.fill: parent



    Loader {
        id: pageLoader
        anchors.fill: parent
        //source: "Page2.qml"
        //sourceComponent: defaultPage
        focus: true
        onStatusChanged:  console.log(pageLoader.status == Loader.Ready)
        onLoaded: console.log("Loaded")
    }

    MouseArea {
        id:mousearea
        anchors.fill: parent

    }

    function show(){
        pageLoader.source = "Page2.qml"
        //pageLoader.item.show()
        console.log("pagedefault show")
    }



    Connections{
        target: mousearea
        onClicked: root.changePage()
    }


    function changePage()
    {
        if(isFirst) {
            pageLoader.source = "Page1.qml"
        } else {
            pageLoader.source = "Page2.qml"
        }

        isFirst = !isFirst;
    }



    Component {
        id: defaultPage
        Rectangle {
            width: 200
            height: 50
            color: "red"
            Text {
                text: "Default Page"
                anchors.fill: parent
            }
        }
    }

    Keys.onPressed: {
        console.log("Captured: ", event.text);
         event.accepted = true;
    }

/*
    Component.onCompleted: {
        rect1.changePage()
    }

    */
}

