From 2270c8c38bb29c9181b7832cbb2c6d6415aadfde Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 3 Jan 2018 02:58:54 +0100 Subject: [PATCH] Ref T215, fixed text message sending from keypad command line * context menu delete history * signals to relay messages which are not "dot" commands --- src/blackgui/components/commandinput.cpp | 14 +++++++---- src/blackgui/components/commandinput.h | 3 +++ .../components/mainkeypadareacomponent.cpp | 1 + .../components/mainkeypadareacomponent.h | 5 +++- .../components/textmessagecomponent.cpp | 11 ++++---- .../components/textmessagecomponent.h | 5 ++-- .../components/textmessagecomponent.ui | 7 +++++- src/blackgui/lineedithistory.cpp | 25 ++++++++++++++++--- src/blackgui/lineedithistory.h | 6 +++++ src/swiftguistandard/swiftguistdinit.cpp | 2 +- 10 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/blackgui/components/commandinput.cpp b/src/blackgui/components/commandinput.cpp index ee810af2c..59d4b6161 100644 --- a/src/blackgui/components/commandinput.cpp +++ b/src/blackgui/components/commandinput.cpp @@ -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() diff --git a/src/blackgui/components/commandinput.h b/src/blackgui/components/commandinput.h index 8d7807a66..054c13899 100644 --- a/src/blackgui/components/commandinput.h +++ b/src/blackgui/components/commandinput.h @@ -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(); diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index cea7e3d2f..74a6fa31d 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -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); diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index 3db4ec1e3..3a007c798 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -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(); diff --git a/src/blackgui/components/textmessagecomponent.cpp b/src/blackgui/components/textmessagecomponent.cpp index 83887ea1f..56fd1ceef 100644 --- a/src/blackgui/components/textmessagecomponent.cpp +++ b/src/blackgui/components/textmessagecomponent.cpp @@ -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 diff --git a/src/blackgui/components/textmessagecomponent.h b/src/blackgui/components/textmessagecomponent.h index 27a7be995..8b71a1ffd 100644 --- a/src/blackgui/components/textmessagecomponent.h +++ b/src/blackgui/components/textmessagecomponent.h @@ -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); diff --git a/src/blackgui/components/textmessagecomponent.ui b/src/blackgui/components/textmessagecomponent.ui index 90ef4a64f..aa48a05b1 100644 --- a/src/blackgui/components/textmessagecomponent.ui +++ b/src/blackgui/components/textmessagecomponent.ui @@ -234,7 +234,7 @@ - + command line (e.g. ".com1", ".x", ".msg com1") @@ -259,6 +259,11 @@
blackgui/components/settingstextmessageinlinecomponent.h
1 + + BlackGui::CLineEditHistory + QLineEdit +
blackgui/lineedithistory.h
+
tw_TextMessages diff --git a/src/blackgui/lineedithistory.cpp b/src/blackgui/lineedithistory.cpp index 1a725c9cf..2175c58b7 100644 --- a/src/blackgui/lineedithistory.cpp +++ b/src/blackgui/lineedithistory.cpp @@ -9,6 +9,7 @@ #include "lineedithistory.h" #include +#include 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 diff --git a/src/blackgui/lineedithistory.h b/src/blackgui/lineedithistory.h index 99f42cffb..225b42399 100644 --- a/src/blackgui/lineedithistory.h +++ b/src/blackgui/lineedithistory.h @@ -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; diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index d96dc2608..b564cbbaf 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -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, [ = ] {