1
0
Fork 0
flightgear/src/GUI/LauncherMainWindow.cxx

138 lines
4.1 KiB
C++
Raw Normal View History

#include "LauncherMainWindow.hxx"
// Qt headers
#include <QMessageBox>
#include <QSettings>
#include <QDebug>
#include <QMenu>
2017-02-21 11:01:06 +00:00
#include <QMenuBar>
#include <QQuickItem>
2017-02-21 11:01:06 +00:00
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlError>
2017-02-21 11:01:06 +00:00
2017-05-16 12:25:33 +00:00
#include "version.h"
// launcher headers
#include "QtLauncher.hxx"
#include "DefaultAircraftLocator.hxx"
#include "LaunchConfig.hxx"
#include "AircraftModel.hxx"
#include "LocalAircraftCache.hxx"
#include "LauncherController.hxx"
#include "AddOnsController.hxx"
#include "LocationController.hxx"
//////////////////////////////////////////////////////////////////////////////
LauncherMainWindow::LauncherMainWindow() :
QQuickView()
{
setTitle("FlightGear " FLIGHTGEAR_VERSION);
m_controller = new LauncherController(this, this);
m_controller->initQML();
#if defined(Q_OS_MAC)
QMenuBar* mb = new QMenuBar();
2017-02-21 11:01:06 +00:00
QMenu* fileMenu = mb->addMenu(tr("File"));
QAction* openAction = fileMenu->addAction(tr("Open saved configuration..."));
connect(openAction, &QAction::triggered,
m_controller, &LauncherController::openConfig);
QAction* saveAction = fileMenu->addAction(tr("Save configuration as..."));
connect(saveAction, &QAction::triggered,
m_controller, &LauncherController::saveConfigAs);
QMenu* toolsMenu = mb->addMenu(tr("Tools"));
QAction* restoreDefaultsAction = toolsMenu->addAction(tr("Restore defaults..."));
connect(restoreDefaultsAction, &QAction::triggered,
2018-06-26 16:13:28 +00:00
m_controller, &LauncherController::requestRestoreDefaults);
QAction* changeDataAction = toolsMenu->addAction(tr("Select data files location..."));
connect(changeDataAction, &QAction::triggered,
2018-06-26 16:13:28 +00:00
m_controller, &LauncherController::requestChangeDataPath);
QAction* viewCommandLineAction = toolsMenu->addAction(tr("View command-line"));
connect(viewCommandLineAction, &QAction::triggered,
m_controller, &LauncherController::viewCommandLine);
#endif
QAction* qa = new QAction(this);
qa->setShortcut(QKeySequence("Ctrl+Q"));
2018-06-26 16:13:28 +00:00
connect(qa, &QAction::triggered, m_controller, &LauncherController::quit);
m_controller->initialRestoreSettings();
flightgear::launcherSetSceneryPaths();
auto addOnsCtl = new AddOnsController(this);
2018-03-11 11:49:38 +00:00
////////////
#if defined(Q_OS_WIN)
const QString osName("win");
#elif defined(Q_OS_MAC)
const QString osName("mac");
#else
const QString osName("unix");
#endif
2018-03-11 11:49:38 +00:00
setResizeMode(QQuickView::SizeRootObjectToView);
engine()->addImportPath("qrc:///");
QQmlContext* ctx = rootContext();
ctx->setContextProperty("_launcher", m_controller);
ctx->setContextProperty("_addOns", addOnsCtl);
ctx->setContextProperty("_config", m_controller->config());
ctx->setContextProperty("_location", m_controller->location());
ctx->setContextProperty("_osName", osName);
2018-03-11 11:49:38 +00:00
auto weatherScenariosModel = new flightgear::WeatherScenariosModel(this);
ctx->setContextProperty("_weatherScenarios", weatherScenariosModel);
setSource(QUrl("qrc:///qml/Launcher.qml"));
2018-06-26 16:13:28 +00:00
setMinimumSize(QSize(300, 400));
2017-02-21 11:01:06 +00:00
}
#if 0
void LauncherMainWindow::onQuickStatusChanged(QQuickWidget::Status status)
{
if (status == QQuickWidget::Error) {
QQuickWidget* qw = qobject_cast<QQuickWidget*>(sender());
QString errorString;
Q_FOREACH(auto err, qw->errors()) {
errorString.append("\n" + err.toString());
}
QMessageBox::critical(this, "UI loading failures.",
tr("Problems occurred loading the user interface. This is often due to missing modules on your system. "
"Please report this error to the FlightGear developer list or forum, and take care to mention your system "
"distribution, etc. Please also include the information provided below.\n")
+ errorString);
}
}
#endif
LauncherMainWindow::~LauncherMainWindow()
{
}
bool LauncherMainWindow::execInApp()
{
2018-06-23 16:55:39 +00:00
m_controller->setInAppMode();
show();
2018-06-23 16:55:39 +00:00
while (m_controller->keepRunningInAppMode()) {
qApp->processEvents();
}
2018-06-23 16:55:39 +00:00
return m_controller->inAppResult();
}