Skip to content
QGCView.qml 4.02 KiB
Newer Older
/****************************************************************************
 *
 *   (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


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

import QtQuick 2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
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
FactPanel {
    id: _rootItem
    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
    /// 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.
    function _checkForEarlyDialog(title) {
        if (!completedSignalled) {
            console.warn(qsTr("showDialog called before QGCView.completed signalled"), title)
    /// Shows a QGCViewDialog component
    ///     @param compoent QGCViewDialog component
    ///     @param title Title for dialog
    ///     @param charWidth Width of dialog in characters
    ///     @param buttons Buttons to show in dialog using StandardButton enum

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

    function showDialog(component, title, charWidth, buttons) {
        if (_checkForEarlyDialog(title)) {
        var dialogComponent = Qt.createComponent("QGCViewDialogContainer.qml")
        if (dialogComponent.status === Component.Error) {
            console.log("Error loading QGCViewDialogContainer.qml: ", dialogComponent.errorString())
        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)
        dialog.focus = true
        viewPanel.enabled = false
Don Gagne's avatar
Don Gagne committed
    }

    function showMessage(title, message, buttons) {
        _messageDialogText = message
        showDialog(_messageDialog, title, showDialogDefaultWidth, buttons)
    QGCPalette { id: _qgcPal; colorGroupEnabled: true }
    property real defaultTextWidth:     ScreenTools.defaultFontPixelWidth
    property real defaultTextHeight:    ScreenTools.defaultFontPixelHeight
    property string _messageDialogText
Don Gagne's avatar
Don Gagne committed

    function _signalCompleted() {
Don Gagne's avatar
Don Gagne committed
        // 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.
        if (!completedSignalled && width != 0 && height != 0) {
            completedSignalled = true
Don Gagne's avatar
Don Gagne committed
            completed()
        }
    }

    Component.onCompleted:  _signalCompleted()
    onWidthChanged:         _signalCompleted()
    onHeightChanged:        _signalCompleted()
Don Gagne's avatar
Don Gagne committed
    Component {
        id: _messageDialog
Don Gagne's avatar
Don Gagne committed

        QGCViewMessage {
            message: _messageDialogText
Don Gagne's avatar
Don Gagne committed
        }
    }