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:
Klaus Basan
2018-01-03 02:58:54 +01:00
parent 26b5a6ce28
commit 2270c8c38b
10 changed files with 60 additions and 19 deletions

View File

@@ -38,15 +38,19 @@ namespace BlackGui
{
const QString c(this->getLastEnteredLineFormatted());
if (c.isEmpty()) { return; }
if (c.toLower().contains("help"))
{
this->setCommandTooltip();
return;
}
if (c.startsWith('.'))
{
if (c.toLower().contains("help"))
{
this->setCommandTooltip();
return;
}
emit this->commandEntered(c, this->identifier());
}
else
{
emit this->textEntered(c, this->identifier());
}
}
void CCommandInput::setCommandTooltip()

View File

@@ -45,6 +45,9 @@ namespace BlackGui
//! Command was entered
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:
//! Basic command validation
void validateCommand();

View File

@@ -66,6 +66,7 @@ namespace BlackGui
// command line
ui->lep_CommandLineInput->setIdentifier(m_identifier);
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->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ownAircraftCockpitChanged);

View File

@@ -54,9 +54,12 @@ namespace BlackGui
//! Change opacity 0..30
void changedOpacity(int opacity);
//! Command was entered
//! \copydoc CCommandInput::commandEntered
void commandEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
//! \copydoc CCommandInput::commandEntered
void textEntered(const QString &commandLine, const BlackMisc::CIdentifier &originator);
//! Connect was pressed
void connectPressed();

View File

@@ -68,6 +68,7 @@ namespace BlackGui
ui->le_textMessages->setVisible(false);
ui->tvp_TextMessagesAll->setResizeMode(CTextMessageView::ResizingAuto);
// le_textMessages is the own line edit
bool c = connect(ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::textMessageEntered);
Q_ASSERT_X(c, Q_FUNC_INFO, "Missing connect");
c = connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::onChangedAircraftCockpit);
@@ -204,7 +205,7 @@ namespace BlackGui
// private message
const CCallsign cs = textMessage.getSenderCallsign();
if (cs.isEmpty()) return false;
QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
const QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet());
if (!tab) { return false; }
return ui->tw_TextMessages->currentWidget() == tab;
}
@@ -380,13 +381,13 @@ namespace BlackGui
// is this a command?
if (!cl.startsWith("."))
{
// build a command line
// build a command line -> e.g. ".msg 122.8 fooBar"
cl = this->textMessageToCommand(cl);
}
// relay the command
if (cl.isEmpty()) { return; }
emit commandEntered(cl, componentIdentifier());
emit this->commandEntered(cl, this->componentIdentifier());
}
QString CTextMessageComponent::textMessageToCommand(const QString &enteredLine)
@@ -453,9 +454,9 @@ namespace BlackGui
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; }
// no "dot" command input

View File

@@ -63,7 +63,7 @@ namespace BlackGui
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
//! Command line was entered
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &orignator);
void commandEntered(const QString commandLine, const BlackMisc::CIdentifier &originator);
public slots:
//! Text messages received
@@ -73,7 +73,8 @@ namespace BlackGui
void onTextMessageSent(const BlackMisc::Network::CTextMessage &sentMessage);
//! 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
void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign);

View File

@@ -234,7 +234,7 @@
<widget class="BlackGui::Components::CSettingsTextMessageInlineComponent" name="comp_Settings"/>
</item>
<item>
<widget class="QLineEdit" name="le_textMessages">
<widget class="BlackGui::CLineEditHistory" name="le_textMessages">
<property name="toolTip">
<string>command line (e.g. &quot;.com1&quot;, &quot;.x&quot;, &quot;.msg com1&quot;)</string>
</property>
@@ -259,6 +259,11 @@
<header>blackgui/components/settingstextmessageinlinecomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::CLineEditHistory</class>
<extends>QLineEdit</extends>
<header>blackgui/lineedithistory.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tw_TextMessages</tabstop>

View File

@@ -9,6 +9,7 @@
#include "lineedithistory.h"
#include <QKeyEvent>
#include <QMenu>
namespace BlackGui
{
@@ -20,7 +21,12 @@ namespace BlackGui
QString CLineEditHistory::getLastEnteredLineFormatted() const
{
return getLastEnteredLine().trimmed().simplified();
return this->getLastEnteredLine().trimmed().simplified();
}
void CLineEditHistory::clearHistory()
{
m_history.clear();
}
void CLineEditHistory::keyPressEvent(QKeyEvent *event)
@@ -36,11 +42,11 @@ namespace BlackGui
else if (event->key() == Qt::Key_Down)
{
// 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 > 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)
@@ -49,10 +55,21 @@ namespace BlackGui
{
m_history.push_front(text());
m_position = 0;
clear();
this->clear();
}
}
// default handler for 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

View File

@@ -33,10 +33,16 @@ namespace BlackGui
//! Get the last entered line but simplified and trimmed
QString getLastEnteredLineFormatted() const;
//! Clear the history
void clearHistory();
protected:
//! \copydoc QLineEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event) override;
//! \copydoc QLineEdit::keyPressEvent
virtual void contextMenuEvent(QContextMenuEvent *event) override;
private:
QStringList m_history;
int m_position = 0;

View File

@@ -193,7 +193,7 @@ void SwiftGuiStd::initGuiSignals()
connect(ui->comp_MainKeypadArea, &CMainKeypadAreaComponent::connectPressed, this, &SwiftGuiStd::loginRequested);
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::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_MainKeypadArea, &CMainKeypadAreaComponent::audioPressed, [ = ]
{