QGCViewDialogContainer.qml 6.11 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

Gus Grubba's avatar
Gus Grubba committed
10
import QtQuick                      2.11
11 12
import QtQuick.Controls             2.4
import QtQuick.Dialogs              1.3
13 14 15 16 17

import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0

18 19 20 21 22 23 24
Drawer {
    edge:           Qt.RightEdge
    interactive:    false

    property var    dialogComponent
    property string dialogTitle
    property var    dialogButtons:        StandardButton.NoButton
25

26 27
    property real   _defaultTextHeight: _textMeasure.contentHeight
    property real   _defaultTextWidth:  _textMeasure.contentWidth
28

29
    function setupDialogButtons(buttons) {
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
        _acceptButton.visible = false
        _rejectButton.visible = false
        // Accept role buttons
        if (buttons & StandardButton.Ok) {
            _acceptButton.text = qsTr("Ok")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Open) {
            _acceptButton.text = qsTr("Open")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Save) {
            _acceptButton.text = qsTr("Save")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Apply) {
            _acceptButton.text = qsTr("Apply")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Open) {
            _acceptButton.text = qsTr("Open")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.SaveAll) {
            _acceptButton.text = qsTr("Save All")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Yes) {
            _acceptButton.text = qsTr("Yes")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.YesToAll) {
            _acceptButton.text = qsTr("Yes to All")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Retry) {
            _acceptButton.text = qsTr("Retry")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Reset) {
            _acceptButton.text = qsTr("Reset")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.RestoreToDefaults) {
            _acceptButton.text = qsTr("Restore to Defaults")
            _acceptButton.visible = true
        } else if (buttons & StandardButton.Ignore) {
            _acceptButton.text = qsTr("Ignore")
            _acceptButton.visible = true
        }

        // Reject role buttons
        if (buttons & StandardButton.Cancel) {
            _rejectButton.text = qsTr("Cancel")
            _rejectButton.visible = true
        } else if (buttons & StandardButton.Close) {
            _rejectButton.text = qsTr("Close")
            _rejectButton.visible = true
        } else if (buttons & StandardButton.No) {
            _rejectButton.text = qsTr("No")
            _rejectButton.visible = true
        } else if (buttons & StandardButton.NoToAll) {
            _rejectButton.text = qsTr("No to All")
            _rejectButton.visible = true
        } else if (buttons & StandardButton.Abort) {
            _rejectButton.text = qsTr("Abort")
            _rejectButton.visible = true
        }
88 89 90 91 92 93 94 95

        if (buttons & StandardButton.Cancel || buttons & StandardButton.Close || buttons & StandardButton.Discard || buttons & StandardButton.Abort || buttons & StandardButton.Ignore) {
            closePolicy = Popup.NoAutoClose;
            interactive = false;
        } else {
            closePolicy = Popup.CloseOnEscape | Popup.CloseOnPressOutside;
            interactive = true;
        }
96 97 98 99 100
    }

    Connections {
        target: _dialogComponentLoader.item
        onHideDialog: {
101
            Qt.inputMethod.hide()
102
            close()
103 104 105
        }
    }

106 107
    Component.onCompleted: setupDialogButtons(dialogButtons)

108 109
    QGCLabel { id: _textMeasure; text: "X"; visible: false }

110 111 112 113 114

    background: Rectangle {
        color:  qgcPal.windowShadeDark
    }

115 116
    // This is the main dialog panel
    Item {
117
        id:                 _dialogPanel
118
        anchors.fill:       parent
119
        Rectangle {
120 121 122 123
            id:             _header
            width:          parent.width
            height:         _acceptButton.visible ? _acceptButton.height : _rejectButton.height
            color:          qgcPal.windowShade
124 125
            QGCLabel {
                x:                  _defaultTextWidth
126
                text:               dialogTitle
127 128 129 130
                height:             parent.height
                verticalAlignment:	Text.AlignVCenter
            }
            QGCButton {
131 132 133
                id:                 _rejectButton
                anchors.right:      _acceptButton.visible ?  _acceptButton.left : parent.right
                anchors.bottom:     parent.bottom
134
                onClicked:          _dialogComponentLoader.item.reject()
135 136
            }
            QGCButton {
137 138 139 140
                id:                 _acceptButton
                anchors.right:      parent.right
                anchors.bottom:     parent.bottom
                primary:            true
141
                onClicked:          _dialogComponentLoader.item.accept()
142 143 144
            }
        }
        Item {
145 146 147 148
            id:                     _spacer
            width:                  10
            height:                 10
            anchors.top:            _header.bottom
149 150 151 152 153 154 155 156
        }
        Loader {
            id:                 _dialogComponentLoader
            anchors.margins:    5
            anchors.left:       parent.left
            anchors.right:      parent.right
            anchors.top:        _spacer.bottom
            anchors.bottom:     parent.bottom
157
            sourceComponent:    dialogComponent
158
            focus:              true
159 160 161
            property bool acceptAllowed: _acceptButton.visible
            property bool rejectAllowed: _rejectButton.visible
        }
162
    }
163
}