import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Fluent as Fluent
import Analyser

Window {
    id: window
    width: 1120
    height: 650
    visible: true
    title: qsTr(Qt.application.name + " " + Qt.application.version)

    OperationItem {
        id: operationItem
        width: 530
        anchors.top: parent.top
    }

    ColumnLayout {
        anchors.left: operationItem.right
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        TabBar {
            id: bar
            width: parent.width
            TabButton {
                implicitWidth: 100
                text: qsTr("视频流")
            }
            TabButton {
                text: qsTr("日志")
            }
        }

        StackLayout {
            width: parent.width
            currentIndex: bar.currentIndex
            Item {
                Image {
                    id: image
                    property real aspectRatio: 600 / 800
                    anchors.centerIn: parent
                    width: Math.min(parent.width, parent.height * aspectRatio)
                    height: width / aspectRatio
                    cache: false
                    fillMode: Image.PreserveAspectFit
                    source: "image://videoframe/"
                }
                Image {
                    anchors.fill: image
                    source: "qrc:/qt/qml/Analyser/resources/palm-middle.png"
                }
            }
            Item {
                ScrollView {
                    id: view
                    anchors.fill: parent
                    TextArea {
                        id: logBrowser
                        readOnly: true
                        wrapMode: TextArea.WordWrap
                    }
                }
                Button {
                    text: "清空"
                    anchors.right: parent.right
                    anchors.bottom: parent.bottom
                    onClicked: logBrowser.clear()
                }
            }
        }
    }

    Fluent.InfoBar{
        id:info_bar
        root: window
        layoutY: 10
    }

    Connections {
        target: App
        function onNewLog(text) {
            logBrowser.append(text)
        }
        function onNewStatusTip(level, tip, detailMessage) {
            if (level === App.Tip) {
                info_bar.showSuccess(tip,2000,detailMessage)
            } else if (level === App.Warnging) {
                info_bar.showWarning(tip,2000,detailMessage)
            } else if (level === App.Error) {
                info_bar.showError(tip,2000,detailMessage)
            } else if (level === 2) {
                info_bar.showInfo(tip,2000,detailMessage)
                resultBrowser.append(tip+":"+detailMessage)
            }
        }
        function onNewVideoFrame() {
            image.source = ""
            image.source = "image://videoframe/"
        }
    }
}