QGCView.qml 3.99 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 62 63 64 65 66 67 68 69 70
        var dialogWidth = charWidth == showDialogFullWidth ? parent.width : ScreenTools.defaultFontPixelWidth * charWidth
        var dialog = dialogComponent.createObject(_rootItem,
                                                  {
                                                      "anchors.fill":       _rootItem,
                                                      "dialogWidth":        dialogWidth,
                                                      "dialogTitle":        title,
                                                      "dialogComponent":    component,
                                                      "viewPanel":          viewPanel
                                                  })
        dialog.setupDialogButtons(buttons)
71
        viewPanel.enabled = false
Don Gagne's avatar
Don Gagne committed
72 73
    }

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

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

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

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

86
    function _signalCompleted() {
Don Gagne's avatar
Don Gagne committed
87 88 89
        // 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.
90 91
        if (!completedSignalled && width != 0 && height != 0) {
            completedSignalled = true
Don Gagne's avatar
Don Gagne committed
92 93 94 95
            completed()
        }
    }

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

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

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