mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-07 18:15:51 +08:00
New GUI based on Qt style sheets. This is the main window.
This commit is contained in:
@@ -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("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user