QGCView.qml 4.02 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 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.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9 10 11 12 13


/// @file
///     @author Don Gagne <don@thegagnes.com>

14 15
import QtQuick 2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
16 17 18 19 20 21 22 23
import QtQuick.Dialogs 1.2

import QGroundControl.Controls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0

Don Gagne's avatar
Don Gagne committed
24
FactPanel {
25
    id: _rootItem
Don Gagne's avatar
Don Gagne committed
26

27 28 29
    property var    qgcView:               _rootItem  ///< Used by Fact controls for validation dialogs
    property bool   completedSignalled:   false
    property var    viewPanel
Don Gagne's avatar
Don Gagne committed
30

Don Gagne's avatar
Don Gagne committed
31 32 33
    /// This is signalled when the top level Item reaches Component.onCompleted. This allows
    /// the view subcomponent to connect to this signal and do work once the full ui is ready
    /// to go.
34
    signal completed
35

36
    function _checkForEarlyDialog(title) {
37
        if (!completedSignalled) {
38
            console.warn(qsTr("showDialog called before QGCView.completed signalled"), title)
39 40 41
        }
    }

42 43 44
    /// Shows a QGCViewDialog component
    ///     @param compoent QGCViewDialog component
    ///     @param title Title for dialog
45
    ///     @param charWidth Width of dialog in characters
46
    ///     @param buttons Buttons to show in dialog using StandardButton enum
47 48 49 50

    readonly property int showDialogFullWidth:      -1  ///< Use for full width dialog
    readonly property int showDialogDefaultWidth:   40  ///< Use for default dialog width

51
    function showDialog(component, title, charWidth, buttons) {
52
        if (_checkForEarlyDialog(title)) {
53 54 55
            return
        }

56 57 58
        var dialogComponent = Qt.createComponent("QGCViewDialogContainer.qml")
        if (dialogComponent.status === Component.Error) {
            console.log("Error loading QGCViewDialogContainer.qml: ", dialogComponent.errorString())
59 60
            return
        }
61
        var dialogWidth = charWidth === showDialogFullWidth ? parent.width : ScreenTools.defaultFontPixelWidth * charWidth
62 63 64 65 66 67 68 69 70
        var dialog = dialogComponent.createObject(_rootItem,
                                                  {
                                                      "anchors.fill":       _rootItem,
                                                      "dialogWidth":        dialogWidth,
                                                      "dialogTitle":        title,
                                                      "dialogComponent":    component,
                                                      "viewPanel":          viewPanel
                                                  })
        dialog.setupDialogButtons(buttons)
71
        dialog.focus = true
72
        viewPanel.enabled = false
Don Gagne's avatar
Don Gagne committed
73 74
    }

75 76 77
    function showMessage(title, message, buttons) {
        _messageDialogText = message
        showDialog(_messageDialog, title, showDialogDefaultWidth, buttons)
Don Gagne's avatar
Don Gagne committed
78 79
    }

80
    QGCPalette { id: _qgcPal; colorGroupEnabled: true }
Don Gagne's avatar
Don Gagne committed
81

82 83
    property real defaultTextWidth:     ScreenTools.defaultFontPixelWidth
    property real defaultTextHeight:    ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
84

85
    property string _messageDialogText
Don Gagne's avatar
Don Gagne committed
86

87
    function _signalCompleted() {
Don Gagne's avatar
Don Gagne committed
88 89 90
        // When we use this control inside a QGCQmlWidgetHolder Component.onCompleted is signalled
        // before the width and height are adjusted. So we need to wait for width and heigth to be
        // set before we signal our own completed signal.
91 92
        if (!completedSignalled && width != 0 && height != 0) {
            completedSignalled = true
Don Gagne's avatar
Don Gagne committed
93 94 95 96
            completed()
        }
    }

97 98 99
    Component.onCompleted:  _signalCompleted()
    onWidthChanged:         _signalCompleted()
    onHeightChanged:        _signalCompleted()
Don Gagne's avatar
Don Gagne committed
100

Don Gagne's avatar
Don Gagne committed
101
    Component {
102
        id: _messageDialog
Don Gagne's avatar
Don Gagne committed
103 104

        QGCViewMessage {
105
            message: _messageDialogText
Don Gagne's avatar
Don Gagne committed
106 107
        }
    }
108
}