Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

FlightControls.qml 28.4 KB
Newer Older
Eike Hein's avatar
Eike Hein 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
/*
 * Copyright 2019 Eike Hein <hein@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.12
import QtQuick.Controls 2.12 as QQC2

import org.kde.kirigami 2.6 as Kirigami

import org.freedesktop.gstreamer.GLVideoItem 1.0

import org.kde.kirogi 0.1 as Kirogi

Kirigami.Page {
    id: page

    LayoutMirroring.enabled: false
    LayoutMirroring.childrenInherit: true

    readonly property int yardstick: Math.min(parent.width, parent.height)
    readonly property bool touched: leftTouchPoint.active || rightTouchPoint.active

39 40
    property alias gamepad: gamepadLoader.item

Eike Hein's avatar
Eike Hein committed
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
    leftPadding: 0
    rightPadding: 0
    topPadding: 0
    bottomPadding: 0

    Connections {
        target: kirogi

        onCurrentPageChanged: updatePilotingState()
        onCurrentVehicleChanged: updatePilotingState()
        onReadyChanged: updatePilotingState()
    }

    function updatePilotingState() {
        var vehicle = kirogi.currentVehicle;

        if (!vehicle || !vehicle.ready) {
            return;
        }

        vehicle.setPiloting(kirogi.currentPage == page);

        if (kirogi.currentPage == page && !kirogi.currentVehicle.videoStreamEnabled
            && vehicle.isActionSupported(Kirogi.AbstractVehicle.ToggleVideoStream)) {
            vehicle.requestEnableVideoStream(true);
        }
    }

    Image {
        id: cameraStream

        anchors.fill: parent

        fillMode: Image.PreserveAspectCrop
        smooth: true

        source: "fallback.jpg"

        Connections {
            target: kirogi

            onCurrentVehicleChanged: {
                videoPlayer.playing = kirogi.currentVehicle != null;
            }

            onCurrentPageChanged: {
                videoPlayer.playing = (kirogi.currentPage == page || kirogi.currentVehicle);
            }
        }

        Binding {
            target: videoPlayer
            property: "pipeline"
            value: kirogi.currentVehicle ? kirogi.currentVehicle.videoSource : ""
        }

        GstGLVideoItem {
            anchors.centerIn: parent

            width: parent.width
            height: parent.width/1.77 // FIXME: Work with non-16:9 videos.

            objectName: "videoOutput"
        }

        Rectangle {
            id: videoOverlay

            anchors.fill: parent

            visible: !kirogi.currentVehicle || kirogi.currentVehicle.videoSource === ""

            opacity: 0.4

            color: "black"
        }
    }

    // FIXME TODO: This is a workaround around the org.kde.desktop+Breeze style engine
    // hijacking drag on the window.
    TapHandler {
        enabled: !Kirigami.Settings.isMobile
    }

    Item {
        anchors.left: parent.left

        width: parent.width / 2
        height: parent.height


        PointHandler {
            id: leftTouchPoint

            enabled: inputMode.selectedMode == 0 || kirogiSettings.alwaysShowDPads

            grabPermissions: PointerHandler.ApprovesTakeOverByAnything | PointerHandler.ApprovesCancellation
        }
    }

    Item {
        anchors.right: parent.right

        width: parent.width / 2
        height: parent.height

        PointHandler {
            id: rightTouchPoint

            enabled: inputMode.selectedMode == 0 || kirogiSettings.alwaysShowDPads
        }
    }

    TouchButton {
        id: leftButton

        anchors.top: leftPillBox.bottom
        anchors.topMargin: Math.round(leftPillBox.y * 1.5)
        anchors.left: parent.left
        anchors.leftMargin: leftPillBox.y

        background: cameraStream
        icon: kirogi.currentVehicle ? kirogi.currentVehicle.iconName : "uav"
        toolTipText: i18nc("%1 = Keyboard shortcut", "Drone (%1)", vehiclePageAction.__shortcut.nativeText)

        onTapped: switchApplicationPage(vehiclePage)
    }

    PillBox {
        id: launchButton

        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: Kirigami.Units.smallSpacing

        width: Math.min(launchButtonLabel.implicitWidth + Kirigami.Units.smallSpacing * 4,
            rightPillBox.x - leftPillBox.x - leftPillBox.width - (leftPillBox.x * 2))
        height: 2 * Math.round((leftPillBox.height * 1.12) / 2);

        readonly property var __color: {
            if (launchButtonMouseArea.containsMouse) {
                return Kirigami.Theme.hoverColor;
            }

            if (kirogi.connected) {
                if (kirogi.flying) {
                    return "red";
                } else if (kirogi.ready) {
                    return "green";
                } else {
                    return "yellow";
                }
            }

            return "red";
        }

        background: cameraStream
        backgroundColor: "dark" + __color
        backgroundOpacity: 0.4

        borderWidth: 2
        borderRadius: height / 4
        borderColor: launchButtonLabel.color

        Text {
            id: launchButtonLabel

            anchors.fill: parent

            font.pixelSize: parent.height * 0.7
            font.bold: true
            color: launchButton.__color

            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter

            elide: Text.ElideRight

            text: {
                if (kirogi.connected) {
                    if (kirogi.flying) {
                        return i18n("LAND");
                    } else if (kirogi.ready) {
                        return i18n("TAKE OFF");
                    } else {
                        return i18n("PREPARING")
                    }
                }

                return i18n("DISCONNECTED");
            }

            Behavior on color {
                enabled: !launchButtonMouseArea.pressed

                ColorAnimation { duration: Kirigami.Units.shortDuration }
            }
        }

        MouseArea {
            id: launchButtonMouseArea

            anchors.fill: parent

            enabled: kirogi.ready
            hoverEnabled: enabled

            onClicked: {
                if (kirogi.flying) {
                    kirogi.currentVehicle.requestLand();
                } else {
                    kirogi.currentVehicle.requestTakeOff();
                }
            }
        }
    }

    TouchButton {
        id: rightButton

        anchors.top: rightPillBox.bottom
        anchors.topMargin: leftButton.anchors.topMargin
        anchors.right: parent.right
        anchors.rightMargin: leftButton.anchors.leftMargin

        background: cameraStream
        icon: "map-flat"
        toolTipText: i18nc("%1 = Keyboard shortcut", "Navigation Map (%1)", navigationMapPageAction.__shortcut.nativeText)

        onTapped: switchApplicationPage(navigationMapPage)
    }

    ModeRocker {
        id: flightMode

        enabled: kirogi.ready

        anchors.left: parent.left
        anchors.verticalCenter: shotButton.verticalCenter

        background: cameraStream

        selectedMode: {
            if (kirogi.ready) {
                if (kirogi.currentVehicle.performanceMode == Kirogi.AbstractVehicle.FilmPerformance) {
                    return 0;
                } else if (kirogi.currentVehicle.performanceMode == Kirogi.AbstractVehicle.SportPerformance) {
                    return 1;
                }
            }

            return -1;
        }

        firstLabelText: i18n("FILM")
        firstToolTipText: i18n("Fly Slow")

        secondLabelText: i18n("SPORT")
        secondToolTipText: i18n("Fly Fast")

        onModeTapped: {
            if (selectedMode == mode) {
                return;
            }

            if (mode == 0) {
                kirogi.currentVehicle.requestPerformanceMode(Kirogi.AbstractVehicle.FilmPerformance);
            } else if (mode == 1) {
                kirogi.currentVehicle.requestPerformanceMode(Kirogi.AbstractVehicle.SportPerformance);
            }
        }

        Component.onCompleted: {
            var handleWidth = kirogi.LayoutMirroring.enabled ? parent.width - globalDrawer.handle.x
                : globalDrawer.handle.x + globalDrawer.handle.width;
            anchors.leftMargin = globalDrawer.modal ? handleWidth + leftPillBox.y : leftPillBox.y;
        }
    }

    ModeRocker {
        id: inputMode

324
        visible: gamepad && gamepad.connected && !kirogiSettings.alwaysShowDPads
Eike Hein's avatar
Eike Hein committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

        anchors.verticalCenter: shotButton.verticalCenter
        anchors.left: flightMode.right
        anchors.leftMargin: leftPillBox.y

        firstLabelText: i18n("SCREEN")
        firstIconSource: Kirigami.Settings.isMobile ? "phone-symbolic" : "computer-symbolic"
        firstToolTipText: i18n("Use Virtual D-Pads")

        secondLabelText: i18n("CONTROLLER")
        secondIconSource: "folder-games-symbolic"
        secondToolTipText: i18n("Use Gamepad Controller")

        showLabels: false
        showIcons: true

        selectedMode: kirogiSettings.lastInputMode

        onModeTapped: {
            selectedMode = mode;
            kirogiSettings.lastInputMode = selectedMode;
            kirogiSettings.save();
        }

    }

    ModeRocker {
        id: shotMode

        enabled: kirogi.ready

        anchors.right: shotButton.right
        anchors.rightMargin: shotButton.width / 2
        anchors.verticalCenter: shotButton.verticalCenter

        width: (implicitWidth + shotButton.width / 2) - Kirigami.Units.largeSpacing

        property int requestedMode: 0

        background: cameraStream

        firstModeEnabled: enabled && kirogi.currentVehicle.isActionSupported(Kirogi.AbstractVehicle.RecordVideo)
        secondModeEnabled: enabled && kirogi.currentVehicle.isActionSupported(Kirogi.AbstractVehicle.TakePicture)

        firstLabelText: i18n("VIDEO")
        firstIconSource: "emblem-videos-symbolic"
        firstToolTipText: i18n("Record Videos")

        secondLabelText: i18n("PHOTO")
        secondIconSource: "emblem-photos-symbolic"
        secondToolTipText: i18n("Take Photos")

        showLabels: false
        showIcons: true

        selectedMode: kirogi.ready ? requestedMode : -1

        onModeTapped: requestedMode = mode
    }

    TouchButton {
        id: shotButton

        enabled: {
            if (!kirogi.ready) {
                return false;
            }

            if ((shotMode.selectedMode == 0 && !kirogi.currentVehicle.isActionSupported(Kirogi.AbstractVehicle.RecordVideo))
                || (shotMode.selectedMode == 1 && (!kirogi.currentVehicle.isActionSupported(Kirogi.AbstractVehicle.TakePicture)
                || !kirogi.currentVehicle.canTakePicture))) {
                return false;
            }

            return true;
        }

        anchors.right: parent.right
        anchors.rightMargin: flightMode.anchors.leftMargin
        anchors.bottom: parent.bottom
        anchors.bottomMargin: launchButton.anchors.topMargin

        background: cameraStream

        icon: "media-record-symbolic"
        iconColor: shotMode.selectedMode == 0 && (kirogi.currentVehicle && kirogi.currentVehicle.isRecordingVideo) ? "red" : "white"
        toolTipText: {
            if (shotMode.selectedMode) {
                return i18n("Take Photo");
            } else if (kirogi.currentVehicle && kirogi.currentVehicle.isRecordingVideo) {
                return i18n("Stop Recording Video");
            }

            return i18n("Record Video");
        }

        onTapped: {
            if (!kirogi.ready) {
                return;
            }

            if (shotMode.selectedMode == 0) {
                kirogi.currentVehicle.requestAction(Kirogi.AbstractVehicle.RecordVideo);
            } else if (shotMode.selectedMode == 1) {
                kirogi.currentVehicle.requestAction(Kirogi.AbstractVehicle.TakePicture);
            }
        }
    }

    TouchDPad {
        id: leftDPad

437
        visible: inputMode.selectedMode == 0 || kirogiSettings.alwaysShowDPads || (gamepad && !gamepad.connected)
Eike Hein's avatar
Eike Hein committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944

        anchors.left: parent.left
        anchors.leftMargin: yardstick * 0.18
        anchors.bottom: parent.bottom
        anchors.bottomMargin: yardstick * 0.20

        width: Math.min(yardstick * 0.45, parent.width / 4)
        height: width

        background: cameraStream
        leftIcon: "edit-undo"
        leftToolTipText: i18n("Turn Left")
        rightIcon: "edit-redo"
        rightToolTipText: i18n("Turn Right")
        topIcon: "arrow-up"
        topToolTipText: i18n("Move Up")
        bottomIcon: "arrow-down"
        bottomToolTipText: i18n("Move Down")

        onXChanged: moved = aboutToMove

        onAxisXChanged: {
            if (kirogi.flying) {
                kirogi.currentVehicle.pilot(rightDPad.axisX, rightDPad.axisY, leftDPad.axisX, leftDPad.axisY);
            }
        }

        onAxisYChanged: {
            if (kirogi.flying) {
                kirogi.currentVehicle.pilot(rightDPad.axisX, rightDPad.axisY, leftDPad.axisX, leftDPad.axisY);
            }
        }

        touchPos: {
            if (moved && leftTouchPoint) {
                var xDifference = 0;

                if (leftTouchPoint.point.scenePosition.x > leftTouchPoint.point.scenePressPosition.x) {
                    xDifference = xDifference + Math.abs(leftTouchPoint.point.scenePressPosition.x - leftTouchPoint.point.scenePosition.x);
                } else {
                    xDifference = xDifference - Math.abs(leftTouchPoint.point.scenePressPosition.x - leftTouchPoint.point.scenePosition.x)
                }

                var x = leftDPad.x + leftDPad.width / 2 + xDifference;

                var yDifference = 0;

                if (leftTouchPoint.point.scenePosition.y > leftTouchPoint.point.scenePressPosition.y) {
                    yDifference = yDifference + Math.abs(leftTouchPoint.point.scenePressPosition.y - leftTouchPoint.point.scenePosition.y);
                } else {
                    yDifference = yDifference - Math.abs(leftTouchPoint.point.scenePressPosition.y - leftTouchPoint.point.scenePosition.y)
                }

                var y = leftDPad.y + leftDPad.height / 2 + yDifference;

                return parent.mapToItem(leftDPad, x, y);
            }

            return null;
        }

        states: [
            State {
                name: "inactive"

                AnchorChanges {
                    target: leftDPad

                    anchors.left: parent.left
                    anchors.bottom: parent.bottom
                }

                PropertyChanges {
                    target: leftDPad

                    aboutToMove: false
                    moved: false
                }
            },
            State {
                name: "active"

                when: leftTouchPoint.active

                AnchorChanges {
                    target: leftDPad

                    anchors.left: undefined
                    anchors.bottom: undefined
                }

                PropertyChanges {
                    target: leftDPad

                    aboutToMove: true
                    x: Math.min((parent.width / 2) - width, Math.max(0, leftTouchPoint.point.scenePressPosition.x - width / 2))
                    y: Math.min(parent.height - height, Math.max(0, leftTouchPoint.point.scenePressPosition.y - height / 2))
                }
            }
        ]
    }

    TouchDPad {
        id: rightDPad

        visible: leftDPad.visible

        width: leftDPad.height
        height: width

        anchors.right: parent.right
        anchors.rightMargin: leftDPad.anchors.leftMargin
        anchors.bottom: parent.bottom
        anchors.bottomMargin: leftDPad.anchors.bottomMargin

        background: cameraStream
        leftIcon: "go-previous"
        leftToolTipText: i18n("Move Left")
        rightIcon: "go-next"
        rightToolTipText: i18n("Move Right")
        topIcon: "go-up"
        topToolTipText: i18n("Move Forward")
        bottomIcon: "go-down"
        bottomToolTipText: i18n("Move Backward")

        onXChanged: moved = aboutToMove

        onAxisXChanged: {
            if (kirogi.flying) {
                kirogi.currentVehicle.pilot(rightDPad.axisX, rightDPad.axisY, leftDPad.axisX, leftDPad.axisY);
            }
        }

        onAxisYChanged: {
            if (kirogi.flying) {
                kirogi.currentVehicle.pilot(rightDPad.axisX, rightDPad.axisY, leftDPad.axisX, leftDPad.axisY);
            }
        }

        touchPos: {
            if (moved && rightTouchPoint.active) {
                var xDifference = 0;

                if (rightTouchPoint.point.scenePosition.x > rightTouchPoint.point.scenePressPosition.x) {
                    xDifference = xDifference + Math.abs(rightTouchPoint.point.scenePressPosition.x - rightTouchPoint.point.scenePosition.x);
                } else {
                    xDifference = xDifference - Math.abs(rightTouchPoint.point.scenePressPosition.x - rightTouchPoint.point.scenePosition.x)
                }

                var x = rightDPad.x + rightDPad.width / 2 + xDifference;

                var yDifference = 0;

                if (rightTouchPoint.point.scenePosition.y > rightTouchPoint.point.scenePressPosition.y) {
                    yDifference = yDifference + Math.abs(rightTouchPoint.point.scenePressPosition.y - rightTouchPoint.point.scenePosition.y);
                } else {
                    yDifference = yDifference - Math.abs(rightTouchPoint.point.scenePressPosition.y - rightTouchPoint.point.scenePosition.y)
                }

                var y = rightDPad.y + rightDPad.height / 2 + yDifference;

                return parent.mapToItem(rightDPad, x, y);
            }

            return null;
        }

        states: [
            State {
                name: "inactive"

                AnchorChanges {
                    target: rightDPad

                    anchors.left: parent.right
                    anchors.bottom: parent.bottom
                }

                PropertyChanges {
                    target: rightDPad

                    aboutToMove: false
                    moved: false
                }
            },
            State {
                name: "active"

                when: rightTouchPoint.active
                AnchorChanges {
                    target: rightDPad

                    anchors.right: undefined
                    anchors.bottom: undefined
                }

                PropertyChanges {
                    target: rightDPad

                    aboutToMove: true
                    x: Math.max(parent.width / 2, Math.min(parent.width - width, rightTouchPoint.point.scenePressPosition.x - width / 2))
                    y: Math.min(parent.height - height, Math.max(0, rightTouchPoint.point.scenePressPosition.y - height / 2))
                }
            }
        ]
    }

    PillBox {
        id: leftPillBox

        anchors.verticalCenter: launchButton.verticalCenter
        anchors.left: parent.left
        anchors.leftMargin: y

        width: leftPillBoxContents.implicitWidth + Kirigami.Units.largeSpacing * 4
        height: 2 * Math.round((Math.max(Kirigami.Units.iconSizes.small, fontMetrics.height) + Kirigami.Units.smallSpacing * 3) / 2);

        background: cameraStream

        Row {
            id: leftPillBoxContents

            anchors.horizontalCenter: parent.horizontalCenter

            height: parent.height

            spacing: Kirigami.Units.largeSpacing

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: true

                source: "speedometer"
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1 m/s", "0.0")).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: {
                    if (kirogi.ready) {
                        return i18n("%1 m/s", kirogi.flying ? kirogi.currentVehicle.speed : "0");
                    }

                    return i18n("– m/s");
                }
            }

            PillBoxSeparator {}

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: true

                source: "kruler-west"
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1 m", "0.0")).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: {
                    if (kirogi.ready) {
                        return i18n("%1 m", kirogi.flying ? kirogi.currentVehicle.altitude.toFixed(2) : "0");
                    }

                    return i18n("– m");
                }
            }

            PillBoxSeparator {}

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: true

                source: "kruler-south"
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1 m", "0.0")).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: {
                    if (kirogi.currentVehicle && kirogi.currentVehicle.distance >= 0
                        && kirogi.ready) {
                        return i18n("%1 m", kirogi.currentVehicle.distance.toFixed(1));
                    }

                    if (gpsPosition.distance !== 0) {
                        return i18n("%1 m", gpsPosition.distance.toFixed(1));
                    }

                    return i18n("– m");
                }
            }
        }
    }

    PillBox {
        id: rightPillBox

        anchors.verticalCenter: launchButton.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: leftPillBox.anchors.leftMargin

        width: rightPillBoxContents.implicitWidth + Kirigami.Units.largeSpacing * 4
        height: leftPillBox.height

        background: cameraStream

       Row {
           id: rightPillBoxContents

            x: Kirigami.Units.largeSpacing

            anchors.horizontalCenter: parent.horizontalCenter

            height: parent.height

            spacing: Kirigami.Units.largeSpacing

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: true

                source: "clock"
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1 m", "0:00")).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: {
                    if (kirogi.ready) {
                        var time = kirogi.flying ? kirogi.currentVehicle.flightTime : 0;
                        return i18n("%1 min", (time - (time %= 60)) / 60 + (9 < time ?':':':0') + time);
                    }

                    return i18n("– min");
                }
            }

            PillBoxSeparator {}

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: kirogi.ready

                source: {
                    if (kirogi.ready) {
                        if (kirogi.currentVehicle.signalStrength === 0) {
                            return "network-wireless-connected-00";
                        } else if (kirogi.currentVehicle.signalStrength < 25) {
                            return "network-wireless-connected-25";
                        } else if (kirogi.currentVehicle.signalStrength < 50) {
                            return "network-wireless-connected-50";
                        } else if (kirogi.currentVehicle.signalStrength < 75) {
                            return "network-wireless-connected-75";
                        } else if (kirogi.currentVehicle.signalStrength <= 100) {
                            return "network-wireless-connected-100";
                        }
                    }

                    if (kirogi.connected) {
                        return "network-wireless-acquiring";
                    }

                    return "network-wireless-disconnected";
                }
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1%", 00)).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: kirogi.ready ? i18n("%1%", kirogi.currentVehicle.signalStrength) : i18n("N/A")
            }

            PillBoxSeparator {}

            Kirigami.Icon {
                anchors.verticalCenter: parent.verticalCenter

                width: Kirigami.Units.iconSizes.small
                height: width

                color: "white"
                smooth: true
                isMask: kirogi.ready

                source: {
                    if (kirogi.ready) {
                        var roundedBatteryLevel = Math.round(kirogi.currentVehicle.batteryLevel / 10);
                        return "battery-" + roundedBatteryLevel.toString().padStart(2, "0") + "0";
                    }

                    return "battery-missing";
                }
            }

            QQC2.Label {
                anchors.verticalCenter: parent.verticalCenter

                width: kirogi.ready ? Math.round(Math.max(implicitWidth, fontMetrics.tightBoundingRect(i18n("%1%", 00)).width))
                    : Math.round(implicitWidth)

                color: "white"

                horizontalAlignment: Text.AlignRight

                text: kirogi.ready ?  i18n("%1%", kirogi.currentVehicle.batteryLevel) : i18n("N/A")
            }
        }
    }

    PitchBar {
        id: pitchBar

        anchors.centerIn: parent

        width: yardstick * 0.04
        height: parent.height * 0.6

        pitch: kirogi.ready ? (Math.min(Math.max(kirogi.currentVehicle.pitch * (180/Math.PI), -90), 90) + 90) : 0.0
    }

    VirtualHorizon {
        id: virtualHorizon

        anchors.centerIn: pitchBar

        width: yardstick * 0.2

        roll: kirogi.ready ? kirogi.currentVehicle.roll * (180/Math.PI) : 0
    }

    VehicleActionsDrawer {
        enabled: kirogi.currentPage == page // FIXME TODO: Why doesn't come down from page.enabled?

        width: Kirigami.Units.gridUnit * 19

        edge: kirogi.LayoutMirroring.enabled ? Qt.LeftEdge : Qt.RightEdge

        handleClosedIcon.source: "configure"
    }

945 946
    Loader {
        id: gamepadLoader
Eike Hein's avatar
Eike Hein committed
947

948 949
        source: "Gamepad.qml"
        asynchronous: true
Eike Hein's avatar
Eike Hein committed
950

951 952 953
        // FIXME TODO: QtGamepad currently causes performance problems on
        // Android (blocking multi-tasking) that need to be investigated.
        active: !Kirigami.Settings.isMobile
Eike Hein's avatar
Eike Hein committed
954
    }
Eike Hein's avatar
Eike Hein committed
955 956 957

    Component.onCompleted: videoPlayer.playing = kirogiSettings.flying
}