refs #288, adjusted main window

* removed redundant parts now own GUI elements / components
* wiring signal / slots as required
This commit is contained in:
Klaus Basan
2014-11-15 02:09:47 +01:00
committed by Roland Winklmeier
parent 9aa10107bd
commit a2be465388
7 changed files with 96 additions and 100 deletions

View File

@@ -19,9 +19,11 @@
#include "blackcore/network.h"
#include "blackmisc/avaircraft.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/notificationsounds.h"
#include <QMouseEvent>
using namespace BlackCore;
using namespace BlackSound;
using namespace BlackMisc;
using namespace BlackGui;
using namespace BlackGui::Components;
@@ -65,11 +67,15 @@ MainWindow::~MainWindow()
/*
* Graceful shutdown
*/
void MainWindow::gracefulShutdown()
void MainWindow::performGracefulShutdown()
{
if (!this->m_init) { return; }
this->m_init = false;
// tell GUI components to shut down
emit requestGracefulShutdown();
// tell context GUI is going down
if (this->getIContextApplication())
{
this->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ApplicationGui, IContextApplication::ApplicationStops);
@@ -107,7 +113,7 @@ void MainWindow::gracefulShutdown()
void MainWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
this->gracefulShutdown();
this->performGracefulShutdown();
// if (this->sender() != this) QMainWindow::closeEvent(event);
QApplication::exit();
}
@@ -143,6 +149,12 @@ void MainWindow::ps_setMainPage(MainWindow::MainPageIndex mainPage)
this->ui->sw_MainMiddle->setCurrentIndex(mainPage);
}
void MainWindow::ps_setMainPageInfoArea(CMainInfoAreaComponent::InfoArea infoArea)
{
this->ps_setMainPageToInfoArea();
this->ui->comp_MainInfoArea->selectArea(infoArea);
}
/*
* Given main page selected?
*/
@@ -151,58 +163,19 @@ bool MainWindow::isMainPageSelected(MainWindow::MainPageIndex mainPage) const
return this->ui->sw_MainMiddle->currentIndex() == static_cast<int>(mainPage);
}
/*
* Connect to Network
*/
void MainWindow::ps_toggleNetworkConnection()
void MainWindow::ps_loginRequested()
{
if (!this->isContextNetworkAvailableCheck()) return;
if (!this->getIContextNetwork()->isConnected())
if (this->ui->sw_MainMiddle->currentIndex() == static_cast<int>(MainPageLogin))
{
// validation of data here is not required, network context does this
// in prephase of login
this->m_ownAircraft.setCallsign(this->ui->comp_MainInfoArea->getSettingsComponent()->getOwnCallsignFromGui());
CAircraftIcao icao = this->m_ownAircraft.getIcaoInfo();
this->ui->comp_MainInfoArea->getSettingsComponent()->setOwnAircraftIcaoDataFromGui(icao);
this->m_ownAircraft.setIcaoInfo(icao);
// set latest aircraft
this->getIContextOwnAircraft()->updateOwnAircraft(this->m_ownAircraft, MainWindow::swiftGuiStandardOriginator());
// flight plan
this->ui->comp_MainInfoArea->getFlightPlanComponent()->prefillWithAircraftData(this->m_ownAircraft);
// Login is based on setting current server
INetwork::LoginMode mode = INetwork::LoginNormal;
if (this->ui->comp_MainInfoArea->getSettingsComponent()->loginStealth())
{
mode = INetwork::LoginStealth;
this->ps_displayStatusMessageInGui(CLogMessage(this).info("login in stealth mode"));
}
else if (this->ui->comp_MainInfoArea->getSettingsComponent()->loginAsObserver())
{
mode = INetwork::LoginAsObserver;
this->ps_displayStatusMessageInGui(CLogMessage(this).info("login in observer mode"));
}
CStatusMessage msg = this->getIContextNetwork()->connectToNetwork(static_cast<uint>(mode));
this->ps_displayStatusMessageInGui(msg);
this->startUpdateTimersWhenConnected();
// already main page, we fake a re-trigger here
emit this->currentMainInfoAreaChanged(this->ui->sw_MainMiddle->currentWidget());
}
else
{
// disconnect from network
this->stopUpdateTimersWhenDisconnected(); // stop update timers, to avoid updates during disconnecting (a short time frame)
if (this->m_contextAudioAvailable) this->getIContextAudio()->leaveAllVoiceRooms();
CStatusMessage msg = this->getIContextNetwork()->disconnectFromNetwork();
this->ps_displayStatusMessageInGui(msg);
this->ps_setMainPage(MainPageLogin);
}
}
void MainWindow::ps_loginRequested()
{
this->ps_setMainPage(MainPageLogin);
}
/*
* Is the network context available?
*/
@@ -400,3 +373,19 @@ void MainWindow::ps_onStyleSheetsChanged()
);
this->setStyleSheet(s);
}
void MainWindow::ps_onCurrentMainWidgetChanged(int currentIndex)
{
emit currentMainInfoAreaChanged(this->ui->sw_MainMiddle->currentWidget());
Q_UNUSED(currentIndex);
}
/*
* Notification
*/
void MainWindow::playNotifcationSound(CNotificationSounds::Notification notification) const
{
if (!this->m_contextAudioAvailable) return;
if (!this->ui->comp_MainInfoArea->getSettingsComponent()->playNotificationSounds()) return;
this->getIContextAudio()->playNotification(static_cast<uint>(notification), true);
}

View File

@@ -7,6 +7,8 @@
* contained in the LICENSE file.
*/
//! \file
#ifndef SAMPLE_MAINWINDOW_H
#define SAMPLE_MAINWINDOW_H
@@ -19,6 +21,7 @@
#include "blackcore/input_manager.h"
#include "blackgui/components/enableforruntime.h"
#include "blackgui/components/infowindowcomponent.h"
#include "blackgui/components/maininfoareacomponent.h"
#include "blackgui/transpondermodeselector.h"
#include "blackgui/models/atcstationlistmodel.h"
#include "blackgui/models/serverlistmodel.h"
@@ -47,6 +50,15 @@ class MainWindow :
Q_OBJECT
public:
//! Main page indexes
//! \remarks keep the values in sync with the real tab indexes
enum MainPageIndex
{
MainPageInfoArea = 0,
MainPageLogin = 1
};
//! Constructor
explicit MainWindow(GuiModes::WindowMode windowMode, QWidget *parent = nullptr);
@@ -56,12 +68,17 @@ public:
//! Init data
void init(const BlackCore::CRuntimeConfig &runtimeConfig);
//! Graceful shutdown
void gracefulShutdown();
//! Log message category
static QString getMessageCategory() { return "swift.gui.component.mainwindow"; }
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);
protected:
//! Close event, e.g. when window is closed
void closeEvent(QCloseEvent *event);
@@ -72,14 +89,6 @@ protected:
//! Mouse press, required for frameless window
void mousePressEvent(QMouseEvent *event);
//! Main page indexes
//! \remarks keep the values in sync with the real tab indexes
enum MainPageIndex
{
MainPageInfoArea = 0,
MainPageLogin = 1
};
private:
QScopedPointer<Ui::MainWindow> ui;
bool m_init = false;
@@ -118,6 +127,9 @@ private:
//! Init dynamic menus
void initDynamicMenus();
//! Graceful shutdown
void performGracefulShutdown();
//! Context network availability check, otherwise status message
bool isContextNetworkAvailableCheck();
@@ -195,13 +207,13 @@ private slots:
//
//! Set \sa MainPageInfoArea
void ps_setMainPage() { this->ps_setMainPage(MainPageInfoArea); }
void ps_setMainPageToInfoArea() { this->ps_setMainPage(MainPageInfoArea); }
//! Set one of the main pages
void ps_setMainPage(MainPageIndex mainPage);
//! Connect to network
void ps_toggleNetworkConnection();
//! Set the main info area
void ps_setMainPageInfoArea(BlackGui::Components::CMainInfoAreaComponent::InfoArea infoArea);
//! Login requested
void ps_loginRequested();
@@ -229,6 +241,10 @@ private slots:
//! Style sheet has been changed
void ps_onStyleSheetsChanged();
//! Main info area current widget changed
void ps_onCurrentMainWidgetChanged(int currentIndex);
};
#pragma pop_macro("interface")

View File

@@ -279,6 +279,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>

View File

@@ -90,11 +90,6 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::ps_handleTimerBasedUpdates);
connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &MainWindow::ps_onChangedSetttings);
// sliders
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedUsersUpdateInterval, this->ui->comp_MainInfoArea->getUserComponent(), &CUserComponent::setUpdateIntervalSeconds);
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAircraftsUpdateInterval, this->ui->comp_MainInfoArea->getAircraftComponent(), &CAircraftComponent::setUpdateIntervalSeconds);
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds);
// log messages
m_logSubscriber.changeSubscription(CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo));
@@ -108,7 +103,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
this->initialDataReads();
// start screen and complete menu
this->ps_setMainPage();
this->ps_setMainPageToInfoArea();
this->initDynamicMenus();
// starting
@@ -137,12 +132,14 @@ void MainWindow::initGuiSignals()
// Remark: With new style, only methods of same signature can be connected
// This is why we still have some "old" SIGNAL/SLOT connections here
// main window
connect(this->ui->sw_MainMiddle, &QStackedWidget::currentChanged, this, &MainWindow::ps_onCurrentMainWidgetChanged);
// main keypad
connect(this->ui->comp_MainKeypadArea, SIGNAL(selectedMainInfoAreaDockWidget(CMainInfoAreaComponent::InfoArea)), this, SLOT(ps_setMainPage()));
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed, this, &MainWindow::ps_toggleNetworkConnection);
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::selectedMainInfoAreaDockWidget, this, &MainWindow::ps_setMainPageInfoArea);
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed, this, &MainWindow::ps_loginRequested);
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity, this , &MainWindow::ps_changeWindowOpacity);
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed, this->ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent);
connect(this->ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::selectedMainInfoAreaDockWidget, this->ui->comp_MainInfoArea, &CMainInfoAreaComponent::selectArea);
connect(this->ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged);
// command line
@@ -166,6 +163,23 @@ void MainWindow::initGuiSignals()
// settings (GUI component), styles
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedWindowsOpacity, this, &MainWindow::ps_changeWindowOpacity);
connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &MainWindow::ps_onStyleSheetsChanged);
// sliders
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedUsersUpdateInterval, this->ui->comp_MainInfoArea->getUserComponent(), &CUserComponent::setUpdateIntervalSeconds);
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAircraftsUpdateInterval, this->ui->comp_MainInfoArea->getAircraftComponent(), &CAircraftComponent::setUpdateIntervalSeconds);
connect(this->ui->comp_MainInfoArea->getSettingsComponent(), &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_MainInfoArea->getAtcStationComponent(), &::CAtcStationComponent::setUpdateIntervalSeconds);
// login
connect(this->ui->comp_Login, &CLoginComponent::loginOrLogoffCancelled, this, &MainWindow::ps_setMainPageToInfoArea);
connect(this->ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, this, &MainWindow::ps_setMainPageToInfoArea);
connect(this->ui->comp_Login, &CLoginComponent::loginOrLogoffSuccessful, this->ui->comp_MainInfoArea->getFlightPlanComponent(), &CFlightPlanComponent::loginDataSet);
connect(this, &MainWindow::currentMainInfoAreaChanged, this->ui->comp_Login, &CLoginComponent::mainInfoAreaChanged);
connect(this->ui->comp_Login, &CLoginComponent::requestNetworkSettings, this->ui->comp_MainInfoArea->getFlightPlanComponent(), [ = ]()
{
this->ps_setMainPageInfoArea(CMainInfoAreaComponent::InfoAreaSettings);
this->ui->comp_MainInfoArea->getSettingsComponent()->setSettingsTab(CSettingsComponent::SettingTabNetwork);
});
}
/*

View File

@@ -48,7 +48,7 @@ void MainWindow::ps_onMenuClicked()
}
else if (sender == this->ui->menu_FileFont)
{
this->ps_setMainPage();
this->ps_setMainPageToInfoArea();
this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui);
}
else if (sender == this->ui->menu_FileClose)

View File

@@ -1,30 +0,0 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "blackmisc/icons.h"
#include "blackgui/models/atcstationlistmodel.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_network.h"
#include "blackcore/context_audio.h"
#include "blacksound/soundgenerator.h"
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackGui;
using namespace BlackSound;
using namespace BlackMisc::Network;
using namespace BlackMisc::Audio;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Settings;
using namespace BlackMisc::Math;
/*
* Notification
*/
void MainWindow::playNotifcationSound(CNotificationSounds::Notification notification) const
{
if (!this->m_contextAudioAvailable) return;
if (!this->ui->comp_MainInfoArea->getSettingsComponent()->playNotificationSounds()) return;
this->getIContextAudio()->playNotification(static_cast<uint>(notification), true);
}