Newer
Older
pixhawk
committed
/*===================================================================
======================================================================*/
/**
* @file
* @brief Implementation of class MainWindow
* @author Lorenz Meier <mail@qgroundcontrol.org>
*/
#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"
lm
committed
#include "QGCToolWidget.h"
#include "QGCMAVLinkLogPlayer.h"
#include "Q3DWidgetFactory.h"
MainWindow* MainWindow::instance()
{
static MainWindow* _instance = 0;
if(_instance == 0)
{
_instance = new MainWindow();
/* Set the application as parent to ensure that this object
* will be destroyed when the main application exits */
//_instance->setParent(qApp);
}
return _instance;
/**
* 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()
**/
Mariano Lizarraga
committed
MainWindow::MainWindow(QWidget *parent):
Mariano Lizarraga
committed
toolsMenuActions(),
changingViewsFlag(false),
// Get current settings
settings.sync();
if (!settings.contains("CURRENT_VIEW"))
{
// Set this view as default view
settings.setValue("CURRENT_VIEW", currentView);
// Enable default tools
// ENABLE UAS LIST
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_UAS_LIST,currentView), true);
// ENABLE COMMUNICATION CONSOLE
settings.setValue(buildMenuKey(SUB_SECTION_CHECKED,MainWindow::MENU_DEBUG_CONSOLE,currentView), true);
}
else
{
currentView = (VIEW_SECTIONS) settings.value("CURRENT_VIEW", currentView).toInt();
}
// Check if the settings exist, instantiate defaults if necessary
// OPERATOR VIEW DEFAULT
QString centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_MAP, VIEW_OPERATOR);
if (!settings.contains(centralKey))
{
settings.setValue(centralKey,true);
}
// ENGINEER VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_LINECHART, VIEW_ENGINEER);
if (!settings.contains(centralKey))
{
settings.setValue(centralKey,true);
}
// MAVLINK VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_PROTOCOL, VIEW_MAVLINK);
if (!settings.contains(centralKey))
{
settings.setValue(centralKey,true);
}
// PILOT VIEW DEFAULT
centralKey = buildMenuKey(SUB_SECTION_CHECKED, CENTRAL_HUD, VIEW_PILOT);
if (!settings.contains(centralKey))
{
settings.setValue(centralKey,true);
}
QString listKey = buildMenuKey(SUB_SECTION_CHECKED, MENU_UAS_LIST, currentView);
if (!settings.contains(listKey))
{
settings.setValue(listKey, true);
}
settings.sync();
setVisible(false);
// Bind together the perspective actions
QActionGroup* perspectives = new QActionGroup(ui.menuPerspectives);
perspectives->addAction(ui.actionEngineersView);
perspectives->addAction(ui.actionMavlinkView);
perspectives->addAction(ui.actionPilotsView);
perspectives->addAction(ui.actionOperatorsView);
perspectives->setExclusive(true);
// Mark the right one as selected
if (currentView == VIEW_ENGINEER) ui.actionEngineersView->setChecked(true);
if (currentView == VIEW_MAVLINK) ui.actionMavlinkView->setChecked(true);
if (currentView == VIEW_PILOT) ui.actionPilotsView->setChecked(true);
if (currentView == VIEW_OPERATOR) ui.actionOperatorsView->setChecked(true);
// The pilot view is not available on startup
ui.actionPilotsView->setEnabled(false);
Mariano Lizarraga
committed
buildCommonWidgets();
Mariano Lizarraga
committed
Mariano Lizarraga
committed
connectCommonWidgets();
Mariano Lizarraga
committed
Mariano Lizarraga
committed
arrangeCommonCenterStack();
Mariano Lizarraga
committed
configureWindowName();
// Set the application style (not the same as a style sheet)
// Set the style to Plastique
qApp->setStyle("plastique");
Mariano Lizarraga
committed
QFile* styleSheet = new QFile(":/images/style-mission.css");
if (styleSheet->open(QIODevice::ReadOnly | QIODevice::Text))
{
QString style = QString(styleSheet->readAll());
style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "/images/");
qApp->setStyleSheet(style);
}
Mariano Lizarraga
committed
connectCommonActions();
lm
committed
// Add option for custom widgets
connect(ui.actionNewCustomWidget, SIGNAL(triggered()), this, SLOT(createCustomWidget()));
// Allow to mute audio
ui.actionMuteAudioOutput->setChecked(GAudioOutput::instance()->isMuted());
connect(ui.actionMuteAudioOutput, SIGNAL(triggered(bool)), GAudioOutput::instance(), SLOT(mute(bool)));
// Set dock options
setDockOptions(AnimatedDocks | AllowTabbedDocks | AllowNestedDocks);
Mariano Lizarraga
committed
// Load mavlink view as default widget set
//loadMAVLinkView();
// Restore the window position and size
if (settings.contains(getWindowGeometryKey()))
{
// Restore the window geometry
restoreGeometry(settings.value(getWindowGeometryKey()).toByteArray());
}
else
{
// Adjust the size
adjustSize();
}
Loading
Loading full blame...