7 #include <QScopedPointer>
8 #include <QStackedWidget>
12 #include <QVBoxLayout>
15 #include "ui_swiftguistd.h"
50 using namespace swift::config;
52 using namespace swift::core::context;
54 using namespace swift::misc::aviation;
55 using namespace swift::misc::network;
56 using namespace swift::misc::input;
60 void SwiftGuiStd::init()
63 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
67 if (m_init) {
return; }
69 ui->dw_InfoBarStatus->initialFloating();
71 this->setVisible(
false);
72 m_mwaStatusBar = &m_statusBar;
73 m_mwaOverlayFrame = ui->fr_CentralFrameInside;
74 m_mwaLogComponent = ui->comp_MainInfoArea->getLogComponent();
78 m_logHistoryForOverlay.setFilter(
CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityError));
79 m_logHistoryForLogButtons.setFilter(
CLogPattern().withSeverityAtOrAbove(SeverityWarning));
80 connect(&m_logHistoryForOverlay, &CLogHistoryReplica::elementAdded,
this, [
this](
const CStatusMessage &message) {
84 ui->fr_CentralFrameInside->showOverlayMessage(message);
87 connect(&m_logHistoryForLogButtons, &CLogHistoryReplica::elementAdded,
this, [
this](
const CStatusMessage &message) {
88 if (message.
getSeverity() == CStatusMessage::SeverityError) { m_statusBar.showErrorButton(); }
89 else if (message.
getSeverity() == CStatusMessage::SeverityWarning) { m_statusBar.showWarningButton(); }
95 this->initStyleSheet();
99 if (this->isFrameless())
102 QHBoxLayout *menuBarLayout = this->addFramelessCloseButton(ui->mb_MainMenuBar);
103 ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0);
106 ui->vl_CentralWidgetOutside->insertWidget(1, ui->dw_InfoBarStatus);
110 ui->sb_MainStatusBar->setParent(ui->wi_CentralWidgetOutside);
111 ui->vl_CentralWidgetOutside->addWidget(ui->sb_MainStatusBar, 0);
114 this->addFramelessSizeGripToStatusBar(ui->sb_MainStatusBar);
118 m_timerContextWatchdog.setObjectName(this->objectName().append(
":m_timerContextWatchdog"));
121 m_statusBar.initStatusBar(ui->sb_MainStatusBar);
122 connect(&m_statusBar, &CManagedStatusBar::requestLogPage, ui->comp_MainInfoArea,
123 &CMainInfoAreaComponent::displayLog);
124 ui->dw_InfoBarStatus->allowStatusBar(
false);
125 ui->dw_InfoBarStatus->setPreferredSizeWhenFloating(ui->dw_InfoBarStatus->size());
128 m_navigator->addAction(this->getToggleWindowVisibilityAction(m_navigator.data()));
129 m_navigator->addActions(ui->comp_MainInfoArea->getInfoAreaToggleFloatingActions(
130 m_navigator.data()));
131 m_navigator->addAction(this->getWindowNormalAction(m_navigator.data()));
132 m_navigator->addAction(this->getWindowMinimizeAction(m_navigator.data()));
133 m_navigator->addAction(this->getToggleStayOnTopAction(m_navigator.data()));
134 m_navigator->buildNavigator(1);
137 this->initGuiSignals();
144 &SwiftGuiStd::onConnectionStatusChanged, Qt::QueuedConnection);
146 s = connect(
sGui->
getIContextNetwork(), &IContextNetwork::kicked,
this, &SwiftGuiStd::onKickedFromNetwork,
147 Qt::QueuedConnection);
150 &SwiftGuiStd::onValidatedModelSet, Qt::QueuedConnection);
152 s = connect(&m_timerContextWatchdog, &QTimer::timeout,
this, &SwiftGuiStd::handleTimerBasedUpdates);
158 &SwiftGuiStd::onAudioClientFailure, Qt::QueuedConnection);
166 &SwiftGuiStd::checkDbDataLoaded, Qt::QueuedConnection);
169 m_timerContextWatchdog.start(2500);
172 this->setContextAvailability();
175 this->initialContextDataReads();
178 this->setMainPageToInfoArea();
182 connect(ui->comp_InfoBarStatus, &CInfoBarStatusComponent::transponderModeChanged, ui->dw_InfoBarStatus,
183 &CDockWidgetInfoBar::reloadStyleSheet, Qt::QueuedConnection);
187 this->setVisible(
true);
190 QPointer<SwiftGuiStd> myself(
this);
192 if (!myself) {
return; }
193 this->verifyPrerequisites();
203 void SwiftGuiStd::initStyleSheet()
207 CStyleSheetUtility::fileNameStandardWidget(),
208 CStyleSheetUtility::fileNameSwiftStandardGui() });
209 this->setStyleSheet(
"");
210 this->setStyleSheet(s);
213 void SwiftGuiStd::initGuiSignals()
219 connect(ui->sw_MainMiddle, &QStackedWidget::currentChanged,
this, &SwiftGuiStd::onCurrentMainWidgetChanged);
222 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::selectedMainInfoAreaDockWidget,
this,
223 &SwiftGuiStd::setMainPageInfoArea);
224 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed,
this, &SwiftGuiStd::loginRequested);
225 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity,
this,
226 &SwiftGuiStd::onChangedWindowOpacity);
227 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed,
228 ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent);
229 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::textEntered,
230 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::handleGlobalCommandLineText);
231 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, ui->comp_MainInfoArea,
232 &CMainInfoAreaComponent::selectAudioTab);
233 connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea,
234 &CMainKeypadAreaComponent::onMainInfoAreaChanged);
237 connect(ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::textMessageTabSelected,
this,
238 &SwiftGuiStd::focusInTextMessageEntryField, Qt::QueuedConnection);
241 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestAudioWidget,
242 ui->comp_MainInfoArea, &CMainInfoAreaComponent::selectAudioTab);
245 connect(ui->menu_TestLocationsEDDF, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
246 connect(ui->menu_TestLocationsEDDM, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
247 connect(ui->menu_TestLocationsEDNX, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
248 connect(ui->menu_TestLocationsEDRY, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
249 connect(ui->menu_TestLocationsLOWW, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
251 connect(ui->menu_WindowToggleNavigator, &QAction::triggered, m_navigator.data(),
252 &CNavigatorDialog::toggleNavigatorVisibility);
253 connect(ui->menu_WindowFont, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
254 connect(ui->menu_WindowMinimize, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
255 connect(ui->menu_WindowToggleOnTop, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
256 connect(ui->menu_InternalsPage, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
257 connect(ui->menu_AutoPublish, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
258 connect(ui->menu_ToggleIncognito, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
259 connect(ui->menu_ModelBrowser, &QAction::triggered,
this, &SwiftGuiStd::startModelBrowser, Qt::QueuedConnection);
260 connect(ui->menu_AfvMap, &QAction::triggered,
this, &SwiftGuiStd::startAFVMap, Qt::QueuedConnection);
262 connect(m_navigator.data(), &CNavigatorDialog::navigatorClosed,
this, &SwiftGuiStd::onNavigatorClosed,
263 Qt::QueuedConnection);
264 m_navigator->setMainWindow(
this);
267 connect(ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedWindowsOpacity,
this,
268 &SwiftGuiStd::onChangedWindowOpacity);
269 connect(
sGui, &CGuiApplication::styleSheetsChanged,
this, &SwiftGuiStd::onStyleSheetsChanged, Qt::QueuedConnection);
272 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffCancelled,
this, &SwiftGuiStd::setMainPageToInfoArea);
273 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful,
this, &SwiftGuiStd::setMainPageToInfoArea);
274 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, ui->comp_MainInfoArea->getFlightPlanComponent(),
275 &CFlightPlanComponent::loginDataSet);
276 connect(ui->comp_Login, &CLoginComponent::loginDataChangedDigest, ui->comp_MainInfoArea->getFlightPlanComponent(),
277 &CFlightPlanComponent::loginDataSet);
278 connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings,
this, &SwiftGuiStd::displayNetworkSettings);
279 connect(ui->comp_Login, &CLoginComponent::requestLoginPage, [
this]() {
280 if (!sApp || sApp->isShuttingDown()) { return; }
281 ui->sw_MainMiddle->setCurrentIndex(MainPageLogin);
284 Qt::QueuedConnection);
287 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageWidget,
288 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
289 Qt::QueuedConnection);
290 connect(ui->comp_MainInfoArea->getMappingComponent(), &CMappingComponent::requestTextMessageWidget,
291 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
292 Qt::QueuedConnection);
293 connect(ui->comp_MainInfoArea->getAircraftComponent(), &CAircraftComponent::requestTextMessageWidget,
294 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
295 Qt::QueuedConnection);
296 connect(ui->comp_MainInfoArea->getUserComponent(), &CUserComponent::requestTextMessageWidget,
297 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
298 Qt::QueuedConnection);
302 ui->fr_CentralFrameInside->activateTextMessages(
true);
303 connect(ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::displayInInfoWindow,
this,
304 &SwiftGuiStd::onShowOverlayVariant, Qt::QueuedConnection);
305 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageEntryTab,
this,
306 &SwiftGuiStd::onShowOverlayInlineTextMessageTab, Qt::QueuedConnection);
307 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageEntryCallsign,
308 this, &SwiftGuiStd::onShowOverlayInlineTextMessageCallsign, Qt::QueuedConnection);
309 connect(ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::requestTextMessageEntryTab,
this,
310 &SwiftGuiStd::onShowOverlayInlineTextMessageTab, Qt::QueuedConnection);
311 connect(ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::requestTextMessageEntryCallsign,
this,
312 &SwiftGuiStd::onShowOverlayInlineTextMessageCallsign, Qt::QueuedConnection);
315 connect(ui->comp_MainInfoArea->getMappingComponent(), &CMappingComponent::requestValidationDialog,
this,
316 &SwiftGuiStd::displayValidationDialog);
319 connect(
sGui, &CGuiApplication::alwaysOnTop,
this, &SwiftGuiStd::onToggledWindowsOnTop, Qt::QueuedConnection);
322 connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedWholeInfoAreaFloating,
this,
323 &SwiftGuiStd::onChangedMainInfoAreaFloating, Qt::QueuedConnection);
326 void SwiftGuiStd::initialContextDataReads()
328 this->setContextAvailability();
329 if (!m_coreAvailable)
331 CLogMessage(
this).
error(u
"No initial data read as network context is not available");
335 this->reloadOwnAircraft();
339 void SwiftGuiStd::stopAllTimers(
bool disconnectSignalSlots)
341 m_timerContextWatchdog.stop();
342 if (!disconnectSignalSlots) {
return; }
343 this->disconnect(&m_timerContextWatchdog);
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
void currentMainInfoAreaChanged(const QWidget *currentWidget)
Main info area has changed.
swift::misc::shared_state::CDataLinkDBus * getDataLinkDBus()
Transport mechanism for sharing state between applications.
const context::IContextAudio * getIContextAudio() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
bool supportsContexts(bool ignoreShutdownTest=false) const
Supports contexts.
CWebDataServices * getWebDataServices() const
Get the web data services.
void triggerNewVersionCheck(int delayedMs)
Trigger new version check.
const CStyleSheetUtility & getStyleSheetUtility() const
Style sheet handling.
void initMainApplicationWidget(QWidget *mainWidget)
Init the main application window based on information in this application.
QString styles(const QStringList &fileNames) const
Multiple styles concatenated.
Class for emitting a log message.
Value class for matching log messages based on their categories.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
Streamable status message, e.g.
StatusSeverity getSeverity() const
Message severity.
const CLogCategoryList & getCategories() const
Message categories.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Free functions in swift::misc.
QMetaObject::Connection connectOnce(T *sender, F signal, U *receiver, G &&slot, Qt::ConnectionType type=Qt::AutoConnection)
Wrapper around QObject::connect which disconnects after the signal has been emitted once.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...