New GUI based on Qt style sheets. This is the main window.

This commit is contained in:
Klaus Basan
2014-01-13 01:09:56 +01:00
parent 60ad43d291
commit b9ad793dd5
11 changed files with 3075 additions and 2066 deletions

View File

@@ -3,6 +3,7 @@
#include "blackgui/atcstationlistmodel.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_network.h"
#include <QMouseEvent>
using namespace BlackCore;
using namespace BlackMisc;
@@ -17,9 +18,11 @@ using namespace BlackMisc::Voice;
/*
* Constructor
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow),
m_init(false), m_withDBus(true),
MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) :
QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint) : Qt::Tool),
ui(new Ui::MainWindow),
m_infoWindow(nullptr),
m_windowMode(windowMode), m_init(false), m_coreMode(GuiModes::CoreExternal),
m_coreAvailable(false), m_contextNetworkAvailable(false), m_contextVoiceAvailable(false),
m_dBusConnection("dummy"), m_coreRuntime(nullptr),
m_atcListOnline(nullptr), m_atcListBooked(nullptr),
@@ -29,8 +32,16 @@ MainWindow::MainWindow(QWidget *parent) :
m_contextSettings(nullptr),
m_ownAircraft(), m_voiceRoomCom1(), m_voiceRoomCom2(),
m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr),
m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr)
m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr),
m_contextMenuAudio(nullptr)
{
if (windowMode == GuiModes::WindowFrameless)
{
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
this->setAttribute(Qt::WA_NoSystemBackground, true);
this->setAttribute(Qt::WA_TranslucentBackground, true);
// this->setAttribute(Qt::WA_PaintOnScreen);
}
ui->setupUi(this);
}
@@ -84,6 +95,39 @@ void MainWindow::gracefulShutdown()
}
}
/*
* Close event, window closes
*/
void MainWindow::closeEvent(QCloseEvent *event)
{
this->gracefulShutdown();
QMainWindow::closeEvent(event);
QApplication::exit();
}
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
// this->ui->fr_PseudoWindowBar->geometry().contains(event->pos())
if (this->m_windowMode == GuiModes::WindowFrameless && event->buttons() & Qt::LeftButton)
{
move(event->globalPos() - this->m_dragPosition);
event->accept();
return;
}
QWidget::mouseMoveEvent(event);
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if (this->m_windowMode == GuiModes::WindowFrameless && event->button() == Qt::LeftButton)
{
this->m_dragPosition = event->globalPos() - this->frameGeometry().topLeft();
event->accept();
return;
}
QWidget::mousePressEvent(event);
}
/*
* Select correct main page
*/
@@ -97,19 +141,35 @@ void MainWindow::setMainPage(bool start)
QObject *sender = QObject::sender();
if (sender == this->ui->pb_MainConnect || sender == this->ui->pb_MainStatus)
this->ui->sw_MainMiddle->setCurrentIndex(0);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageStatus);
else if (sender == this->ui->pb_MainAtc)
this->ui->sw_MainMiddle->setCurrentIndex(1);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageAtc);
else if (sender == this->ui->pb_MainAircrafts)
this->ui->sw_MainMiddle->setCurrentIndex(2);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageAircrafts);
else if (sender == this->ui->pb_MainCockpit)
this->ui->sw_MainMiddle->setCurrentIndex(3);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageCockpit);
else if (sender == this->ui->pb_MainTextMessages)
this->ui->sw_MainMiddle->setCurrentIndex(4);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageTextMessages);
else if (sender == this->ui->pb_MainFlightplan)
this->ui->sw_MainMiddle->setCurrentIndex(5);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageFlightplan);
else if (sender == this->ui->pb_MainSettings)
this->ui->sw_MainMiddle->setCurrentIndex(6);
this->ui->sw_MainMiddle->setCurrentIndex(MainPageSettings);
}
/*
* Set main page
*/
void MainWindow::setMainPage(MainWindow::MainPageIndex mainPage)
{
this->ui->sw_MainMiddle->setCurrentIndex(mainPage);
}
/*
* Given main page selected?
*/
bool MainWindow::isMainPageSelected(MainWindow::MainPageIndex mainPage) const
{
return this->ui->sw_MainMiddle->currentIndex() == static_cast<int>(mainPage);
}
/*
@@ -119,6 +179,8 @@ void MainWindow::toggleNetworkConnection()
{
CStatusMessageList msgs;
if (!this->isContextNetworkAvailableCheck()) return;
this->ui->lbl_StatusNetworkConnectedIcon->setPixmap(this->m_resPixmapConnectionConnecting);
if (!this->m_contextNetwork->isConnected())
{
QString cs = this->ui->le_SettingsAircraftCallsign->text();
@@ -133,8 +195,8 @@ void MainWindow::toggleNetworkConnection()
}
else
{
if (this->m_contextVoiceAvailable) this->m_contextVoice->leaveAllVoiceRooms();
msgs = this->m_contextNetwork->disconnectFromNetwork();
this->m_contextVoice->leaveAllVoiceRooms();
}
if (!msgs.isEmpty()) this->displayStatusMessages(msgs);
}
@@ -180,39 +242,6 @@ void MainWindow::displayStatusMessages(const CStatusMessageList &messages)
}
}
/*
* Menu clicked
*/
void MainWindow::menuClicked()
{
QObject *sender = QObject::sender();
CStatusMessageList msgs;
if (sender == this->ui->menu_TestLocationsEDRY)
{
this->setTestPosition("N 049° 18' 17", "E 008° 27' 05", CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
}
else if (sender == this->ui->menu_TestLocationsEDNX)
{
this->setTestPosition("N 048° 14 22", "E 011° 33 41", CAltitude(486, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_TestLocationsEDDM)
{
this->setTestPosition("N 048° 21 14", "E 011° 47 10", CAltitude(448, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_TestLocationsEDDF)
{
this->setTestPosition("N 50° 2 0", "E 8° 34 14", CAltitude(100, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_ReloadSettings)
{
this->reloadSettings();
msgs.push_back(CStatusMessage::getInfoMessage("Settings reloaded"));
}
if (!msgs.isEmpty()) this->displayStatusMessages(msgs);
}
/*
* Connection terminated
*/
@@ -227,12 +256,12 @@ void MainWindow::connectionTerminated()
void MainWindow::connectionStatusChanged(uint /** from **/, uint to)
{
// CContextNetwork::ConnectionStatus statusFrom = static_cast<CContextNetwork::ConnectionStatus>(from);
CContextNetwork::ConnectionStatus statusTo = static_cast<CContextNetwork::ConnectionStatus>(to);
INetwork::ConnectionStatus statusTo = static_cast<INetwork::ConnectionStatus>(to);
// always
this->updateGuiStatusInformation();
if (statusTo == CContextNetwork::ConnectionStatusConnected)
if (statusTo == INetwork::Connected)
{
QTimer::singleShot(5 * 1000, this, SLOT(reloadAircraftsInRange()));
QTimer::singleShot(5 * 1000, this, SLOT(reloadAtcStationsOnline()));
@@ -242,19 +271,19 @@ void MainWindow::connectionStatusChanged(uint /** from **/, uint to)
/*
* Timer event
*/
void MainWindow::updateTimer()
void MainWindow::timerBasedUpdates()
{
QObject *sender = QObject::sender();
if (sender == this->m_timerUpdateAtcStationsOnline)
{
int t = this->ui->hs_AtcStationsOnline->value() * 1000;
int t = this->ui->hs_SettingsGuiAtcRefreshTime->value() * 1000;
this->m_timerUpdateAtcStationsOnline->start(t);
if (ui->tv_AtcStationsOnline->isVisible())
this->reloadAtcStationsOnline();
}
if (sender == this->m_timerUpdateAircraftsInRange)
{
int t = this->ui->hs_AtcStationsOnline->value() * 1000;
int t = this->ui->hs_SettingsGuiAircraftRefreshTime->value() * 1000;
this->m_timerUpdateAircraftsInRange->start(t);
if (ui->tv_AircraftsInRange->isVisible())
this->reloadAircraftsInRange();
@@ -312,28 +341,78 @@ void MainWindow::updateGuiStatusInformation()
network = this->m_contextNetwork->usingLocalObjects() ? "local" : now;
}
// handle voice, mute
QString voice("unavailable");
if (this->m_contextVoiceAvailable)
{
voice = this->m_contextVoice->usingLocalObjects() ? "local" : now;
this->ui->pb_SoundMute->setEnabled(true);
}
else
{
// voice not available
this->ui->pb_SoundMute->setEnabled(false);
}
// update status fields
this->ui->le_StatusNetworkContext->setText(network);
this->ui->le_StatusVoiceContext->setText(voice);
this->ui->cb_StatusWithDBus->setCheckState(this->m_withDBus ? Qt::Checked : Qt::Unchecked);
this->ui->cb_StatusWithDBus->setCheckState(this->m_coreMode ? Qt::Checked : Qt::Unchecked);
// Connected button
if (this->m_contextNetworkAvailable && this->m_contextNetwork->isConnected())
{
if (this->ui->lbl_StatusNetworkConnectedIcon->toolTip().startsWith("dis", Qt::CaseInsensitive))
this->ui->lbl_StatusNetworkConnectedIcon->setToolTip(now);
this->ui->pb_MainConnect->setText("Disconnect");
this->ui->pb_MainConnect->setStyleSheet("background-color: green");
if (!this->ui->le_StatusNetworkConnected->text().startsWith("2"))
this->ui->le_StatusNetworkConnected->setText(now);
this->ui->lbl_StatusNetworkConnectedIcon->setPixmap(this->m_resPixmapConnectionConnected);
}
else
{
this->ui->lbl_StatusNetworkConnectedIcon->setToolTip("disconnected");
this->ui->pb_MainConnect->setText("Connect");
this->ui->pb_MainConnect->setStyleSheet("background-color: ");
this->ui->le_StatusNetworkConnected->setText("Disconnected");
this->ui->lbl_StatusNetworkConnectedIcon->setPixmap(this->m_resPixmapConnectionDisconnected);
}
}
/*
* Opacity 0-100
*/
void MainWindow::changeWindowOpacity(int opacity)
{
if (opacity < 0)
{
QObject *sender = QObject::sender();
if (sender == this->ui->pb_MainKeypadOpacity050)
opacity = 50;
else if (sender == this->ui->pb_MainKeypadOpacity100)
opacity = 100;
else
return;
}
qreal o = opacity / 100.0;
QWidget::setWindowOpacity(o);
}
/*
* Display the info window
*/
void MainWindow::displayOverlayInfo(const QString &message)
{
if (!this->m_infoWindow)
{
this->m_infoWindow = new CInfoWindow(this);
}
// display window
if (message.isEmpty())
{
this->m_infoWindow->hide();
}
else
{
this->m_infoWindow->setInfoMessage(message);
}
}

View File

@@ -1,10 +1,19 @@
#ifndef BLACKMISC_MAINWINDOW_H
#define BLACKMISC_MAINWINDOW_H
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef SAMPLE_MAINWINDOW_H
#define SAMPLE_MAINWINDOW_H
// clash with struct interface in objbase.h used to happen
#pragma push_macro("interface")
#undef interface
#include <QMainWindow>
#include <QTextEdit>
#include <QItemSelection>
#include <QTimer>
#include "blackgui/atcstationlistmodel.h"
#include "blackgui/serverlistmodel.h"
#include "blackgui/aircraftlistmodel.h"
@@ -15,10 +24,8 @@
#include "blackcore/context_settings_interface.h"
#include "blackcore/context_application_interface.h"
#include "blackcore/coreruntime.h"
#include <QMainWindow>
#include <QTextEdit>
#include <QItemSelection>
#include <QTimer>
#include "infowindow.h"
#include "guimodeenums.h"
namespace Ui
{
@@ -35,9 +42,10 @@ class MainWindow : public QMainWindow
public:
/*!
* \brief Constructor
* \param windowMode
* \param parent
*/
explicit MainWindow(QWidget *parent = nullptr);
explicit MainWindow(GuiModes::WindowMode windowMode, QWidget *parent = nullptr);
/*!
* Destructor
@@ -46,19 +54,54 @@ public:
/*!
* \brief Init data
* \param withDBus
* \param coreMode
*/
void init(bool withDBus);
void init(GuiModes::CoreMode coreMode);
/*!
* \brief Graceful shutdown
*/
void gracefulShutdown();
protected:
/*!
* \brief Close event, e.g. when window is closed
* \param event
*/
void closeEvent(QCloseEvent *event);
/*!
* \brief Mouse moving, required for frameless window
* \param event
*/
void mouseMoveEvent(QMouseEvent *event);
/*!
* \brief Mouse press, required for frameless window
* \param event
*/
void mousePressEvent(QMouseEvent *event);
/*!
* \brief Main page indexes
*/
enum MainPageIndex
{
MainPageStatus = 0,
MainPageAtc = 1,
MainPageAircrafts = 2,
MainPageCockpit = 3,
MainPageTextMessages = 4,
MainPageFlightplan = 5,
MainPageSettings = 6
};
private:
Ui::MainWindow *ui;
CInfoWindow *m_infoWindow;
bool m_init;
bool m_withDBus;
GuiModes::WindowMode m_windowMode;
GuiModes::CoreMode m_coreMode;
bool m_coreAvailable;
bool m_contextNetworkAvailable;
bool m_contextVoiceAvailable;
@@ -75,10 +118,18 @@ private:
BlackMisc::Aviation::CAircraft m_ownAircraft; /*!< own aircraft's state */
BlackMisc::Voice::CVoiceRoom m_voiceRoomCom1;
BlackMisc::Voice::CVoiceRoom m_voiceRoomCom2;
QTimer *m_timerUpdateAtcStationsOnline; /*!< update stations */
QTimer *m_timerUpdateAircraftsInRange; /*!< update aircrafts */
QTimer *m_timerUpdateAtcStationsOnline; /*!< timer for update of stations */
QTimer *m_timerUpdateAircraftsInRange; /*!< timer for update of aircrafts */
QTimer *m_timerCollectedCockpitUpdates; /*!< collect cockpit updates over a short period before sending */
QTimer *m_timerContextWatchdog; /*!< core available? */
QPixmap m_resPixmapConnectionConnected;
QPixmap m_resPixmapConnectionDisconnected;
QPixmap m_resPixmapConnectionConnecting;
QPixmap m_resPixmapVoiceHigh;
QPixmap m_resPixmapVoiceLow;
QPixmap m_resPixmapVoiceMuted;
QPoint m_dragPosition; /*!< position, if moving is handled with frameless window */
QMenu *m_contextMenuAudio; /*! Audio context menu */
/*!
* \brief GUI status update
@@ -102,6 +153,11 @@ private:
*/
void initialDataReads();
/*!
* \brief Init GUI signals
*/
void initGuiSignals();
/*!
* \brief Context network availability check, otherwise status message
* \return
@@ -137,7 +193,7 @@ private:
* \param name
* \return
*/
QWidget *findTextMessageTabByName(const QString &name);
QWidget *findTextMessageTabByName(const QString &name) const;
/*!
* \brief Private channel text message
@@ -147,7 +203,8 @@ private:
void addPrivateChannelTextMessage(const BlackMisc::Network::CTextMessage &textMessage, bool sending = false);
/*!
* \brief stub for sending a text message (eihter radio or private message)
* Stub for sending a text message (eihter radio or private message).
* Sets sender / receiver depending on frequency / channel situation.
* \return
*/
BlackMisc::Network::CTextMessage getTextMessageStubForChannel();
@@ -171,6 +228,30 @@ private:
*/
void setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude);
/*!
* \brief Display the overlay window
*/
void displayOverlayInfo(const QString &message = "");
/*!
* \brief Is given main page selected?
* \param mainPage
* \return
*/
bool isMainPageSelected(MainPageIndex mainPage) const;
/*!
* \brief For this text message's receiver, is the current tab selected
* \param textMessage
* \return
*/
bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const;
/*!
* \brief Init the context menus
*/
void initContextMenus();
private slots:
//
@@ -218,11 +299,11 @@ private slots:
void connectionStatusChanged(uint from, uint to);
/*!
* \brief Text messages received
* \brief Append text messages (received, to be sent) to GUI
* \param messages
* \param sending
*/
void textMessageReceived(const BlackMisc::Network::CTextMessageList &messages, bool sending = false);
void appendTextMessagesToGui(const BlackMisc::Network::CTextMessageList &messages, bool sending = false);
/*!
* \brief Reload settings
@@ -240,9 +321,16 @@ private slots:
/*!
* \brief Set the main page
* \param start Startup phase
*/
void setMainPage(bool start = false);
/*!
* \brief setMainPage
* \param mainPage
*/
void setMainPage(MainPageIndex mainPage);
/*!
* \brief Connect to network
* \param userId
@@ -285,7 +373,7 @@ private slots:
/*!
* \brief Update timer
*/
void updateTimer();
void timerBasedUpdates();
/*!
* \brief ATC station, tab changed, reload data
@@ -337,10 +425,26 @@ private slots:
void resetTransponderModerToCharly();
/*!
* \brief Override voice room
* \brief Override voice room (allows to set an arbitrary voice room for testing purposes)
*/
void voiceRoomOverride();
/*!
* \brief Audio volume handling and mute
*/
void audioVolumes();
/*!
* \brief changeOpacity
* \param opacity 0-100
*/
void changeWindowOpacity(int opacity = -1);
/*!
* \brief Context menu for audio
*/
void audioIconContextMenu(const QPoint &position);
};
#pragma pop_macro("interface")

File diff suppressed because it is too large Load Diff

View File

@@ -22,6 +22,7 @@ void MainWindow::reloadAircraftsInRange()
if (!this->isContextNetworkAvailableCheck()) return;
this->m_aircraftsInRange->update(this->m_contextNetwork->getAircraftsInRange());
this->ui->tv_AircraftsInRange->resizeColumnsToContents();
this->ui->tv_AircraftsInRange->resizeRowsToContents();
}
/*

View File

@@ -22,6 +22,7 @@ void MainWindow::reloadAtcStationsBooked()
if (!this->isContextNetworkAvailableCheck()) return;
this->m_atcListBooked->update(this->m_contextNetwork->getAtcStationsBooked());
this->ui->tv_AtcStationsBooked->resizeColumnsToContents();
this->ui->tv_AtcStationsBooked->resizeRowsToContents();
}
/*
@@ -32,6 +33,7 @@ void MainWindow::reloadAtcStationsOnline()
if (!this->isContextNetworkAvailableCheck()) return;
this->m_atcListOnline->update(this->m_contextNetwork->getAtcStationsOnline());
this->ui->tv_AtcStationsOnline->resizeColumnsToContents();
this->ui->tv_AtcStationsOnline->resizeRowsToContents();
}
/*

View File

@@ -21,6 +21,29 @@ void MainWindow::cockpitValuesChanged()
{
Q_ASSERT(this->m_timerCollectedCockpitUpdates);
// frequency switch?
QObject *sender = QObject::sender();
if (sender == this->ui->pb_CockpitToggleCom1)
{
if (this->ui->ds_CockpitCom1Standby->value() == this->ui->ds_CockpitCom1Active->value()) return;
double f = this->ui->ds_CockpitCom1Active->value();
this->ui->ds_CockpitCom1Active->setValue(this->ui->ds_CockpitCom1Standby->value());
this->ui->ds_CockpitCom1Standby->setValue(f);
}
else if (sender == this->ui->pb_CockpitToggleCom2)
{
if (this->ui->ds_CockpitCom2Standby->value() == this->ui->ds_CockpitCom2Active->value()) return;
double f = this->ui->ds_CockpitCom2Active->value();
this->ui->ds_CockpitCom2Active->setValue(this->ui->ds_CockpitCom2Standby->value());
this->ui->ds_CockpitCom2Standby->setValue(f);
}
else if (sender == this->ui->pb_CockpitIdent)
{
// trigger the real button
this->ui->cb_CockpitTransponderMode->setCurrentText("I");
return;
}
// this will call send cockpit updates with all changes made
this->m_timerCollectedCockpitUpdates->stop();
this->m_timerCollectedCockpitUpdates->start(1000); // start
@@ -87,7 +110,7 @@ void MainWindow::updateCockpitFromContext()
}
//
// voice
// Voice room override
//
if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked())
{

View File

@@ -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
*/

View File

@@ -0,0 +1,86 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/avaltitude.h"
#include <QPoint>
#include <QMenu>
#include <QDesktopServices>
#include <QProcess>
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
/*
* Menu clicked
*/
void MainWindow::menuClicked()
{
QObject *sender = QObject::sender();
CStatusMessageList msgs;
if (sender == this->ui->menu_TestLocationsEDRY)
{
this->setTestPosition("N 049° 18' 17", "E 008° 27' 05", CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
}
else if (sender == this->ui->menu_TestLocationsEDNX)
{
this->setTestPosition("N 048° 14 22", "E 011° 33 41", CAltitude(486, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_TestLocationsEDDM)
{
this->setTestPosition("N 048° 21 14", "E 011° 47 10", CAltitude(448, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_TestLocationsEDDF)
{
this->setTestPosition("N 50° 2 0", "E 8° 34 14", CAltitude(100, CAltitude::MeanSeaLevel, CLengthUnit::m()));
}
else if (sender == this->ui->menu_ReloadSettings)
{
this->reloadSettings();
msgs.insert(CStatusMessage::getInfoMessage("Settings reloaded"));
}
else if (sender == this->ui->menu_FileClose)
{
msgs.insert(CStatusMessage::getInfoMessage("Closing"));
this->close();
}
if (!msgs.isEmpty()) this->displayStatusMessages(msgs);
}
/*
* Reload settings
*/
void MainWindow::initContextMenus()
{
this->ui->lbl_VoiceStatus->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this->ui->lbl_VoiceStatus, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(audioIconContextMenu(const QPoint &)));
}
/*
* Reload settings
*/
void MainWindow::audioIconContextMenu(const QPoint &position)
{
// for most widgets
QPoint globalPosition = this->ui->lbl_VoiceStatus->mapToGlobal(position);
if (!this->m_contextMenuAudio)
{
this->m_contextMenuAudio = new QMenu(this);
if (QSysInfo::WindowsVersion && QSysInfo::WV_NT_based)
{
this->m_contextMenuAudio->addAction("Mixer");
}
}
QAction *selectedItem = this->m_contextMenuAudio->exec(globalPosition);
if (selectedItem)
{
// http://forum.technical-assistance.co.uk/sndvol32exe-command-line-parameters-vt1348.html
const QList<QAction *> actions = this->m_contextMenuAudio->actions();
QStringList parameterlist;
if (selectedItem == actions.at(0)) QProcess::startDetached("SndVol.exe", parameterlist);
}
}

View File

@@ -24,6 +24,8 @@ void MainWindow::reloadSettings()
// update servers
this->m_trafficServerList->setSelectedServer(nws.getCurrentNetworkServer());
this->m_trafficServerList->update(nws.getTrafficNetworkServers());
this->ui->tv_SettingsTnServers->resizeColumnsToContents();
this->ui->tv_SettingsTnServers->resizeRowsToContents();
}
/*

View File

@@ -11,33 +11,89 @@ using namespace BlackMisc::Geo;
using namespace BlackMisc::Settings;
/*
* Text messages received
* Text messages received or send, append to GUI
*/
void MainWindow::textMessageReceived(const CTextMessageList &messages, bool sending)
void MainWindow::appendTextMessagesToGui(const CTextMessageList &messages, bool sending)
{
if (messages.isEmpty()) return;
foreach(CTextMessage message, messages)
{
bool relevantForMe = false;
QString m = message.asString(true, true, "\t");
this->ui->te_TextMessagesAll->append(m);
m = message.asString(true, false, "\t");
if (message.isSendToUnicom()) this->ui->te_TextMessagesUnicom->append(m);
// check for own COM frequencies
if (message.isRadioMessage())
if (message.isSendToUnicom())
{
if (message.isSendToFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive()))
this->ui->te_TextMessagesCOM1->append(m);
if (message.isSendToFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive()))
this->ui->te_TextMessagesCOM2->append(m);
this->ui->te_TextMessagesUnicom->append(m);
relevantForMe = true;
}
// individual channel text messages
if (message.isPrivateMessage()) this->addPrivateChannelTextMessage(message, sending);
// check message
if (message.isRadioMessage())
{
// check for own COM frequencies
if (message.isSendToFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive()))
{
this->ui->te_TextMessagesCOM1->append(m);
relevantForMe = true;
}
if (message.isSendToFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive()))
{
this->ui->te_TextMessagesCOM2->append(m);
relevantForMe = true;
}
}
else if (message.isPrivateMessage() && !message.isServerMessage())
{
// private message
this->addPrivateChannelTextMessage(message, sending);
relevantForMe = true;
}
// message for me? right frequency? otherwise quit
if (relevantForMe || message.isServerMessage()) this->ui->te_TextMessagesAll->append(m);
if (!relevantForMe) return;
// overlay message if this channel is not selected
if (!sending && !message.isSendToUnicom() && !message.isServerMessage())
{
// if the channel is selected, do nothing
if (!this->isCorrespondingTextMessageTabSelected(message))
this->displayOverlayInfo(m);
}
}
}
/*
* Is the tab of the message's receiver selected?
*/
bool MainWindow::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const
{
if (!this->isMainPageSelected(MainPageTextMessages)) return false;
if (!textMessage.hasValidRecipient()) return false;
if (textMessage.isEmpty()) return false; // ignore empty message
if (textMessage.isPrivateMessage())
{
// private message
CCallsign cs = textMessage.getSenderCallsign();
if (cs.isEmpty()) return false;
QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
if (!tab) return false;
return this->ui->tw_TextMessages->currentWidget() == tab;
}
else
{
// frequency message
if (this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesAll) return true;
if (textMessage.isSendToFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive()))
return this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesCOM1;
if (textMessage.isSendToFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive()))
return this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesCOM2;
return false;
}
}
/*
* Add new text message tab
*/
@@ -47,6 +103,9 @@ QWidget *MainWindow::addNewTextMessageTab(const QString &tabName)
QPushButton *closeButton = new QPushButton("Close", newTab);
QVBoxLayout *layout = new QVBoxLayout(newTab);
QTextEdit *textEdit = new QTextEdit(newTab);
int marginLeft, marginRight, marginTop, marginBottom;
this->ui->tb_TextMessagesAll->layout()->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
newTab->layout()->setContentsMargins(marginLeft, marginTop, marginRight, 2);
textEdit->setReadOnly(true);
textEdit->setWordWrapMode(QTextOption::NoWrap);
layout->addWidget(textEdit);
@@ -64,7 +123,7 @@ QWidget *MainWindow::addNewTextMessageTab(const QString &tabName)
void MainWindow::addPrivateChannelTextMessage(const CTextMessage &textMessage, bool sending)
{
if (!textMessage.isPrivateMessage()) return;
CCallsign cs = sending ? textMessage.getRecipient() : textMessage.getSender();
CCallsign cs = sending ? textMessage.getRecipientCallsign() : textMessage.getSenderCallsign();
if (cs.isEmpty()) return;
QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
if (tab == nullptr) tab = this->findTextMessageTabByName(cs.asString());
@@ -79,7 +138,7 @@ void MainWindow::addPrivateChannelTextMessage(const CTextMessage &textMessage, b
/*
* Message tab by name
*/
QWidget *MainWindow::findTextMessageTabByName(const QString &name)
QWidget *MainWindow::findTextMessageTabByName(const QString &name) const
{
if (name.isEmpty()) return nullptr;
QString n = name.trimmed();
@@ -94,7 +153,7 @@ QWidget *MainWindow::findTextMessageTabByName(const QString &name)
}
/*
* Selected tab text
* Text message stub (sender/receiver) for current channel
*/
CTextMessage MainWindow::getTextMessageStubForChannel()
{
@@ -104,28 +163,24 @@ CTextMessage MainWindow::getTextMessageStubForChannel()
if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesAll)) return tm;
// from
tm.setSender(this->m_ownAircraft.getCallsign());
tm.setSenderCallsign(this->m_ownAircraft.getCallsign());
if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1) ||
index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2) ||
index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesUnicom))
// frequency text message?
if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1))
{
// frequency text message
if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1))
{
tm.setFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive());
}
else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2))
{
tm.setFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive());
}
else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesUnicom))
{
tm.setFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom());
}
tm.setFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive());
}
else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2))
{
tm.setFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive());
}
else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesUnicom))
{
tm.setFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom());
}
else
{
// not a standard channel
QString selectedTabText = this->ui->tw_TextMessages->tabText(index);
bool isNumber;
double frequency = selectedTabText.toDouble(&isNumber);
@@ -138,14 +193,14 @@ CTextMessage MainWindow::getTextMessageStubForChannel()
}
else
{
CCallsign recipient(selectedTabText);
tm.setRecipient(recipient);
CCallsign toCallsign(selectedTabText);
tm.setRecipientCallsign(toCallsign);
}
}
else
{
CCallsign recipient(selectedTabText);
tm.setRecipient(recipient);
CCallsign toCallsign(selectedTabText);
tm.setRecipientCallsign(toCallsign);
}
}
return tm; // now valid message stub with receiver
@@ -176,7 +231,7 @@ void MainWindow::commandEntered()
// TODO: just a first draft of the command line parser
// needs to be refactored, as soon as a first version works
QString cmdLine = this->ui->le_TextMessagesInput->text().simplified();
QString cmdLine = this->ui->le_CommandLineInput->text().simplified();
if (cmdLine.isEmpty()) return;
QList<QString> parts = cmdLine.toLower().split(' ');
if (parts.length() < 1) return;
@@ -193,9 +248,10 @@ void MainWindow::commandEntered()
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, "incorrect message"));
return;
}
QString p = parts[1].trimmed();
QString p = parts[1].trimmed(); // receiver
// select current tab by command
this->setMainPage(MainPageTextMessages);
if (p == "c1" || p == "com1")
{
this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesCOM1);
@@ -215,7 +271,7 @@ void MainWindow::commandEntered()
this->ui->tw_TextMessages->setCurrentWidget(tab);
}
CTextMessage tm = this->getTextMessageStubForChannel();
int index = cmdLine.indexOf(tm.getRecipient().getStringAsSet(), 0, Qt::CaseInsensitive);
int index = cmdLine.indexOf(tm.getRecipientCallsign().getStringAsSet(), 0, Qt::CaseInsensitive);
if (index < 0)
{
this->displayStatusMessage(
@@ -224,14 +280,14 @@ void MainWindow::commandEntered()
);
return;
}
QString msg(cmdLine.mid(index + tm.getRecipient().asString().length() + 1));
QString msg(cmdLine.mid(index + tm.getRecipientCallsign().asString().length() + 1));
tm.setMessage(msg);
if (tm.isEmpty()) return;
if (!this->isContextNetworkAvailableCheck()) return;
CTextMessageList tml(tm);
this->m_contextNetwork->sendTextMessages(tml);
this->textMessageReceived(tml, true);
this->ui->le_TextMessagesInput->setText("");
this->appendTextMessagesToGui(tml, true);
this->ui->le_CommandLineInput->setText("");
}
else if (cmd.startsWith("."))
{
@@ -240,13 +296,19 @@ void MainWindow::commandEntered()
else
{
// single line, no command
// just send
// line is considered to be a message to the selected channel, send
if (!this->m_contextNetwork->isConnected())
{
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "network needs to be connected"));
return;
}
if (!this->isMainPageSelected(MainPageTextMessages))
{
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "text messages can only be sent from corresponding page"));
return;
}
int index = this->ui->tw_TextMessages->currentIndex();
if (index < 0 || index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesAll))
{
@@ -258,10 +320,10 @@ void MainWindow::commandEntered()
tm.setMessage(cmdLine);
if (tm.isEmpty()) return;
if (!this->isContextNetworkAvailableCheck()) return;
CTextMessageList tml(tm);
this->m_contextNetwork->sendTextMessages(tml);
this->textMessageReceived(tml, true);
this->ui->le_TextMessagesInput->setText("");
CTextMessageList textMessageList(tm);
this->m_contextNetwork->sendTextMessages(textMessageList);
this->appendTextMessagesToGui(textMessageList, true);
this->ui->le_CommandLineInput->setText("");
}
}
}

View File

@@ -77,3 +77,71 @@ void MainWindow::audioDeviceSelected(int index)
this->m_contextVoice->setCurrentAudioDevice(selectedDevice);
}
}
/*
* Select audio device
*/
void MainWindow::audioVolumes()
{
if (!this->m_contextVoiceAvailable)
{
this->ui->pb_SoundMute->setEnabled(false);
this->ui->pb_SoundMaxVolume->setEnabled(false);
return;
}
// enable the buttons, as we have a voice context
this->ui->pb_SoundMute->setEnabled(true);
this->ui->pb_SoundMaxVolume->setEnabled(true);
QObject *sender = QObject::sender();
CComSystem com1 = this->m_ownAircraft.getCom1System();
CComSystem com2 = this->m_ownAircraft.getCom2System();
bool muted;
if (sender == this->ui->pb_SoundMute)
{
if (this->m_contextVoice->isMuted())
{
// muted right now, now unmute
muted = false;
}
else
{
// unmuted right now, now mute
muted = true;
}
}
else if (sender == this->ui->pb_SoundMaxVolume)
{
muted = false;
com1.setVolumeOutput(100);
com2.setVolumeOutput(100);
this->ui->di_CockpitCom1Volume->setValue(100);
this->ui->di_CockpitCom2Volume->setValue(100);
}
else if (sender == this->ui->di_CockpitCom1Volume ||
sender == this->ui->di_CockpitCom2Volume)
{
muted = false;
com1.setVolumeOutput(this->ui->di_CockpitCom1Volume->value());
com2.setVolumeOutput(this->ui->di_CockpitCom2Volume->value());
}
else
{
return;
}
// mute / umute
com1.setEnabled(!muted);
com2.setEnabled(!muted);
this->ui->pb_SoundMute->setText(muted ? "Unmute" : "Mute");
this->ui->lbl_VoiceStatus->setPixmap(muted ? this->m_resPixmapVoiceMuted : this->m_resPixmapVoiceHigh);
this->ui->pb_SoundMute->setStyleSheet(muted ? "background-color: red;" : "");
if (muted) this->displayOverlayInfo("Sound is muted!");
// update own aircraft, also set volume/mute in voice
this->m_ownAircraft.setCom1System(com1);
this->m_ownAircraft.setCom1System(com2);
this->m_contextVoice->setVolumes(this->m_ownAircraft.getCom1System(), this->m_ownAircraft.getCom1System());
}