Skip to content
MainWindow.cc 64.3 KiB
Newer Older
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009 - 2013 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Implementation of class MainWindow
 *   @author Lorenz Meier <mail@qgroundcontrol.org>
 */

#include <QSettings>
#include <QDockWidget>
#include <QNetworkInterface>
#include <QDebug>
#include <QTimer>
#include <QHostInfo>
#include <QSplashScreen>
#include <QGCHilLink.h>
#include <QGCHilConfiguration.h>
#include <QGCHilFlightGearConfiguration.h>
#include <QQuickView>
#include <QDesktopWidget>

#include "QGC.h"
#include "MAVLinkSimulationLink.h"
#include "SerialLink.h"
#include "UDPLink.h"
#include "MAVLinkProtocol.h"
#include "CommConfigurationWindow.h"
#include "QGCWaypointListMulti.h"
#include "MainWindow.h"
#include "JoystickWidget.h"
#include "GAudioOutput.h"
#include "QGCToolWidget.h"
#include "QGCMAVLinkLogPlayer.h"
Don Gagne's avatar
Don Gagne committed
#include "SettingsDialog.h"
#include "QGCMapTool.h"
#include "MAVLinkDecoder.h"
#include "QGCMAVLinkMessageSender.h"
#include "QGCRGBDView.h"
#include "QGCStatusBar.h"
#include "QGCDataPlot2D.h"
#include "Linecharts.h"
#include "QGCTabbedInfoView.h"
#include "UASRawStatusView.h"
#include "SetupView.h"
#include "SerialSettingsDialog.h"
#include "terminalconsole.h"
#include "QGCUASFileViewMulti.h"
Don Gagne's avatar
Don Gagne committed
#include "QGCApplication.h"
#include "QGCFileDialog.h"
Don Gagne's avatar
Don Gagne committed
#include "QGCMessageBox.h"

#ifdef QGC_OSG_ENABLED
#include "Q3DWidgetFactory.h"
#endif

#include "LogCompressor.h"

Don Gagne's avatar
Don Gagne committed
static MainWindow* _instance = NULL;   ///< @brief MainWindow singleton

// Set up some constants
const QString MainWindow::defaultDarkStyle = ":files/styles/style-dark.css";
const QString MainWindow::defaultLightStyle = ":files/styles/style-light.css";

Don Gagne's avatar
Don Gagne committed
MainWindow* MainWindow::_create(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode)
Don Gagne's avatar
Don Gagne committed
    Q_ASSERT(_instance == NULL);
    
    new MainWindow(splashScreen, mode);
    
    // _instance is set in constructor
    Q_ASSERT(_instance);

Don Gagne's avatar
Don Gagne committed
MainWindow* MainWindow::instance(void)
Don Gagne's avatar
Don Gagne committed
    return _instance;
void MainWindow::deleteInstance(void)
{
Don Gagne's avatar
Don Gagne committed
    delete this;
Don Gagne's avatar
Don Gagne committed
/// @brief Private constructor for MainWindow. MainWindow singleton is only ever created
///         by MainWindow::_create method. Hence no other code should have access to
///         constructor.
MainWindow::MainWindow(QSplashScreen* splashScreen, enum MainWindow::CUSTOM_MODE mode) :
    currentView(VIEW_FLIGHT),
    currentStyle(QGC_MAINWINDOW_STYLE_DARK),
Don Gagne's avatar
Don Gagne committed
    mavlink(new MAVLinkProtocol()),
    centerStackActionGroup(new QActionGroup(this)),
    autoReconnect(false),
    simulationLink(NULL),
Don Gagne's avatar
Don Gagne committed
    customMode(mode),
    menuActionHelper(new MenuActionHelper()),
    _splashScreen(splashScreen)
Don Gagne's avatar
Don Gagne committed
    Q_ASSERT(_instance == NULL);
    _instance = this;
    
    if (splashScreen) {
        connect(this, &MainWindow::initStatusChanged, splashScreen, &QSplashScreen::showMessage);
    }
    this->setAttribute(Qt::WA_DeleteOnClose);
    connect(menuActionHelper, SIGNAL(needToShowDockWidget(QString,bool)),SLOT(showDockWidget(QString,bool)));
Don Gagne's avatar
Don Gagne committed
    connect(mavlink, SIGNAL(protocolStatusMessage(const QString&, const QString&)), this, SLOT(showCriticalMessage(const QString&, const QString&)));
    connect(mavlink, SIGNAL(saveTempFlightDataLog(QString)), this, SLOT(_saveTempFlightDataLog(QString)));
    emit initStatusChanged(tr("Loading style"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));
    loadStyle(currentStyle);
        menuActionHelper->setAdvancedMode(settings.value("ADVANCED_MODE").toBool());
    // Select the proper view. Default to the flight view or load the last one used if it's supported.
    if (!settings.contains("CURRENT_VIEW"))
    {
        settings.setValue("CURRENT_VIEW", currentView);
    }
    else
    {
        VIEW_SECTIONS currentViewCandidate = (VIEW_SECTIONS) settings.value("CURRENT_VIEW", currentView).toInt();
        switch (currentViewCandidate) {
            case VIEW_ENGINEER:
            case VIEW_MISSION:
            case VIEW_FLIGHT:
            case VIEW_SIMULATION:
            case VIEW_SETUP:
            case VIEW_SOFTWARE_CONFIG:
            case VIEW_TERMINAL:

// And only re-load views if they're supported with the current QGC build
#ifdef QGC_OSG_ENABLED
            case VIEW_LOCAL3D:
#endif
#ifdef QGC_GOOGLE_EARTH_ENABLED
            case VIEW_GOOGLEEARTH:
#endif

                currentView = currentViewCandidate;
            default:
                // If an invalid view candidate was found in the settings file, just use the default view and re-save.
                settings.setValue("CURRENT_VIEW", currentView);
                break;
    emit initStatusChanged(tr("Setting up user interface"), Qt::AlignLeft | Qt::AlignBottom, QColor(62, 93, 141));

    // Setup user interface
    ui.setupUi(this);
    // Set dock options
    setDockOptions(AnimatedDocks | AllowTabbedDocks | AllowNestedDocks);

    configureWindowName();

    // Setup corners
    setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
    // Qt 4 on Ubuntu does place the native menubar correctly so on Linux we revert back to in-window menu bar.
    // TODO: Check that this is still necessary on Qt5 on Ubuntu
#ifdef Q_OS_LINUX
    menuBar()->setNativeMenuBar(false);
#endif
Loading
Loading full blame...