QGCPopupDialogContainer.qml 7.81 KB
Newer Older
DoinLakeFlyer's avatar
DoinLakeFlyer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick                      2.12
import QtQuick.Controls             2.4
import QtQuick.Layouts              1.12
import QtQuick.Dialogs              1.3

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

Popup {
21 22 23
    property var    dialogComponent
    property string dialogSource
    property var    dialogProperties
24

25
    id:                 _root
DoinLakeFlyer's avatar
DoinLakeFlyer committed
26
    anchors.centerIn:   parent
27 28
    width:              mainColumnLayout.width + (padding * 2)
    height:             mainColumnLayout.y + mainColumnLayout.height + padding
DonLakeFlyer's avatar
DonLakeFlyer committed
29
    padding:            2
DoinLakeFlyer's avatar
DoinLakeFlyer committed
30 31 32
    modal:              true
    focus:              true

33 34
    property var    _pal:               QGroundControl.globalPalette
    property real   _frameSize:         ScreenTools.defaultFontPixelWidth
35
    property string _dialogTitle
36 37 38 39
    property real   _contentMargin:     ScreenTools.defaultFontPixelHeight / 2
    property real   _popupDoubleInset:  ScreenTools.defaultFontPixelHeight * 2
    property real   _maxContentWidth:   parent.width - _popupDoubleInset
    property real   _maxContentHeight:  parent.height - titleRowLayout.height - _popupDoubleInset
DonLakeFlyer's avatar
DonLakeFlyer committed
40 41 42 43 44

    background: Item {
        Rectangle {
            anchors.left:   parent.left
            anchors.top:    parent.top
45 46 47
            width:          _frameSize
            height:         _frameSize
            color:          _pal.text
DonLakeFlyer's avatar
DonLakeFlyer committed
48 49 50 51 52 53
            visible:        enabled
        }

        Rectangle {
            anchors.right:  parent.right
            anchors.top:    parent.top
54 55 56
            width:          _frameSize
            height:         _frameSize
            color:          _pal.text
DonLakeFlyer's avatar
DonLakeFlyer committed
57 58 59 60 61 62
            visible:        enabled
        }

        Rectangle {
            anchors.left:   parent.left
            anchors.bottom: parent.bottom
63 64 65
            width:          _frameSize
            height:         _frameSize
            color:          _pal.text
DonLakeFlyer's avatar
DonLakeFlyer committed
66 67 68 69 70 71
            visible:        enabled
        }

        Rectangle {
            anchors.right:  parent.right
            anchors.bottom: parent.bottom
72 73 74
            width:          _frameSize
            height:         _frameSize
            color:          _pal.text
DonLakeFlyer's avatar
DonLakeFlyer committed
75 76 77 78
            visible:        enabled
        }

        Rectangle {
79
            anchors.margins:    _root.padding
DonLakeFlyer's avatar
DonLakeFlyer committed
80
            anchors.fill:       parent
81
            color:              _pal.window
DonLakeFlyer's avatar
DonLakeFlyer committed
82
        }
DoinLakeFlyer's avatar
DoinLakeFlyer committed
83 84
    }

85 86 87 88
    Component.onCompleted: {
        _dialogTitle = dialogComponentLoader.item.title
        setupDialogButtons(dialogComponentLoader.item.buttons)
    }
DoinLakeFlyer's avatar
DoinLakeFlyer committed
89 90 91

    QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled }

92
    function setupDialogButtons(buttons) {
DoinLakeFlyer's avatar
DoinLakeFlyer committed
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
        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
        }

        if (rejectButton.visible) {
            closePolicy = Popup.NoAutoClose | Popup.CloseOnEscape
        } else {
            closePolicy = Popup.NoAutoClose
        }
    }

    Connections {
        target:         dialogComponentLoader.item
        onHideDialog:   close()
    }

164 165 166 167 168
    Rectangle {
        width:  titleRowLayout.width
        height: titleRowLayout.height
        color:  qgcPal.windowShade
    }
DoinLakeFlyer's avatar
DoinLakeFlyer committed
169

170 171 172
    ColumnLayout {
        id:         mainColumnLayout
        spacing:    _contentMargin
DoinLakeFlyer's avatar
DoinLakeFlyer committed
173

174 175 176
        RowLayout {
            id:                 titleRowLayout
            Layout.fillWidth:   true
DoinLakeFlyer's avatar
DoinLakeFlyer committed
177

178 179
            QGCLabel {
                Layout.leftMargin:  ScreenTools.defaultFontPixelWidth
DoinLakeFlyer's avatar
DoinLakeFlyer committed
180
                Layout.fillWidth:   true
181 182 183 184
                text:               _dialogTitle
                height:             parent.height
                verticalAlignment:	Text.AlignVCenter
            }
DoinLakeFlyer's avatar
DoinLakeFlyer committed
185

186 187 188 189
            QGCButton {
                id:         rejectButton
                onClicked:  dialogComponentLoader.item.reject()
            }
DoinLakeFlyer's avatar
DoinLakeFlyer committed
190

191 192 193 194
            QGCButton {
                id:         acceptButton
                primary:    true
                onClicked:  dialogComponentLoader.item.accept()
DoinLakeFlyer's avatar
DoinLakeFlyer committed
195
            }
196 197 198 199 200 201 202 203
        }

        QGCFlickable {
            id:                     mainFlickable
            Layout.preferredWidth:  Math.min(marginItem.width, _maxContentWidth)
            Layout.preferredHeight: Math.min(marginItem.height, _maxContentHeight)
            contentWidth:           marginItem.width
            contentHeight:          marginItem.height
DoinLakeFlyer's avatar
DoinLakeFlyer committed
204 205

            Item {
206 207 208
                id:     marginItem
                width:  dialogComponentLoader.width + (_contentMargin * 2)
                height: dialogComponentLoader.height + _contentMargin
DoinLakeFlyer's avatar
DoinLakeFlyer committed
209 210 211 212

                Loader {
                    id:                 dialogComponentLoader
                    x:                  _contentMargin
213
                    source:             dialogSource
DoinLakeFlyer's avatar
DoinLakeFlyer committed
214 215
                    sourceComponent:    dialogComponent
                    focus:              true
216

217
                    property var dialogProperties:  _root.dialogProperties
218 219
                    property bool acceptAllowed:    acceptButton.visible
                    property bool rejectAllowed:    rejectButton.visible
DoinLakeFlyer's avatar
DoinLakeFlyer committed
220 221 222 223 224
                }
            }
        }
    }
}