mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-04 16:22:52 +08:00
New GUI based on Qt style sheets. This is the main window.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "blackcore/context_network.h"
|
||||
#include "blackcore/coreruntime.h"
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QSizeGrip>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using namespace BlackCore;
|
||||
using namespace BlackMisc;
|
||||
@@ -14,10 +16,34 @@ using namespace BlackGui;
|
||||
/*
|
||||
* Init data
|
||||
*/
|
||||
void MainWindow::init(bool withDBus)
|
||||
void MainWindow::init(GuiModes::CoreMode coreMode)
|
||||
{
|
||||
if (this->m_init) return;
|
||||
this->m_withDBus = withDBus;
|
||||
this->m_coreMode = coreMode;
|
||||
|
||||
// with frameless window, we shift menu and statusbar into central widget
|
||||
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
|
||||
if (this->m_windowMode == GuiModes::WindowFrameless)
|
||||
{
|
||||
|
||||
this->ui->wi_CentralWidgetOutside->setStyleSheet("#wi_CentralWidgetOutside {border: 2px solid green; border-radius: 20px; }");
|
||||
this->ui->vl_CentralWidgetOutside->setContentsMargins(8, 8, 8, 8);
|
||||
|
||||
QHBoxLayout *menuBarLayout = new QHBoxLayout();
|
||||
QPushButton *closeIcon = new QPushButton(this);
|
||||
closeIcon->setStyleSheet("margin: 0; padding: 0; background: transparent;");
|
||||
closeIcon->setIcon(QIcon(":/blackgui/icons/close.png"));
|
||||
QObject::connect(closeIcon, SIGNAL(clicked()), this, SLOT(close()));
|
||||
menuBarLayout->addWidget(this->ui->mb_MainMenuBar, 0, Qt::AlignTop | Qt::AlignLeft);
|
||||
menuBarLayout->addWidget(closeIcon, 0, Qt::AlignTop | Qt::AlignRight);
|
||||
this->ui->vl_CentralWidgetOutside->insertLayout(0, menuBarLayout, 0);
|
||||
|
||||
QSizeGrip *grip = new QSizeGrip(this);
|
||||
grip->setStyleSheet("margin-right: 25px; background-color: transparent;");
|
||||
this->ui->sb_MainStatusBar->setParent(this->ui->wi_CentralWidgetOutside);
|
||||
this->ui->vl_CentralWidgetOutside->addWidget(this->ui->sb_MainStatusBar, 0);
|
||||
this->ui->sb_MainStatusBar->addPermanentWidget(grip);
|
||||
}
|
||||
|
||||
// init models, the delete allows to re-init
|
||||
if (this->m_atcListBooked != nullptr) this->m_atcListBooked->deleteLater();
|
||||
@@ -51,6 +77,8 @@ void MainWindow::init(bool withDBus)
|
||||
this->ui->tv_AircraftsInRange->horizontalHeader()->setSortIndicator(this->m_aircraftsInRange->getSortColumn(), this->m_aircraftsInRange->getSortOrder());
|
||||
|
||||
this->ui->tv_SettingsTnServers->setModel(this->m_trafficServerList);
|
||||
this->ui->tv_AircraftsInRange->resizeColumnsToContents();
|
||||
this->ui->tv_AircraftsInRange->resizeRowsToContents();
|
||||
|
||||
if (this->m_timerUpdateAircraftsInRange == nullptr) this->m_timerUpdateAircraftsInRange = new QTimer(this);
|
||||
if (this->m_timerUpdateAtcStationsOnline == nullptr) this->m_timerUpdateAtcStationsOnline = new QTimer(this);
|
||||
@@ -58,7 +86,7 @@ void MainWindow::init(bool withDBus)
|
||||
if (this->m_timerCollectedCockpitUpdates == nullptr) this->m_timerCollectedCockpitUpdates = new QTimer(this);
|
||||
|
||||
// context
|
||||
if (this->m_withDBus)
|
||||
if (this->m_coreMode != GuiModes::CoreInGuiProcess)
|
||||
{
|
||||
this->m_dBusConnection = QDBusConnection::sessionBus();
|
||||
this->m_contextNetwork = new BlackCore::IContextNetwork(BlackCore::CDBusServer::ServiceName, this->m_dBusConnection, this);
|
||||
@@ -75,6 +103,17 @@ void MainWindow::init(bool withDBus)
|
||||
this->m_contextApplication = this->m_coreRuntime->getIContextApplication();
|
||||
}
|
||||
|
||||
// wire GUI signals
|
||||
this->initGuiSignals();
|
||||
|
||||
// images
|
||||
this->m_resPixmapConnectionConnected = QPixmap(":/blackgui/icons/logingreen.png");
|
||||
this->m_resPixmapConnectionDisconnected = QPixmap(":/blackgui/icons/loginred.png");
|
||||
this->m_resPixmapConnectionConnecting = QPixmap(":/blackgui/icons/loginyellow.png");
|
||||
this->m_resPixmapVoiceLow = QPixmap(":/blackgui/icons/audiovolumelow.png");
|
||||
this->m_resPixmapVoiceHigh = QPixmap(":/blackgui/icons/audiovolumehigh.png");
|
||||
this->m_resPixmapVoiceMuted = QPixmap(":/blackgui/icons/audiovolumemuted.png");
|
||||
|
||||
// relay status messages
|
||||
bool connect;
|
||||
connect = this->connect(this->m_contextNetwork, SIGNAL(statusMessage(BlackMisc::CStatusMessage)),
|
||||
@@ -94,38 +133,26 @@ void MainWindow::init(bool withDBus)
|
||||
Q_ASSERT_X(connect, "init", "cannot connect change network status");
|
||||
|
||||
connect = this->connect(this->m_contextNetwork, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)),
|
||||
this, SLOT(textMessageReceived(BlackMisc::Network::CTextMessageList)));
|
||||
this, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList)));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect text message received");
|
||||
|
||||
connect = this->connect(this->m_timerUpdateAircraftsInRange, SIGNAL(timeout()),
|
||||
this, SLOT(updateTimer()));
|
||||
this, SLOT(timerBasedUpdates()));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect timer");
|
||||
|
||||
connect = this->connect(this->m_timerUpdateAtcStationsOnline, SIGNAL(timeout()),
|
||||
this, SLOT(updateTimer()));
|
||||
this, SLOT(timerBasedUpdates()));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect timer");
|
||||
|
||||
connect = this->connect(this->m_timerContextWatchdog, SIGNAL(timeout()),
|
||||
this, SLOT(updateTimer()));
|
||||
this, SLOT(timerBasedUpdates()));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect timer (watchdog)");
|
||||
|
||||
connect = this->connect(this->m_timerCollectedCockpitUpdates, SIGNAL(timeout()),
|
||||
this, SLOT(sendCockpitUpdates()));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect timer (cockpit updates)");
|
||||
|
||||
//
|
||||
// GUI
|
||||
//
|
||||
connect = this->connect(this->ui->tw_AtcStations, SIGNAL(currentChanged(int)),
|
||||
this, SLOT(atcStationTabChanged(int)));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect stations tab changed");
|
||||
|
||||
connect = this->connect(this->ui->sw_MainMiddle, SIGNAL(currentChanged(int)),
|
||||
this, SLOT(middlePanelChanged(int)));
|
||||
Q_ASSERT_X(connect, "init", "cannot connect middle panle changed");
|
||||
Q_UNUSED(connect);
|
||||
|
||||
|
||||
// start timers
|
||||
this->m_timerUpdateAircraftsInRange->start(10 * 1000);
|
||||
this->m_timerUpdateAtcStationsOnline->start(10 * 1000);
|
||||
@@ -143,11 +170,112 @@ void MainWindow::init(bool withDBus)
|
||||
// start screen
|
||||
this->setMainPage(true);
|
||||
|
||||
// init context menus
|
||||
this->initContextMenus();
|
||||
|
||||
// do this as last statement, so it can be used as flag
|
||||
// whether init has been completed
|
||||
this->m_init = true;
|
||||
}
|
||||
|
||||
//
|
||||
// GUI
|
||||
//
|
||||
void MainWindow::initGuiSignals()
|
||||
{
|
||||
bool connected;
|
||||
|
||||
// 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 buttons
|
||||
this->connect(this->ui->sw_MainMiddle, &QStackedWidget::currentChanged, this, &MainWindow::middlePanelChanged);
|
||||
connected = this->connect(this->ui->pb_MainAircrafts, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainAtc, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainCockpit, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainConnect, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainConnect, SIGNAL(released()), this, SLOT(toggleNetworkConnection()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainFlightplan, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainSettings, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainStatus, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainTextMessages, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_MainWeather, SIGNAL(released()), this, SLOT(setMainPage()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this->ui->pb_MainKeypadOpacity050, &QPushButton::clicked, this, &MainWindow::changeWindowOpacity);
|
||||
this->connect(this->ui->pb_MainKeypadOpacity100, &QPushButton::clicked, this, &MainWindow::changeWindowOpacity);
|
||||
|
||||
// Sound buttons
|
||||
this->connect(this->ui->pb_SoundMute, &QPushButton::clicked, this, &MainWindow::audioVolumes);
|
||||
this->connect(this->ui->pb_SoundMaxVolume, &QPushButton::clicked, this, &MainWindow::audioVolumes);
|
||||
connected = this->connect(this->ui->di_CockpitCom1Volume, &QDial::valueChanged, this, &MainWindow::audioVolumes);
|
||||
connected = this->connect(this->ui->di_CockpitCom2Volume, &QDial::valueChanged, this, &MainWindow::audioVolumes);
|
||||
|
||||
// menu
|
||||
this->connect(this->ui->menu_ReloadSettings, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_TestLocationsEDDF, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_TestLocationsEDDM, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_TestLocationsEDNX, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_TestLocationsEDRY, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_FileClose, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
|
||||
// command line
|
||||
this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &MainWindow::commandEntered);
|
||||
|
||||
// cockpit
|
||||
connected = this->connect(this->ui->cb_CockpitTransponderMode, SIGNAL(currentIndexChanged(QString)),
|
||||
this, SLOT(cockpitValuesChanged()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this->ui->ds_CockpitCom1Active, &QDoubleSpinBox::editingFinished, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->ds_CockpitCom2Active, &QDoubleSpinBox::editingFinished, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->ds_CockpitCom1Standby, &QDoubleSpinBox::editingFinished, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->ds_CockpitCom2Standby, &QDoubleSpinBox::editingFinished, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->ds_CockpitTransponder, &QDoubleSpinBox::editingFinished, this, &MainWindow::cockpitValuesChanged);
|
||||
|
||||
this->connect(this->ui->cb_CockpitVoiceRoom1Override, &QCheckBox::clicked, this, &MainWindow::voiceRoomOverride);
|
||||
this->connect(this->ui->cb_CockpitVoiceRoom2Override, &QCheckBox::clicked, this, &MainWindow::voiceRoomOverride);
|
||||
this->connect(this->ui->le_CockpitVoiceRoomCom1, &QLineEdit::returnPressed, this, &MainWindow::voiceRoomOverride);
|
||||
this->connect(this->ui->le_CockpitVoiceRoomCom2, &QLineEdit::returnPressed, this, &MainWindow::voiceRoomOverride);
|
||||
this->connect(this->ui->pb_CockpitToggleCom1, &QPushButton::clicked, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->pb_CockpitToggleCom2, &QPushButton::clicked, this, &MainWindow::cockpitValuesChanged);
|
||||
this->connect(this->ui->pb_CockpitIdent, &QPushButton::clicked, this, &MainWindow::cockpitValuesChanged);
|
||||
|
||||
// voice
|
||||
connected = this->connect(this->ui->cb_VoiceInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int)));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->cb_VoiceOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int)));
|
||||
Q_ASSERT(connected);
|
||||
|
||||
// ATC
|
||||
connected = this->connect(this->ui->le_AtcStationsOnlineMetar, SIGNAL(returnPressed()), this, SLOT(getMetar()));
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this->ui->tw_AtcStations, &QTabWidget::currentChanged, this, &MainWindow::atcStationTabChanged);
|
||||
this->connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &MainWindow::reloadAtcStationsBooked);
|
||||
this->connect(this->ui->tv_AtcStationsOnline, &QTableView::clicked, this, &MainWindow::onlineAtcStationSelected);
|
||||
|
||||
// Settings server
|
||||
this->connect(this->ui->pb_SettingsTnCurrentServer, &QPushButton::released, this, &MainWindow::alterTrafficServer);
|
||||
this->connect(this->ui->pb_SettingsTnRemoveServer, &QPushButton::released, this, &MainWindow::alterTrafficServer);
|
||||
this->connect(this->ui->pb_SettingsTnSaveServer, &QPushButton::released, this, &MainWindow::alterTrafficServer);
|
||||
this->connect(this->ui->tv_SettingsTnServers, &QTableView::clicked, this, &MainWindow::networkServerSelected);
|
||||
|
||||
// Settings
|
||||
this->connect(this->ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &MainWindow::changeWindowOpacity);
|
||||
|
||||
// no warnings in release build
|
||||
Q_UNUSED(connected);
|
||||
}
|
||||
|
||||
/*
|
||||
* Init data when started
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user