mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +08:00
refs #608, generic menus are now available via CGuiApplication and don`t have to be redefined over and over again
This commit is contained in:
committed by
Mathew Sutcliffe
parent
bf9ea12a2b
commit
bcb00b1b91
@@ -9,16 +9,18 @@
|
||||
|
||||
#include "swiftguistd.h"
|
||||
#include "ui_swiftguistd.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackgui/models/atcstationlistmodel.h"
|
||||
#include "blackgui/components/logcomponent.h"
|
||||
#include "blackgui/components/settingscomponent.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackcore/contextnetwork.h"
|
||||
#include "blackcore/contextapplication.h"
|
||||
#include "blackcore/contextownaircraft.h"
|
||||
#include "blackcore/network.h"
|
||||
#include "blackmisc/threadutils.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/audio/notificationsounds.h"
|
||||
@@ -54,18 +56,6 @@ SwiftGuiStd::SwiftGuiStd(BlackGui::CEnableForFramelessWindow::WindowMode windowM
|
||||
SwiftGuiStd::~SwiftGuiStd()
|
||||
{ }
|
||||
|
||||
bool SwiftGuiStd::displayInStatusBar(const CStatusMessage &message)
|
||||
{
|
||||
this->ps_displayStatusMessageInGui(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SwiftGuiStd::displayInOverlayWindow(const CStatusMessage &message)
|
||||
{
|
||||
this->ui->fr_CentralFrameInside->showOverlayMessage(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SwiftGuiStd::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!handleMouseMoveEvent(event)) { QMainWindow::mouseMoveEvent(event); }
|
||||
@@ -81,13 +71,15 @@ void SwiftGuiStd::performGracefulShutdown()
|
||||
if (!this->m_init) { return; }
|
||||
this->m_init = false;
|
||||
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Should shutdown in main thread");
|
||||
|
||||
// shut down all timers
|
||||
this->stopAllTimers(true);
|
||||
|
||||
// if we have a context, we shut some things down
|
||||
if (this->m_contextNetworkAvailable)
|
||||
{
|
||||
if (sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected())
|
||||
if (sGui && sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected())
|
||||
{
|
||||
if (this->m_contextAudioAvailable)
|
||||
{
|
||||
@@ -103,11 +95,9 @@ void SwiftGuiStd::performGracefulShutdown()
|
||||
this->ui->comp_MainInfoArea->dockAllWidgets();
|
||||
|
||||
// allow some other parts to react
|
||||
if (!sGui) { return; } // overall shutdown
|
||||
sGui->processEventsToRefreshGui();
|
||||
|
||||
// tell GUI components to shut down
|
||||
emit requestGracefulShutdown();
|
||||
|
||||
// tell context GUI is going down
|
||||
if (sGui->getIContextApplication())
|
||||
{
|
||||
@@ -267,13 +257,16 @@ void SwiftGuiStd::setContextAvailability()
|
||||
{
|
||||
bool corePreviouslyAvailable = this->m_coreAvailable;
|
||||
|
||||
if (sGui->getIContextApplication()->isUsingImplementingObject())
|
||||
if (sGui && sGui->getIContextApplication()->isUsingImplementingObject())
|
||||
{
|
||||
this->m_coreAvailable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_coreAvailable = isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier()));
|
||||
// ping to check if core is still alive
|
||||
this->m_coreAvailable =
|
||||
sGui &&
|
||||
this->isMyIdentifier(sGui->getIContextApplication()->registerApplication(getCurrentTimestampIdentifier()));
|
||||
}
|
||||
this->m_contextNetworkAvailable = this->m_coreAvailable || sGui->getIContextNetwork()->isUsingImplementingObject();
|
||||
this->m_contextAudioAvailable = this->m_coreAvailable || sGui->getIContextAudio()->isUsingImplementingObject();
|
||||
@@ -283,7 +276,7 @@ void SwiftGuiStd::setContextAvailability()
|
||||
{
|
||||
if (this->m_coreAvailable)
|
||||
{
|
||||
// core has just become available
|
||||
// core has just become available (startup)
|
||||
sGui->getIContextApplication()->synchronizeLogSubscriptions();
|
||||
sGui->getIContextApplication()->synchronizeLocalSettings();
|
||||
}
|
||||
@@ -321,21 +314,7 @@ void SwiftGuiStd::ps_onChangedWindowOpacity(int opacity)
|
||||
|
||||
void SwiftGuiStd::ps_toogleWindowStayOnTop()
|
||||
{
|
||||
Qt::WindowFlags flags = this->windowFlags();
|
||||
if (Qt::WindowStaysOnTopHint & flags)
|
||||
{
|
||||
flags ^= Qt::WindowStaysOnTopHint;
|
||||
flags |= Qt::WindowStaysOnBottomHint;
|
||||
CLogMessage(this).info("Window on bottom");
|
||||
}
|
||||
else
|
||||
{
|
||||
flags ^= Qt::WindowStaysOnBottomHint;
|
||||
flags |= Qt::WindowStaysOnTopHint;
|
||||
CLogMessage(this).info("Window on top");
|
||||
}
|
||||
this->setWindowFlags(flags);
|
||||
this->show();
|
||||
CGuiUtility::toggleStayOnTop(this);
|
||||
}
|
||||
|
||||
void SwiftGuiStd::ps_toggleWindowVisibility()
|
||||
|
||||
@@ -70,17 +70,7 @@ public:
|
||||
//! Log message category
|
||||
static QString getMessageCategory() { return "swift.gui.stdgui"; }
|
||||
|
||||
//! \name direct access to main application window
|
||||
//! @{
|
||||
virtual bool displayInStatusBar(const BlackMisc::CStatusMessage &message) override;
|
||||
virtual bool displayInOverlayWindow(const BlackMisc::CStatusMessage &message) override;
|
||||
//! }@
|
||||
|
||||
signals:
|
||||
//! GUI is shutting down, request graceful shutdown
|
||||
void requestGracefulShutdown();
|
||||
|
||||
//! Main info area changed
|
||||
//! \remarks using widget pointer allows the component itself to identify if it is current
|
||||
void currentMainInfoAreaChanged(const QWidget *currentWidget);
|
||||
|
||||
@@ -150,10 +140,7 @@ private:
|
||||
void initGuiSignals();
|
||||
|
||||
//! Init dynamic menus
|
||||
void initDynamicMenus();
|
||||
|
||||
//! Menu icons where required
|
||||
void initMenuIcons();
|
||||
void initMenus();
|
||||
|
||||
//! Graceful shutdown
|
||||
void performGracefulShutdown();
|
||||
|
||||
@@ -259,25 +259,14 @@
|
||||
<addaction name="menu_TestLocationsEDNX"/>
|
||||
<addaction name="menu_TestLocationsLOWW"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Reload">
|
||||
<property name="title">
|
||||
<string>Reload</string>
|
||||
</property>
|
||||
<addaction name="menu_ReloadSettings"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_InternalsItem">
|
||||
<widget class="QMenu" name="menu_Internals">
|
||||
<property name="title">
|
||||
<string>Internals</string>
|
||||
</property>
|
||||
<addaction name="menu_Internals"/>
|
||||
<addaction name="menu_InternalsMetatypes"/>
|
||||
<addaction name="menu_InternalsSetup"/>
|
||||
<addaction name="menu_InternalsCompileInfo"/>
|
||||
<addaction name="menu_InternalsPage"/>
|
||||
</widget>
|
||||
<addaction name="menu_InternalsItem"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="menu_Internals"/>
|
||||
<addaction name="menu_PlanePositions"/>
|
||||
<addaction name="menu_Reload"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
@@ -288,27 +277,7 @@
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_Settings">
|
||||
<property name="title">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
<addaction name="menu_SettingsDirectory"/>
|
||||
<addaction name="menu_SettingsFiles"/>
|
||||
<addaction name="menu_SettingsReset"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Cache">
|
||||
<property name="title">
|
||||
<string>Cache</string>
|
||||
</property>
|
||||
<addaction name="menu_CacheDirectory"/>
|
||||
<addaction name="menu_CacheFiles"/>
|
||||
<addaction name="menu_CacheReset"/>
|
||||
</widget>
|
||||
<addaction name="menu_Settings"/>
|
||||
<addaction name="menu_Cache"/>
|
||||
<addaction name="menu_FileReloadStyleSheets"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="menu_FileExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_InfoAreas">
|
||||
<property name="title">
|
||||
@@ -320,9 +289,8 @@
|
||||
<string>Window</string>
|
||||
</property>
|
||||
<addaction name="menu_WindowFont"/>
|
||||
<addaction name="menu_WindowMinimize"/>
|
||||
<addaction name="menu_WindowToggleOnTop"/>
|
||||
<addaction name="menu_WindowToggleNavigator"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<addaction name="menu_File"/>
|
||||
<addaction name="menu_Window"/>
|
||||
@@ -498,9 +466,9 @@
|
||||
<string>Compile info</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menu_Internals">
|
||||
<action name="menu_InternalsPage">
|
||||
<property name="text">
|
||||
<string>Internal page</string>
|
||||
<string>Internals page</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menu_InternalsDeleteCachedFiles">
|
||||
@@ -546,6 +514,12 @@
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::COverlayMessagesFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/overlaymessagesframe.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CMainInfoAreaComponent</class>
|
||||
<extends>QWidget</extends>
|
||||
@@ -582,12 +556,6 @@
|
||||
<header>blackgui/components/internalscomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::COverlayMessagesFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/overlaymessagesframe.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -35,8 +35,14 @@ void SwiftGuiStd::init()
|
||||
// POST(!) GUI init
|
||||
|
||||
if (this->m_init) { return; }
|
||||
|
||||
this->setVisible(false); // hide all, so no flashing windows during init
|
||||
this->m_mwaStatusBar = &this->m_statusBar;
|
||||
this->m_mwaOverlayFrame = this->ui->fr_CentralFrameInside;
|
||||
this->m_mwaLogComponent = this->ui->comp_MainInfoArea->getLogComponent();
|
||||
|
||||
sGui->initMainApplicationWindow(this);
|
||||
this->initStyleSheet();
|
||||
|
||||
// with frameless window, we shift menu and statusbar into central widget
|
||||
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
|
||||
@@ -102,8 +108,7 @@ void SwiftGuiStd::init()
|
||||
|
||||
// start screen and complete menu
|
||||
this->ps_setMainPageToInfoArea();
|
||||
this->initDynamicMenus();
|
||||
this->initMenuIcons();
|
||||
this->initMenus();
|
||||
|
||||
// info
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(sGui->swiftVersionString());
|
||||
@@ -148,34 +153,17 @@ void SwiftGuiStd::initGuiSignals()
|
||||
connect(this->ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged);
|
||||
|
||||
// menu
|
||||
connect(this->ui->menu_ReloadSettings, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_TestLocationsEDDF, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_TestLocationsEDDM, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_TestLocationsEDNX, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_TestLocationsEDRY, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_TestLocationsLOWW, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
|
||||
connect(this->ui->menu_FileExit, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_FileReloadStyleSheets, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
|
||||
connect(this->ui->menu_SettingsDirectory, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_SettingsFiles, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_SettingsReset, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_CacheDirectory, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_CacheFiles, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_CacheReset, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
|
||||
connect(this->ui->menu_WindowFont, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_WindowMinimize, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_WindowToggleOnTop, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_WindowToggleNavigator, &QAction::triggered, this->m_navigator.data(), &CNavigatorDialog::toggleNavigator);
|
||||
|
||||
connect(this->ui->menu_InternalsCompileInfo, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsEnvVars, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsMetatypes, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsSetup, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsDeleteCachedFiles, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsDisplayCachedFiles, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
connect(this->ui->menu_InternalsPage, &QAction::triggered, this, &SwiftGuiStd::ps_onMenuClicked);
|
||||
|
||||
// command line / text messages
|
||||
connect(this->ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::displayInInfoWindow, this->ui->fr_CentralFrameInside, &COverlayMessagesFrame::showOverlayVariant);
|
||||
|
||||
@@ -56,100 +56,23 @@ void SwiftGuiStd::ps_onMenuClicked()
|
||||
{
|
||||
this->setTestPosition("N 48° 7′ 6.3588", "E 16° 33′ 39.924", CAltitude(100, CAltitude::MeanSeaLevel, CLengthUnit::m()));
|
||||
}
|
||||
else if (sender == this->ui->menu_FileReloadStyleSheets)
|
||||
{
|
||||
sGui->reloadStyleSheets();
|
||||
}
|
||||
else if (sender == this->ui->menu_WindowFont)
|
||||
{
|
||||
this->ps_setMainPageToInfoArea();
|
||||
this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui);
|
||||
}
|
||||
else if (sender == this->ui->menu_WindowMinimize)
|
||||
{
|
||||
this->ps_showMinimized();
|
||||
}
|
||||
else if (sender == this->ui->menu_WindowToggleOnTop)
|
||||
{
|
||||
this->ps_toogleWindowStayOnTop();
|
||||
}
|
||||
else if (sender == this->ui->menu_FileExit)
|
||||
{
|
||||
CLogMessage(this).info("Closing");
|
||||
this->close();
|
||||
}
|
||||
else if (sender == this->ui->menu_SettingsDirectory)
|
||||
{
|
||||
QString path(QDir::toNativeSeparators(CSettingsCache::persistentStore()));
|
||||
if (QDir(path).exists())
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl("file:///" + path));
|
||||
}
|
||||
}
|
||||
else if (sender == this->ui->menu_SettingsReset)
|
||||
{
|
||||
CSettingsCache::instance()->clearAllValues();
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole("Cleared all settings!");
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_SettingsFiles)
|
||||
{
|
||||
QStringList cachedFiles(CSettingsCache::instance()->enumerateStore());
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(cachedFiles.join("\n"));
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_CacheDirectory)
|
||||
{
|
||||
QString path(QDir::toNativeSeparators(CDataCache::persistentStore()));
|
||||
if (QDir(path).exists())
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl("file:///" + path));
|
||||
}
|
||||
}
|
||||
else if (sender == this->ui->menu_CacheFiles)
|
||||
{
|
||||
QStringList cachedFiles(CDataCache::instance()->enumerateStore());
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(cachedFiles.join("\n"));
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_CacheReset)
|
||||
{
|
||||
CDataCache::instance()->clearAllValues();
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole("Cleared all cached values!");
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_Internals)
|
||||
else if (sender == this->ui->menu_InternalsPage)
|
||||
{
|
||||
this->ui->sw_MainMiddle->setCurrentIndex(MainPageInternals);
|
||||
}
|
||||
else if (sender == this->ui->menu_InternalsMetatypes)
|
||||
{
|
||||
QString metadata(getAllUserMetatypesTypes());
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(metadata);
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_InternalsSetup)
|
||||
{
|
||||
QString setup(sApp->getGlobalSetup().convertToQString("\n", true));
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(setup);
|
||||
this->displayConsole();
|
||||
}
|
||||
else if (sender == this->ui->menu_InternalsCompileInfo)
|
||||
{
|
||||
QString project(sGui->convertToQString("\n"));
|
||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(project);
|
||||
this->displayConsole();
|
||||
}
|
||||
}
|
||||
|
||||
void SwiftGuiStd::initDynamicMenus()
|
||||
void SwiftGuiStd::initMenus()
|
||||
{
|
||||
Q_ASSERT(this->ui->menu_InfoAreas);
|
||||
Q_ASSERT(this->ui->comp_MainInfoArea);
|
||||
sGui->addMenuFile(*this->ui->menu_File);
|
||||
sGui->addMenuInternals(*this->ui->menu_Internals);
|
||||
sGui->addMenuWindow(*this->ui->menu_Window);
|
||||
this->ui->menu_InfoAreas->addActions(this->ui->comp_MainInfoArea->getInfoAreaSelectActions(this->ui->menu_InfoAreas));
|
||||
}
|
||||
|
||||
void SwiftGuiStd::initMenuIcons()
|
||||
{
|
||||
this->ui->menu_WindowMinimize->setIcon(this->style()->standardIcon(QStyle::SP_TitleBarMinButton));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user