TabCamera.qml 5.71 KB
Newer Older
Artem Sidyakin's avatar
Artem Sidyakin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.Layouts 1.11
import QtQuick.Controls 2.4
import QtMultimedia 5.11

Item {
    GridLayout {
        anchors.fill: parent
        rows: 2
        columns: 2
        rowSpacing: 0
        columnSpacing: 0

        Rectangle {
            Layout.row: 0
            Layout.column: 0
            Layout.fillWidth: true
            Layout.fillHeight: true

            Text {
                id: cameraStatus
                anchors.centerIn: parent
                width: parent.width
                text: qsTr("loading camera...")
                font.pixelSize: 40
                horizontalAlignment: Text.AlignHCenter
                wrapMode: Text.WordWrap
            }

//                    Rectangle {
//                        anchors.fill: parent
//                        border.width: 5
//                        border.color: "gray"

                VideoOutput {
                    anchors.fill: parent
                    orientation: cameraUpsideDown ? 180 : 0
                    fillMode: VideoOutput.PreserveAspectCrop
                    source: camera

                    Camera {
                        id: camera
                        //cameraState: tabCamera.checked ? Camera.ActiveState : Camera.LoadedState
                        viewfinder.resolution: Qt.size(848, 480) // picture quality
                        metaData.orientation: cameraUpsideDown ? 180 : 0

                        imageCapture {
                            onCaptureFailed: {
                                dialogError.textMain = "Some error taking a picture\n" + message;
                                dialogError.show();
                            }
                            onImageCaptured: {
                                //console.log("photo has been captured")
                            }
                            onImageSaved: {
                                //console.log("photo has been saved:", camera.imageCapture.capturedImagePath)
                            }
                        }

                        onError: {
                            cameraStatus.text = qsTr("Error: ") + errorString;
                            console.log(errorCode, errorString);
                        }

                        Component.onCompleted: {
                            //console.log(qsTr("camera orientation:"), camera.orientation);
                            //console.log(qsTr("camera state:"), camera.cameraState);
                            //console.log(qsTr("camera status:"), camera.cameraStatus);
                            //console.log(qsTr("camera supported resolutions:"), imageCapture.supportedResolutions);

//                            var supRezes = camera.supportedViewfinderResolutions();
//                            for (var rez in supRezes)
//                            {
//                                console.log(supRezes[rez].width, "x", supRezes[rez].height);
//                            }
                        }
                    }
                }
//                    }
        }

        Rectangle {
            Layout.row: 1
            Layout.column: 0
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.maximumHeight: root.maxSize
            color: root.sliderColor

            Slider {
                id: sliderPan
                anchors.fill: parent
                orientation: Qt.Horizontal
                from: root.maxValue
                value: 0
                stepSize: 1
                to: -root.maxValue

                onPressedChanged: {
                    if (!pressed)
                    {
                        //console.log("new pan value:", sliderPan.value)
                        backend.movePanTilt(basePath, sliderPan.value, sliderTilt.value)
                    }
                }

//                onValueChanged: {
//                    console.log("new pan value:", sliderPan.value)
//                    backend.movePanTilt(basePath, sliderPan.value, sliderTilt.value)
//                }
            }
        }

        Rectangle {
            Layout.row: 0
            Layout.column: 1
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.maximumWidth: root.maxSize
            color: root.sliderColor

            Slider {
                id: sliderTilt
                anchors.fill: parent
                orientation: Qt.Vertical
                from: root.maxValue
                value: 0
                stepSize: 1
                to: -root.maxValue

                onPressedChanged: {
                    if (!pressed)
                    {
                        //console.log("new tilt value:", sliderTilt.value)
                        backend.movePanTilt(basePath, sliderPan.value, sliderTilt.value)
                    }
                }

//                onValueChanged: {
//                    console.log("new tilt value:", sliderTilt.value)
//                    backend.movePanTilt(basePath, sliderPan.value, sliderTilt.value)
//                }
            }
        }

        Button {
            Layout.row: 1
            Layout.column: 1
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.maximumWidth: root.maxSize
            Layout.maximumHeight: root.maxSize

            scale: hovered ? (pressed ? 0.9 : 1.1) : 1

            background: Rectangle {
                color: "transparent"
            }

            Image {
                id: cameraIcon
                anchors.fill: parent
                source: "/img/camera.png"
            }

            onClicked: {
                camera.imageCapture.captureToLocation(basePath + "shots/" + getCurrentDateTime() + ".jpg");
            }
        }
    }
}