TabCamera.qml 5.94 KB
Newer Older
Artem Sidyakin's avatar
Artem Sidyakin committed
1 2 3 4
import QtQuick 2.11
import QtQuick.Layouts 1.11
import QtQuick.Controls 2.4
import QtMultimedia 5.11
Artem Sidyakin's avatar
Artem Sidyakin committed
5
//import Qt.labs.handlers 1.0
Artem Sidyakin's avatar
Artem Sidyakin committed
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

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"

Artem Sidyakin's avatar
Artem Sidyakin committed
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
            Camera {
                id: camera
                //cameraState: tabCamera.checked ? Camera.ActiveState : Camera.LoadedState
                viewfinder.resolution: Qt.size(848, 480) // picture quality
                metaData.orientation: cameraUpsideDown ? 180 : 0

//                focus {
//                    focusMode: Camera.FocusMacro
//                    focusPointMode: Camera.FocusPointCenter
//                }

                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);
Artem Sidyakin's avatar
Artem Sidyakin committed
70 71 72 73 74 75 76

//                            var supRezes = camera.supportedViewfinderResolutions();
//                            for (var rez in supRezes)
//                            {
//                                console.log(supRezes[rez].width, "x", supRezes[rez].height);
//                            }
                }
Artem Sidyakin's avatar
Artem Sidyakin committed
77 78 79 80 81 82 83 84 85 86 87 88
            }

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

//                TapHandler {
//                    onTapped: console.log(point.position.x, point.position.y)
//                }
            }
89 90 91 92 93 94

//                Image {
//                    anchors.fill: parent
//                    source: "img/viewfinder.png"
//                    visible: camera.cameraState == Camera.ActiveState
//                }
Artem Sidyakin's avatar
Artem Sidyakin committed
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186
//                    }
        }

        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 {
                anchors.fill: parent
                source: "/img/camera.png"
            }

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