import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.14
import QtQuick.Dialogs 1.3
import QtQuick.Controls.Styles 1.4
import QtQuick.VirtualKeyboard 2.15

import TService 1.0
import BackendLogic 1.0

Window {
    id:main_window
    width: 1280
    height: 760
    visible: true
    title: qsTr("油气回收测试装备")

    flags:Qt.FramelessWindowHint


    Image {
        id: bg
        anchors.horizontalCenter: parent.horizontalCenter
        fillMode: Image.PreserveAspectFit
        source: "img/main_zjtj_bj.jpg"
        //source: "img/main_jl_bj.jpg"
    }



    BackendLogic {
            id: backend
    }

    Rectangle{
        id: logo
        x: 20
        y: 20

        width:300
        height:100
        color:"transparent"

        Image {
            anchors.fill:parent
            fillMode: Image.PreserveAspectFit
            source:"img/zjtj_logo.png"
            //source:"img/jl_logo.png"
        }

    }



    UserButton {
        text: "登  录"
        font.bold: true
        font.pixelSize: 24
        width:180
        height:60
        anchors.centerIn: parent

/*
        background: Image {
            anchors.fill:parent
            fillMode: Image.PreserveAspectFit
            source:"img/blue_button.png"
        }
        */
        //icon.source: "img/blue_button.png"
        //icon.color: "transparent"


        onClicked: myLoder.sourceComponent = mainpage // 切换显示主页面
    }

    Button {
        //text: "点击进入"
        width:80
        height:80
        anchors.right: parent.right
        anchors.rightMargin: 40;
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 40;
        //color:"transparent"
        background:Image {
            anchors.fill:parent
            fillMode: Image.PreserveAspectFit
            source:"img/shutdown_red.png"
        }

        onClicked: {
            backend.shutdown()
        }
    }

    Rectangle{
        id: info
        x: 30
        y: 650

        width:500
        height:400
        color:"transparent"

        Column{
            spacing: 2
            Text {
                id: ver_text
                text: qsTr("软件版本: V2.1.2")
                font.bold: true
            }

            Text {
                id: model_text
                text: qsTr("")
                font.bold: true
            }

            Text {
                id: devid_text
                text: qsTr("")
                font.bold: true
            }

            Text {
                id: manufacture_text
                text: qsTr("")
                font.bold: true
            }
        }

    }




    Item {
        id: cornerItem
        x: 0
        y: 0
    }

    property int activeFocusItemBottom : activeFocusItem == null ? 0 : Math.min(height, cornerItem.mapFromItem(activeFocusItem, 0, activeFocusItem.height).y + 50)



    Loader{
        id:myLoder
        anchors.centerIn: parent
    }

    Component.onCompleted:{
        var jsonobj = backend.getDeviceInfo()
        model_text.text = "设备型号:"+jsonobj.model
        devid_text.text = "设备ID:"+jsonobj.id
        //manufacture_text.text = "制造商:"+jsonobj.manufacture

    }

    Component{
        id:firstpage
        PageFirst{
            width:300
            height: 200
            anchors.centerIn: parent
        }
    }

    Component{
        id:mainpage
        PageMain{
            width: 1280
            height: 760
            anchors.centerIn: parent
        }
    }


    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: main_window.height
        width: main_window.width


        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: main_window.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
    }



}



