mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
Ref T215, fixed text message sending from keypad command line
* context menu delete history * signals to relay messages which are not "dot" commands
This commit is contained in:
@@ -38,15 +38,19 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
const QString c(this->getLastEnteredLineFormatted());
|
const QString c(this->getLastEnteredLineFormatted());
|
||||||
if (c.isEmpty()) { return; }
|
if (c.isEmpty()) { return; }
|
||||||
if (c.toLower().contains("help"))
|
|
||||||
{
|
|
||||||
this->setCommandTooltip();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (c.startsWith('.'))
|
if (c.startsWith('.'))
|
||||||
{
|
{
|
||||||
|
if (c.toLower().contains("help"))
|
||||||
|
{
|
||||||
|
this->setCommandTooltip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
emit this->commandEntered(c, this->identifier());
|
emit this->commandEntered(c, this->identifier());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit this->textEntered(c, this->identifier());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCommandInput::setCommandTooltip()
|
void CCommandInput::setCommandTooltip()
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ namespace BlackGui
|
|||||||
//! Command was entered
|
//! Command was entered
|
||||||
void commandEntered(const QString &command, const BlackMisc::CIdentifier &originator);
|
void commandEntered(const QString &command, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
|
//! Text entered (which is not a command)
|
||||||
|
void textEntered(const QString &command, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Basic command validation
|
//! Basic command validation
|
||||||
void validateCommand();
|
void validateCommand();
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ namespace BlackGui
|
|||||||
// command line
|
// command line
|
||||||
ui->lep_CommandLineInput->setIdentifier(m_identifier);
|
ui->lep_CommandLineInput->setIdentifier(m_identifier);
|
||||||
connect(ui->lep_CommandLineInput, &CCommandInput::commandEntered, this, &CMainKeypadAreaComponent::commandEntered);
|
connect(ui->lep_CommandLineInput, &CCommandInput::commandEntered, this, &CMainKeypadAreaComponent::commandEntered);
|
||||||
|
connect(ui->lep_CommandLineInput, &CCommandInput::textEntered, this, &CMainKeypadAreaComponent::textEntered);
|
||||||
|
|
||||||
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::connectionStatusChanged);
|
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::connectionStatusChanged);
|
||||||
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ownAircraftCockpitChanged);
|
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ownAircraftCockpitChanged);
|
||||||
|
|||||||
@@ -54,9 +54,12 @@ namespace BlackGui
|
|||||||
//! Change opacity 0..30
|
//! Change opacity 0..30
|
||||||
void changedOpacity(int opacity);
|
void changedOpacity(int opacity);
|
||||||
|
|
||||||
//! Command was entered
|
//! \copydoc CCommandInput::commandEntered
|
||||||
void commandEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
|
void commandEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
|
//! \copydoc CCommandInput::commandEntered
|
||||||
|
void textEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
//! Connect was pressed
|
//! Connect was pressed
|
||||||
void connectPressed();
|
void connectPressed();
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ namespace BlackGui
|
|||||||
ui->le_textMessages->setVisible(false);
|
ui->le_textMessages->setVisible(false);
|
||||||
ui->tvp_TextMessagesAll->setResizeMode(CTextMessageView::ResizingAuto);
|
ui->tvp_TextMessagesAll->setResizeMode(CTextMessageView::ResizingAuto);
|
||||||
|
|
||||||
|
// le_textMessages is the own line edit
|
||||||
bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered);
|
bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
|
||||||
c = connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::onChangedAircraftCockpit);
|
c = connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::onChangedAircraftCockpit);
|
||||||
@@ -204,7 +205,7 @@ namespace BlackGui
|
|||||||
// private message
|
// private message
|
||||||
const CCallsign cs = textMessage.getSenderCallsign();
|
const CCallsign cs = textMessage.getSenderCallsign();
|
||||||
if (cs.isEmpty()) return false;
|
if (cs.isEmpty()) return false;
|
||||||
QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
|
const QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
|
||||||
if (!tab) { return false; }
|
if (!tab) { return false; }
|
||||||
return ui->tw_TextMessages->currentWidget() == tab;
|
return ui->tw_TextMessages->currentWidget() == tab;
|
||||||
}
|
}
|
||||||
@@ -380,13 +381,13 @@ namespace BlackGui
|
|||||||
// is this a command?
|
// is this a command?
|
||||||
if (!cl.startsWith("."))
|
if (!cl.startsWith("."))
|
||||||
{
|
{
|
||||||
// build a command line
|
// build a command line -> e.g. ".msg 122.8 fooBar"
|
||||||
cl = this->textMessageToCommand(cl);
|
cl = this->textMessageToCommand(cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// relay the command
|
// relay the command
|
||||||
if (cl.isEmpty()) { return; }
|
if (cl.isEmpty()) { return; }
|
||||||
emit commandEntered(cl, componentIdentifier());
|
emit this->commandEntered(cl, this->componentIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CTextMessageComponent::textMessageToCommand(const QString &enteredLine)
|
QString CTextMessageComponent::textMessageToCommand(const QString &enteredLine)
|
||||||
@@ -453,9 +454,9 @@ namespace BlackGui
|
|||||||
this->displayTextMessage(sentMessage);
|
this->displayTextMessage(sentMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTextMessageComponent::handleGlobalCommandLine(const QString &commandLine, const CIdentifier &originator)
|
bool CTextMessageComponent::handleGlobalCommandLineText(const QString &commandLine, const CIdentifier &originator)
|
||||||
{
|
{
|
||||||
if (originator == componentIdentifier()) { return false; }
|
if (originator == this->componentIdentifier()) { return false; }
|
||||||
if (commandLine.isEmpty() || commandLine.startsWith(".")) { return false; }
|
if (commandLine.isEmpty() || commandLine.startsWith(".")) { return false; }
|
||||||
|
|
||||||
// no "dot" command input
|
// no "dot" command input
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace BlackGui
|
|||||||
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
|
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
|
||||||
|
|
||||||
//! Command line was entered
|
//! Command line was entered
|
||||||
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &orignator);
|
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Text messages received
|
//! Text messages received
|
||||||
@@ -73,7 +73,8 @@ namespace BlackGui
|
|||||||
void onTextMessageSent(const BlackMisc::Network::CTextMessage &sentMessage);
|
void onTextMessageSent(const BlackMisc::Network::CTextMessage &sentMessage);
|
||||||
|
|
||||||
//! Used to allow direct input from global command line when visible
|
//! Used to allow direct input from global command line when visible
|
||||||
bool handleGlobalCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator);
|
//! \remark takes the messages, turns it into a ".msg" command, and emits it
|
||||||
|
bool handleGlobalCommandLineText(const QString &commandLine, const BlackMisc::CIdentifier &originator);
|
||||||
|
|
||||||
//! Display the tab for given callsign
|
//! Display the tab for given callsign
|
||||||
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign);
|
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
|
|||||||
@@ -234,7 +234,7 @@
|
|||||||
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_Settings"/>
|
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_Settings"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="le_textMessages">
|
<widget class="BlackGui::CLineEditHistory" name="le_textMessages">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>command line (e.g. ".com1", ".x", ".msg com1")</string>
|
<string>command line (e.g. ".com1", ".x", ".msg com1")</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -259,6 +259,11 @@
|
|||||||
<header>blackgui/components/settingstextmessageinlinecomponent.h</header>
|
<header>blackgui/components/settingstextmessageinlinecomponent.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CLineEditHistory</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>blackgui/lineedithistory.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>tw_TextMessages</tabstop>
|
<tabstop>tw_TextMessages</tabstop>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "lineedithistory.h"
|
#include "lineedithistory.h"
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -20,7 +21,12 @@ namespace BlackGui
|
|||||||
|
|
||||||
QString CLineEditHistory::getLastEnteredLineFormatted() const
|
QString CLineEditHistory::getLastEnteredLineFormatted() const
|
||||||
{
|
{
|
||||||
return getLastEnteredLine().trimmed().simplified();
|
return this->getLastEnteredLine().trimmed().simplified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLineEditHistory::clearHistory()
|
||||||
|
{
|
||||||
|
m_history.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLineEditHistory::keyPressEvent(QKeyEvent *event)
|
void CLineEditHistory::keyPressEvent(QKeyEvent *event)
|
||||||
@@ -36,11 +42,11 @@ namespace BlackGui
|
|||||||
else if (event->key() == Qt::Key_Down)
|
else if (event->key() == Qt::Key_Down)
|
||||||
{
|
{
|
||||||
// move forward in history
|
// move forward in history
|
||||||
if (m_position <= 0) { clear(); return; }
|
if (m_position <= 0) { this->clear(); return; }
|
||||||
if (m_position == m_history.size()) { --m_position; } // avoid need of 2xKeyDown at end
|
if (m_position == m_history.size()) { --m_position; } // avoid need of 2xKeyDown at end
|
||||||
if (m_position > 0 && m_history.size() > --m_position)
|
if (m_position > 0 && m_history.size() > --m_position)
|
||||||
{
|
{
|
||||||
setText(m_history.at(m_position));
|
this->setText(m_history.at(m_position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event->key() == Qt::Key_Return)
|
else if (event->key() == Qt::Key_Return)
|
||||||
@@ -49,10 +55,21 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
m_history.push_front(text());
|
m_history.push_front(text());
|
||||||
m_position = 0;
|
m_position = 0;
|
||||||
clear();
|
this->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// default handler for event
|
// default handler for event
|
||||||
QLineEdit::keyPressEvent(event);
|
QLineEdit::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLineEditHistory::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
if (!event) { return; }
|
||||||
|
QMenu *menu = this->createStandardContextMenu();
|
||||||
|
menu->addSeparator();
|
||||||
|
menu->addAction("Clear history");
|
||||||
|
connect(menu->actions().last(), &QAction::triggered, this, &CLineEditHistory::clearHistory);
|
||||||
|
menu->exec(event->globalPos());
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -33,10 +33,16 @@ namespace BlackGui
|
|||||||
//! Get the last entered line but simplified and trimmed
|
//! Get the last entered line but simplified and trimmed
|
||||||
QString getLastEnteredLineFormatted() const;
|
QString getLastEnteredLineFormatted() const;
|
||||||
|
|
||||||
|
//! Clear the history
|
||||||
|
void clearHistory();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \copydoc QLineEdit::keyPressEvent
|
//! \copydoc QLineEdit::keyPressEvent
|
||||||
virtual void keyPressEvent(QKeyEvent *event) override;
|
virtual void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
|
//! \copydoc QLineEdit::keyPressEvent
|
||||||
|
virtual void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_history;
|
QStringList m_history;
|
||||||
int m_position = 0;
|
int m_position = 0;
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ void SwiftGuiStd::initGuiSignals()
|
|||||||
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed, this, &SwiftGuiStd::loginRequested);
|
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed, this, &SwiftGuiStd::loginRequested);
|
||||||
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity, this , &SwiftGuiStd::onChangedWindowOpacity);
|
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::changedOpacity, this , &SwiftGuiStd::onChangedWindowOpacity);
|
||||||
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed, ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent);
|
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::identPressed, ui->comp_MainInfoArea->getCockpitComponent(), &CCockpitComponent::setSelectedTransponderModeStateIdent);
|
||||||
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::commandEntered, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::handleGlobalCommandLine);
|
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::textEntered, ui->comp_MainInfoArea->getTextMessageComponent(), &CTextMessageComponent::handleGlobalCommandLineText);
|
||||||
connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged);
|
connect(ui->comp_MainInfoArea, &CMainInfoAreaComponent::changedInfoAreaStatus, ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::onMainInfoAreaChanged);
|
||||||
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, [ = ]
|
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, [ = ]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user