mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-10 19:46:10 +08:00
refs #240, removed text message parts from main GUI window
* text message now encapsulated in component * adjusted main GUI window to be used with component
This commit is contained in:
@@ -171,29 +171,6 @@ private:
|
||||
//! Update the COM frequency displays
|
||||
void updateComFrequencyDisplays(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2);
|
||||
|
||||
/*!
|
||||
* \brief Add new text message tab
|
||||
* \param tabName name of the new tab, usually the channel name
|
||||
* \return
|
||||
*/
|
||||
QWidget *addNewTextMessageTab(const QString &tabName);
|
||||
|
||||
//! Find text message tab by its name
|
||||
QWidget *findTextMessageTabByName(const QString &name) const;
|
||||
|
||||
/*!
|
||||
* \brief Private channel text message
|
||||
* \param textMessage
|
||||
* \param sending sending or receiving
|
||||
*/
|
||||
void addPrivateChannelTextMessage(const BlackMisc::Network::CTextMessage &textMessage, bool sending = false);
|
||||
|
||||
/*!
|
||||
* Stub for sending a text message (eihter radio or private message).
|
||||
* Sets sender / receiver depending on frequency / channel situation.
|
||||
*/
|
||||
BlackMisc::Network::CTextMessage getTextMessageStubForChannel();
|
||||
|
||||
//! Audio device lists
|
||||
void setAudioDeviceLists();
|
||||
|
||||
@@ -208,12 +185,6 @@ private:
|
||||
*/
|
||||
void setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude);
|
||||
|
||||
//! Display the overlay window
|
||||
void displayOverlayInfo(const QString &message = "");
|
||||
|
||||
//! Overlay info displaying status message
|
||||
void displayOverlayInfo(const BlackMisc::CStatusMessage &message);
|
||||
|
||||
/*!
|
||||
* \brief Is given main page selected?
|
||||
* \param mainPage index to be checked
|
||||
@@ -221,9 +192,6 @@ private:
|
||||
*/
|
||||
bool isMainPageSelected(MainPageIndex mainPage) const;
|
||||
|
||||
//! For this text message's recepient, is the current tab selected?
|
||||
bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const;
|
||||
|
||||
//! Start all update timers
|
||||
void startUpdateTimers();
|
||||
|
||||
@@ -243,7 +211,7 @@ private:
|
||||
void audioTestUpdate();
|
||||
|
||||
//! Play notifcation sound
|
||||
void playNotifcationSound(BlackSound::CSoundGenerator::Notification notification) const;
|
||||
void playNotifcationSound(BlackSound::CNotificationSounds::Notification notification) const;
|
||||
|
||||
//! Update simulator page with latest user aircraft data
|
||||
void updateSimulatorData();
|
||||
@@ -276,13 +244,6 @@ private slots:
|
||||
*/
|
||||
void connectionStatusChanged(uint from, uint to, const QString &message);
|
||||
|
||||
/*!
|
||||
* \brief Append text messages (received, to be sent) to GUI
|
||||
* \param messages
|
||||
* \param sending
|
||||
*/
|
||||
void appendTextMessagesToGui(const BlackMisc::Network::CTextMessageList &messages, bool sending = false);
|
||||
|
||||
//! Reload settings
|
||||
void reloadSettings();
|
||||
|
||||
@@ -332,12 +293,6 @@ private slots:
|
||||
//! Update timer
|
||||
void timerBasedUpdates();
|
||||
|
||||
//! Command entered
|
||||
void commandEntered();
|
||||
|
||||
//! Close text message tab
|
||||
void closeTextMessageTab();
|
||||
|
||||
//! Cockpit values changed
|
||||
void cockpitValuesChanged();
|
||||
|
||||
@@ -387,6 +342,14 @@ private slots:
|
||||
//! Toogle Windows stay on top
|
||||
void toogleWindowStayOnTop();
|
||||
|
||||
//! Display the overlay window
|
||||
//! Empty string hides window
|
||||
void displayOverlayInfo(const QString &message = "");
|
||||
|
||||
//! Overlay info displaying status message
|
||||
void displayOverlayInfo(const BlackMisc::CStatusMessage &message);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#pragma pop_macro("interface")
|
||||
|
||||
@@ -461,7 +461,7 @@ QStatusBar QLabel {
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>5</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="pg_StatusPage">
|
||||
<property name="sizePolicy">
|
||||
@@ -571,7 +571,7 @@ QStatusBar QLabel {
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>90</width>
|
||||
<width>86</width>
|
||||
<height>59</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -694,7 +694,7 @@ QStatusBar QLabel {
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::CAtcStationComponent" name="twp_AtcStations">
|
||||
<widget class="BlackGui::CAtcStationComponent" name="comp_AtcStations">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -743,7 +743,7 @@ QStatusBar QLabel {
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::CAircraftComponent" name="twp_Aircrafts"/>
|
||||
<widget class="BlackGui::CAircraftComponent" name="comp_Aircrafts"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -765,7 +765,7 @@ QStatusBar QLabel {
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::CUserComponent" name="twp_Users"/>
|
||||
<widget class="BlackGui::CUserComponent" name="comp_Users"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -1329,150 +1329,10 @@ QStatusBar QLabel {
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tw_TextMessages">
|
||||
<widget class="BlackGui::CTextMessageComponent" name="comp_TextMessages">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tb_TextMessagesAll">
|
||||
<attribute name="title">
|
||||
<string>All</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_TextMessagesAll">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="te_TextMessagesAll">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabStopWidth">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_TextMessagesUnicom">
|
||||
<attribute name="title">
|
||||
<string>UNICOM</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_TextMessagesUnicom">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="te_TextMessagesUnicom">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabStopWidth">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_TextMessagesCOM1">
|
||||
<attribute name="title">
|
||||
<string>COM 1</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_TextMessagesCom1">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="te_TextMessagesCOM1">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabStopWidth">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_TextMessagesCOM2">
|
||||
<attribute name="title">
|
||||
<string>COM 2</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_TextMessagesCom2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="te_TextMessagesCOM2">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabStopWidth">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -1519,7 +1379,7 @@ QStatusBar QLabel {
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tw_Settings">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tb_SettingsTrafficNetwork">
|
||||
<attribute name="title">
|
||||
@@ -2944,6 +2804,12 @@ QStatusBar QLabel {
|
||||
<header>blackgui/atcstationcomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::CTextMessageComponent</class>
|
||||
<extends>QTabWidget</extends>
|
||||
<header>blackgui/textmessagecomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>cb_StatusWithDBus</tabstop>
|
||||
@@ -2951,7 +2817,7 @@ QStatusBar QLabel {
|
||||
<tabstop>le_StatusAudioContext</tabstop>
|
||||
<tabstop>tvp_StatusMessages</tabstop>
|
||||
<tabstop>le_CommandLineInput</tabstop>
|
||||
<tabstop>twp_AtcStations</tabstop>
|
||||
<tabstop>comp_AtcStations</tabstop>
|
||||
<tabstop>pb_CockpitToggleCom1</tabstop>
|
||||
<tabstop>ds_CockpitCom1Active</tabstop>
|
||||
<tabstop>ds_CockpitCom1Standby</tabstop>
|
||||
@@ -2971,11 +2837,7 @@ QStatusBar QLabel {
|
||||
<tabstop>cb_CockpitVoiceRoom2Override</tabstop>
|
||||
<tabstop>tvp_CockpitVoiceRoom1</tabstop>
|
||||
<tabstop>tvp_CockpitVoiceRoom2</tabstop>
|
||||
<tabstop>tw_TextMessages</tabstop>
|
||||
<tabstop>te_TextMessagesAll</tabstop>
|
||||
<tabstop>te_TextMessagesUnicom</tabstop>
|
||||
<tabstop>te_TextMessagesCOM1</tabstop>
|
||||
<tabstop>te_TextMessagesCOM2</tabstop>
|
||||
<tabstop>comp_TextMessages</tabstop>
|
||||
<tabstop>tw_Settings</tabstop>
|
||||
<tabstop>tvp_SettingsTnServers</tabstop>
|
||||
<tabstop>le_SettingsTnCsName</tabstop>
|
||||
|
||||
@@ -154,8 +154,8 @@ void MainWindow::updateCockpitFromContext()
|
||||
}
|
||||
|
||||
// update some other GUI elements
|
||||
this->ui->tw_TextMessages->setTabToolTip(this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1), com1.getFrequencyActive().valueRoundedWithUnit(3));
|
||||
this->ui->tw_TextMessages->setTabToolTip(this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2), com2.getFrequencyActive().valueRoundedWithUnit(3));
|
||||
this->ui->comp_TextMessages->setTabToolTip(BlackGui::CTextMessageComponent::TextMessagesCom1, com1.getFrequencyActive().valueRoundedWithUnit(3));
|
||||
this->ui->comp_TextMessages->setTabToolTip(BlackGui::CTextMessageComponent::TextMessagesCom2, com2.getFrequencyActive().valueRoundedWithUnit(3));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blackgui/atcstationlistmodel.h"
|
||||
#include "blackgui/keyboardkeylistmodel.h"
|
||||
#include "blackgui/textmessagecomponent.h"
|
||||
#include "blackmisc/avselcal.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include <QSortFilterProxyModel>
|
||||
@@ -111,7 +112,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::connectionTerminated, this, &MainWindow::connectionTerminated);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &MainWindow::connectionStatusChanged);
|
||||
this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &MainWindow::changedSettings);
|
||||
connect = this->connect(this->getIContextNetwork(), SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList)));
|
||||
connect = this->connect(this->getIContextNetwork(), SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this->ui->comp_TextMessages, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList)));
|
||||
Q_ASSERT(connect);
|
||||
this->connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &MainWindow::simulatorConnectionChanged);
|
||||
this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates);
|
||||
@@ -121,8 +122,8 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
||||
connect = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &MainWindow::audioTestUpdate);
|
||||
|
||||
// sliders
|
||||
this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this->ui->twp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds);
|
||||
this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this->ui->twp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds);
|
||||
this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this->ui->comp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds);
|
||||
this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this->ui->comp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds);
|
||||
|
||||
Q_ASSERT(connect);
|
||||
Q_UNUSED(connect); // suppress GCC warning in release build
|
||||
@@ -220,8 +221,12 @@ void MainWindow::initGuiSignals()
|
||||
this->connect(this->ui->menu_FileSettingsDirectory, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
this->connect(this->ui->menu_FileResetSettings, &QAction::triggered, this, &MainWindow::menuClicked);
|
||||
|
||||
// command line
|
||||
this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &MainWindow::commandEntered);
|
||||
// command line / text messages
|
||||
connected = this->connect(this->ui->le_CommandLineInput, SIGNAL(returnPressed()), this->ui->comp_TextMessages, SLOT(commandEntered()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this->ui->comp_TextMessages, SIGNAL(displayOverlayInfo(BlackMisc::CStatusMessage)), this, SLOT(displayOverlayInfo(BlackMisc::CStatusMessage)));
|
||||
Q_ASSERT(connected);
|
||||
this->ui->comp_TextMessages->setSelcalCallback(std::bind(&MainWindow::getSelcalCode, this));
|
||||
|
||||
// cockpit
|
||||
connected = this->connect(this->ui->cbp_CockpitTransponderMode, SIGNAL(currentIndexChanged(QString)), this, SLOT(cockpitValuesChanged()));
|
||||
@@ -289,12 +294,12 @@ void MainWindow::initialDataReads()
|
||||
if (this->getIContextNetwork()->isConnected())
|
||||
{
|
||||
// connection is already established
|
||||
this->ui->twp_Aircrafts->update();
|
||||
this->ui->twp_AtcStations->update();
|
||||
this->ui->comp_Aircrafts->update();
|
||||
this->ui->comp_AtcStations->update();
|
||||
|
||||
this->updateGuiStatusInformation();
|
||||
this->ui->twp_Users->update();
|
||||
this->ui->twp_Aircrafts->update();
|
||||
this->ui->comp_Users->update();
|
||||
this->ui->comp_Aircrafts->update();
|
||||
}
|
||||
|
||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "initial data read"));
|
||||
@@ -305,9 +310,9 @@ void MainWindow::initialDataReads()
|
||||
*/
|
||||
void MainWindow::startUpdateTimers()
|
||||
{
|
||||
this->ui->twp_Aircrafts->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAtcRefreshTime->value());
|
||||
this->ui->twp_AtcStations->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAircraftRefreshTime->value());
|
||||
this->ui->twp_Users->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiUserRefreshTime->value());
|
||||
this->ui->comp_Aircrafts->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAtcRefreshTime->value());
|
||||
this->ui->comp_AtcStations->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAircraftRefreshTime->value());
|
||||
this->ui->comp_Users->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiUserRefreshTime->value());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -315,9 +320,9 @@ void MainWindow::startUpdateTimers()
|
||||
*/
|
||||
void MainWindow::stopUpdateTimers()
|
||||
{
|
||||
this->ui->twp_AtcStations->stopTimer();
|
||||
this->ui->twp_Aircrafts->stopTimer();
|
||||
this->ui->twp_Users->stopTimer();
|
||||
this->ui->comp_AtcStations->stopTimer();
|
||||
this->ui->comp_Aircrafts->stopTimer();
|
||||
this->ui->comp_Users->stopTimer();
|
||||
}
|
||||
|
||||
void MainWindow::stopAllTimers(bool disconnect)
|
||||
|
||||
@@ -1,352 +0,0 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "blacksound/soundgenerator.h"
|
||||
|
||||
using namespace BlackCore;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Settings;
|
||||
using namespace BlackMisc::Audio;
|
||||
|
||||
/*
|
||||
* Text messages received or send, append to GUI
|
||||
*/
|
||||
void MainWindow::appendTextMessagesToGui(const CTextMessageList &messages, bool sending)
|
||||
{
|
||||
if (messages.isEmpty()) return;
|
||||
foreach(CTextMessage message, messages)
|
||||
{
|
||||
const QString currentSelcal = this->getSelcalCode();
|
||||
if (CSelcal::isValidCode(currentSelcal) && message.isSelcalMessageFor(currentSelcal))
|
||||
{
|
||||
if (this->m_ownAircraft.isActiveFrequencyWithin25kHzChannel(message.getFrequency()))
|
||||
{
|
||||
// this is SELCAL for me
|
||||
if (this->m_contextAudioAvailable)
|
||||
{
|
||||
CAudioDevice dev = this->getIContextAudio()->getCurrentAudioDevices().getOutputDevices()[0];
|
||||
BlackSound::CSoundGenerator::playSelcal(90, CSelcal(currentSelcal), dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->displayOverlayInfo("SELCAL received");
|
||||
}
|
||||
}
|
||||
continue; // not displayed
|
||||
}
|
||||
|
||||
bool relevantForMe = false;
|
||||
QString m = message.asString(true, true, "\t");
|
||||
m = message.asString(true, false, "\t");
|
||||
|
||||
if (message.isSendToUnicom())
|
||||
{
|
||||
this->ui->te_TextMessagesUnicom->append(m);
|
||||
relevantForMe = true;
|
||||
}
|
||||
|
||||
// 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
|
||||
*/
|
||||
QWidget *MainWindow::addNewTextMessageTab(const QString &tabName)
|
||||
{
|
||||
QWidget *newTab = new QWidget(this->ui->tw_TextMessages);
|
||||
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);
|
||||
layout->addWidget(closeButton);
|
||||
newTab->setLayout(layout);
|
||||
int index = this->ui->tw_TextMessages->addTab(newTab, tabName);
|
||||
this->connect(closeButton, SIGNAL(released()), this, SLOT(closeTextMessageTab()));
|
||||
this->ui->tw_TextMessages->setCurrentIndex(index);
|
||||
return newTab;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a private channel text message
|
||||
*/
|
||||
void MainWindow::addPrivateChannelTextMessage(const CTextMessage &textMessage, bool sending)
|
||||
{
|
||||
if (!textMessage.isPrivateMessage()) return;
|
||||
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());
|
||||
if (tab == nullptr) tab = this->addNewTextMessageTab(cs.getStringAsSet());
|
||||
Q_ASSERT(tab != nullptr);
|
||||
QTextEdit *textEdit = tab->findChild<QTextEdit *>();
|
||||
Q_ASSERT(textEdit != nullptr);
|
||||
if (textEdit == nullptr) return; // do not crash, though this situation could not happen
|
||||
textEdit->append(textMessage.asString(true, false, "\t"));
|
||||
|
||||
// sound
|
||||
this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationTextMessage);
|
||||
}
|
||||
|
||||
/*
|
||||
* Message tab by name
|
||||
*/
|
||||
QWidget *MainWindow::findTextMessageTabByName(const QString &name) const
|
||||
{
|
||||
if (name.isEmpty()) return nullptr;
|
||||
QString n = name.trimmed();
|
||||
for (int index = 0; index < this->ui->tw_TextMessages->count(); index++)
|
||||
{
|
||||
QString tabName = this->ui->tw_TextMessages->tabText(index);
|
||||
if (tabName.indexOf(n, 0, Qt::CaseInsensitive) < 0) continue;
|
||||
QWidget *tab = this->ui->tw_TextMessages->widget(index);
|
||||
return tab;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Text message stub (sender/receiver) for current channel
|
||||
*/
|
||||
CTextMessage MainWindow::getTextMessageStubForChannel()
|
||||
{
|
||||
CTextMessage tm;
|
||||
int index = this->ui->tw_TextMessages->currentIndex();
|
||||
if (index < 0) return tm;
|
||||
if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesAll)) return tm;
|
||||
|
||||
// from
|
||||
tm.setSenderCallsign(this->m_ownAircraft.getCallsign());
|
||||
|
||||
// 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());
|
||||
}
|
||||
else
|
||||
{
|
||||
// not a standard channel
|
||||
QString selectedTabText = this->ui->tw_TextMessages->tabText(index);
|
||||
bool isNumber;
|
||||
double frequency = selectedTabText.toDouble(&isNumber);
|
||||
if (isNumber)
|
||||
{
|
||||
CFrequency radioFrequency = CFrequency(frequency, CFrequencyUnit::MHz());
|
||||
if (CComSystem::isValidCivilAviationFrequency(radioFrequency))
|
||||
{
|
||||
tm.setFrequency(radioFrequency);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCallsign toCallsign(selectedTabText);
|
||||
tm.setRecipientCallsign(toCallsign);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CCallsign toCallsign(selectedTabText);
|
||||
tm.setRecipientCallsign(toCallsign);
|
||||
}
|
||||
}
|
||||
return tm; // now valid message stub with receiver
|
||||
}
|
||||
|
||||
/*
|
||||
* Close message tab
|
||||
*/
|
||||
void MainWindow::closeTextMessageTab()
|
||||
{
|
||||
QObject *sender = QObject::sender();
|
||||
QWidget *parentWidget = qobject_cast<QWidget *>(sender->parent());
|
||||
int index = -1;
|
||||
|
||||
while (index < 0 && parentWidget)
|
||||
{
|
||||
index = this->ui->tw_TextMessages->indexOf(parentWidget);
|
||||
parentWidget = parentWidget->parentWidget();
|
||||
}
|
||||
if (index >= 0) this->ui->tw_TextMessages->removeTab(index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Command entered
|
||||
*/
|
||||
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_CommandLineInput->text().simplified();
|
||||
if (cmdLine.isEmpty()) return;
|
||||
QList<QString> parts = cmdLine.toLower().split(' ');
|
||||
if (parts.length() < 1) return;
|
||||
QString cmd = parts[0].startsWith('.') ? parts[0].toLower() : "";
|
||||
if (cmd == ".m" || cmd == ".msg")
|
||||
{
|
||||
if (!this->m_contextNetworkAvailable || !this->getIContextNetwork()->isConnected())
|
||||
{
|
||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "network needs to be connected"));
|
||||
return;
|
||||
}
|
||||
if (parts.length() < 3)
|
||||
{
|
||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, "incorrect message"));
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if (p == "c2" || p == "com2")
|
||||
{
|
||||
this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesCOM2);
|
||||
}
|
||||
else if (p == "u" || p == "unicom" || p == "uni")
|
||||
{
|
||||
this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesUnicom);
|
||||
}
|
||||
else
|
||||
{
|
||||
QWidget *tab = this->findTextMessageTabByName(p.trimmed());
|
||||
if (tab == nullptr) tab = this->addNewTextMessageTab(p.trimmed().toUpper());
|
||||
this->ui->tw_TextMessages->setCurrentWidget(tab);
|
||||
}
|
||||
CTextMessage tm = this->getTextMessageStubForChannel();
|
||||
int index = cmdLine.indexOf(tm.getRecipientCallsign().getStringAsSet(), 0, Qt::CaseInsensitive);
|
||||
if (index < 0)
|
||||
{
|
||||
this->displayStatusMessage(
|
||||
CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError,
|
||||
"incomplete message")
|
||||
);
|
||||
return;
|
||||
}
|
||||
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->getIContextNetwork()->sendTextMessages(tml);
|
||||
this->appendTextMessagesToGui(tml, true);
|
||||
this->ui->le_CommandLineInput->setText("");
|
||||
}
|
||||
else if (cmd.startsWith("."))
|
||||
{
|
||||
// dump CMDs
|
||||
}
|
||||
else
|
||||
{
|
||||
// single line, no command
|
||||
// line is considered to be a message to the selected channel, send
|
||||
if (!this->getIContextNetwork()->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))
|
||||
{
|
||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, "incorrect channel"));
|
||||
}
|
||||
else
|
||||
{
|
||||
CTextMessage tm = this->getTextMessageStubForChannel();
|
||||
tm.setMessage(cmdLine);
|
||||
if (tm.isEmpty()) return;
|
||||
if (!this->isContextNetworkAvailableCheck()) return;
|
||||
CTextMessageList textMessageList(tm);
|
||||
this->getIContextNetwork()->sendTextMessages(textMessageList);
|
||||
this->appendTextMessagesToGui(textMessageList, true);
|
||||
this->ui->le_CommandLineInput->setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user