Skip to content
MainWindow.cc 28.7 KiB
Newer Older
pixhawk's avatar
pixhawk committed
/*=====================================================================

QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed

This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
    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,
pixhawk's avatar
pixhawk committed
    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/>.
pixhawk's avatar
pixhawk committed

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

/**
 * @file
 *   @brief Implementation of class MainWindow
 *   @author Lorenz Meier <mail@qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
 */

#include <QSettings>
#include <QDockWidget>
#include <QNetworkInterface>
#include <QMessageBox>
#include <QDebug>
#include <QTimer>
#include <QHostInfo>

#include "MG.h"
#include "MAVLinkSimulationLink.h"
#include "SerialLink.h"
#include "UDPLink.h"
#include "MAVLinkProtocol.h"
#include "CommConfigurationWindow.h"
#include "WaypointList.h"
#include "MainWindow.h"
#include "JoystickWidget.h"
pixhawk's avatar
pixhawk committed
#include "GAudioOutput.h"
pixhawk's avatar
pixhawk committed

lm's avatar
lm committed
// FIXME Move
#include "PxQuadMAV.h"
#include "SlugsMAV.h"

pixhawk's avatar
pixhawk committed

#include "LogCompressor.h"

/**
* Create new mainwindow. The constructor instantiates all parts of the user
* interface. It does NOT show the mainwindow. To display it, call the show()
* method.
*
* @see QMainWindow::show()
**/
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  settings()
pixhawk's avatar
pixhawk committed
{
    this->hide();
    this->setVisible(false);

pixhawk's avatar
pixhawk committed
    // Setup user interface
    ui.setupUi(this);

    buildWidgets();

    connectWidgets();

    arrangeCenterStack();

    configureWindowName();
pixhawk's avatar
pixhawk committed

    // Add status bar
    setStatusBar(createStatusBar());

    // Set the application style (not the same as a style sheet)
    // Set the style to Plastique
    qApp->setStyle("plastique");
pixhawk's avatar
pixhawk committed
    // Set style sheet as last step
    reloadStylesheet();


    // Create actions
    connectActions();

    // Load widgets and show application window
    loadWidgets();

    // Adjust the size
    adjustSize();
pixhawk's avatar
pixhawk committed
}

pixhawk's avatar
pixhawk committed
MainWindow::~MainWindow()
pixhawk's avatar
pixhawk committed
{
    delete statusBar;
    statusBar = NULL;
}

  //FIXME: memory of acceptList will never be freed again
  QStringList* acceptList = new QStringList();
  acceptList->append("roll IMU");
  acceptList->append("pitch IMU");
  acceptList->append("yaw IMU");
  acceptList->append("rollspeed IMU");
  acceptList->append("pitchspeed IMU");
  acceptList->append("yawspeed IMU");

  //FIXME: memory of acceptList2 will never be freed again
  QStringList* acceptList2 = new QStringList();
  acceptList2->append("Battery");
  acceptList2->append("Pressure");

  //TODO:  move protocol outside UI

  // Center widgets
  linechartWidget   = new Linecharts(this);
  hudWidget         = new HUD(640, 480, this);
  mapWidget         = new MapWidget(this);
  protocolWidget    = new XMLCommProtocolWidget(this);
  dataplotWidget    = new QGCDataPlot2D(this);

  // Dock widgets
  controlDockWidget = new QDockWidget(tr("Control"), this);
  controlDockWidget->setWidget( new UASControlWidget(this) );

  listDockWidget = new QDockWidget(tr("Unmanned Systems"), this);
  listDockWidget->setWidget( new UASListWidget(this) );

  waypointsDockWidget = new QDockWidget(tr("Waypoint List"), this);
  waypointsDockWidget->setWidget( new WaypointList(this, NULL) );

  infoDockWidget = new QDockWidget(tr("Status Details"), this);
  infoDockWidget->setWidget( new UASInfoWidget(this) );

  detectionDockWidget = new QDockWidget(tr("Object Recognition"), this);
  detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) );

  debugConsoleDockWidget = new QDockWidget(tr("Communication Console"), this);
  debugConsoleDockWidget->setWidget( new DebugConsole(this) );

  parametersDockWidget = new QDockWidget(tr("Onboard Parameters"), this);
  parametersDockWidget->setWidget( new ParameterInterface(this) );

  watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this);
  watchdogControlDockWidget->setWidget( new WatchdogControl(this) );

  hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this);
  hsiDockWidget->setWidget( new HSIDisplay(this) );

  headDown1DockWidget = new QDockWidget(tr("Primary Flight Display"), this);
  headDown1DockWidget->setWidget( new HDDisplay(acceptList, this) );

  headDown2DockWidget = new QDockWidget(tr("Payload Status"), this);
  headDown2DockWidget->setWidget( new HDDisplay(acceptList2, this) );

  rcViewDockWidget = new QDockWidget(tr("Radio Control"), this);
  rcViewDockWidget->setWidget( new QGCRemoteControlView(this) );

  // Dialogue widgets
  //FIXME: free memory in destructor
  if (linechartWidget)
  {
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
      linechartWidget, SLOT(addSystem(UASInterface*)));
    connect(UASManager::instance(), SIGNAL(activeUASSet(int)),
      linechartWidget, SLOT(selectSystem(int)));
    connect(linechartWidget, SIGNAL(logfileWritten(QString)),
      this, SLOT(loadDataView(QString)));
  }
  if (infoDockWidget && infoDockWidget->widget())
  {
    connect(mavlink, SIGNAL(receiveLossChanged(int, float)),
      infoDockWidget->widget(), SLOT(updateSendLoss(int, float)));
  }
  QStackedWidget *centerStack = new QStackedWidget(this);
  if (!centerStack) return;
Loading
Loading full blame...