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()
216 connect(ui->sw_MainMiddle, &QStackedWidget::currentChanged,
this, &SwiftGuiStd::onCurrentMainWidgetChanged);
219 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::selectedMainInfoAreaDockWidget,
this,
220 &SwiftGuiStd::setMainPageInfoArea);
221 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed,
this, &SwiftGuiStd::loginRequested);
222 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity,
this,
223 &SwiftGuiStd::onChangedWindowOpacity);
224 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed,
225 ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent);
226 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::textEntered,
227 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::handleGlobalCommandLineText);
228 connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, ui->comp_MainInfoArea,
229 &CMainInfoAreaComponent::selectAudioTab);
230 connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea,
231 &CMainKeypadAreaComponent::onMainInfoAreaChanged);
234 connect(ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::textMessageTabSelected,
this,
235 &SwiftGuiStd::focusInTextMessageEntryField, Qt::QueuedConnection);
238 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestAudioWidget,
239 ui->comp_MainInfoArea, &CMainInfoAreaComponent::selectAudioTab);
242 connect(ui->menu_TestLocationsEDDF, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
243 connect(ui->menu_TestLocationsEDDM, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
244 connect(ui->menu_TestLocationsEDNX, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
245 connect(ui->menu_TestLocationsEDRY, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
246 connect(ui->menu_TestLocationsLOWW, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
248 connect(ui->menu_WindowToggleNavigator, &QAction::triggered, m_navigator.data(),
249 &CNavigatorDialog::toggleNavigatorVisibility);
250 connect(ui->menu_WindowFont, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
251 connect(ui->menu_WindowMinimize, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
252 connect(ui->menu_WindowToggleOnTop, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
253 connect(ui->menu_InternalsPage, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
254 connect(ui->menu_AutoPublish, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
255 connect(ui->menu_ToggleIncognito, &QAction::triggered,
this, &SwiftGuiStd::onMenuClicked);
256 connect(ui->menu_ModelBrowser, &QAction::triggered,
this, &SwiftGuiStd::startModelBrowser, Qt::QueuedConnection);
257 connect(ui->menu_AfvMap, &QAction::triggered,
this, &SwiftGuiStd::startAFVMap, Qt::QueuedConnection);
259 connect(m_navigator.data(), &CNavigatorDialog::navigatorClosed,
this, &SwiftGuiStd::onNavigatorClosed,
260 Qt::QueuedConnection);
261 m_navigator->setMainWindow(
this);
264 connect(ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedWindowsOpacity,
this,
265 &SwiftGuiStd::onChangedWindowOpacity);
266 connect(
sGui, &CGuiApplication::styleSheetsChanged,
this, &SwiftGuiStd::onStyleSheetsChanged, Qt::QueuedConnection);
269 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffCancelled,
this, &SwiftGuiStd::setMainPageToInfoArea);
270 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful,
this, &SwiftGuiStd::setMainPageToInfoArea);
271 connect(ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, ui->comp_MainInfoArea->getFlightPlanComponent(),
272 &CFlightPlanComponent::loginDataSet);
273 connect(ui->comp_Login, &CLoginComponent::loginDataChangedDigest, ui->comp_MainInfoArea->getFlightPlanComponent(),
274 &CFlightPlanComponent::loginDataSet);
275 connect(ui->comp_Login, &CLoginComponent::requestNetworkSettings,
this, &SwiftGuiStd::displayNetworkSettings);
276 connect(ui->comp_Login, &CLoginComponent::requestLoginPage, [
this]() {
277 if (!sApp || sApp->isShuttingDown()) { return; }
278 ui->sw_MainMiddle->setCurrentIndex(MainPageLogin);
281 Qt::QueuedConnection);
284 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageWidget,
285 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
286 Qt::QueuedConnection);
287 connect(ui->comp_MainInfoArea->getMappingComponent(), &CMappingComponent::requestTextMessageWidget,
288 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
289 Qt::QueuedConnection);
290 connect(ui->comp_MainInfoArea->getAircraftComponent(), &CAircraftComponent::requestTextMessageWidget,
291 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
292 Qt::QueuedConnection);
293 connect(ui->comp_MainInfoArea->getUserComponent(), &CUserComponent::requestTextMessageWidget,
294 ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::showCorrespondingTab,
295 Qt::QueuedConnection);
299 ui->fr_CentralFrameInside->activateTextMessages(
true);
300 connect(ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::displayInInfoWindow,
this,
301 &SwiftGuiStd::onShowOverlayVariant, Qt::QueuedConnection);
302 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageEntryTab,
this,
303 &SwiftGuiStd::onShowOverlayInlineTextMessageTab, Qt::QueuedConnection);
304 connect(ui->comp_MainInfoArea->getAtcStationComponent(), &CAtcStationComponent::requestTextMessageEntryCallsign,
305 this, &SwiftGuiStd::onShowOverlayInlineTextMessageCallsign, Qt::QueuedConnection);
306 connect(ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::requestTextMessageEntryTab,
this,
307 &SwiftGuiStd::onShowOverlayInlineTextMessageTab, Qt::QueuedConnection);
308 connect(ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::requestTextMessageEntryCallsign,
this,
309 &SwiftGuiStd::onShowOverlayInlineTextMessageCallsign, Qt::QueuedConnection);
312 connect(ui->comp_MainInfoArea->getMappingComponent(), &CMappingComponent::requestValidationDialog,
this,
313 &SwiftGuiStd::displayValidationDialog);
316 connect(
sGui, &CGuiApplication::alwaysOnTop,
this, &SwiftGuiStd::onToggledWindowsOnTop, Qt::QueuedConnection);
319 connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedWholeInfoAreaFloating,
this,
320 &SwiftGuiStd::onChangedMainInfoAreaFloating, Qt::QueuedConnection);
323 void SwiftGuiStd::initialContextDataReads()
325 this->setContextAvailability();
326 if (!m_coreAvailable)
328 CLogMessage(
this).
error(u
"No initial data read as network context is not available");
332 this->reloadOwnAircraft();
336 void SwiftGuiStd::stopAllTimers(
bool disconnectSignalSlots)
338 m_timerContextWatchdog.stop();
339 if (!disconnectSignalSlots) {
return; }
340 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...