From 6296feac19ed6dbd89101462cd0b3f37903601fe Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 4 Apr 2019 00:09:29 +0200 Subject: [PATCH] Allow to disable tooltip by dot command ".tooltip" --- src/blackgui/components/commandinput.cpp | 32 ++++++++++++++++-------- src/blackgui/components/commandinput.h | 12 ++++----- src/blackmisc/simplecommandparser.cpp | 9 +++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/blackgui/components/commandinput.cpp b/src/blackgui/components/commandinput.cpp index a6c4b0f60..ab8642c1a 100644 --- a/src/blackgui/components/commandinput.cpp +++ b/src/blackgui/components/commandinput.cpp @@ -42,27 +42,30 @@ namespace BlackGui { if (sGui->getIContextSimulator()) { - connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CCommandInput::onSimulatorPluginChanged); + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CCommandInput::onSimulatorPluginChanged, Qt::QueuedConnection); } if (sGui->getIContextNetwork()) { - connect(sGui->getIContextNetwork(), &IContextNetwork::connectedServerChanged, this, &CCommandInput::onConnectedServerChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectedServerChanged, this, &CCommandInput::onConnectedServerChanged, Qt::QueuedConnection); } } connect(this, &CCommandInput::returnPressed, this, &CCommandInput::validateCommand); } + void CCommandInput::showToolTip(bool show) + { + m_showToolTip = show; + this->setCommandToolTip(); + } + void CCommandInput::validateCommand() { const QString c(this->getLastEnteredLineFormatted()); if (c.isEmpty()) { return; } if (c.startsWith('.')) { - if (c.contains("help", Qt::CaseInsensitive)) - { - this->setCommandTooltip(); - return; - } + if (c.contains("help", Qt::CaseInsensitive)) { this->setCommandToolTip(); return; } + if (c.contains("tooltip", Qt::CaseInsensitive)) { this->showToolTip(!m_showToolTip); return; } emit this->commandEntered(c, this->identifier()); } else @@ -71,12 +74,19 @@ namespace BlackGui } } - void CCommandInput::setCommandTooltip() + void CCommandInput::setCommandToolTip() { const bool context = (sGui && sGui->getIContextApplication()); - this->setToolTip(context ? - sGui->getIContextApplication()->dotCommandsHtmlHelp() : - CSimpleCommandParser::commandsHtmlHelp()); + if (m_showToolTip) + { + this->setToolTip(context ? + sGui->getIContextApplication()->dotCommandsHtmlHelp() : + CSimpleCommandParser::commandsHtmlHelp()); + } + else + { + this->setToolTip(""); + } } void CCommandInput::onSimulatorPluginChanged(const CSimulatorPluginInfo &info) diff --git a/src/blackgui/components/commandinput.h b/src/blackgui/components/commandinput.h index 0b605dec4..6250a51da 100644 --- a/src/blackgui/components/commandinput.h +++ b/src/blackgui/components/commandinput.h @@ -21,7 +21,6 @@ #include #include -class QWidget; namespace BlackMisc { namespace Network { class CServer; } @@ -33,7 +32,7 @@ namespace BlackGui { //! Specialized line edit for command inputs class BLACKGUI_EXPORT CCommandInput : - public BlackGui::CLineEditHistory, + public CLineEditHistory, public BlackMisc::CIdentifiable { Q_OBJECT @@ -42,8 +41,8 @@ namespace BlackGui //! Constructor CCommandInput(QWidget *parent = nullptr); - //! Destructor - virtual ~CCommandInput() {} + //! Show tooltip + void showToolTip(bool show); signals: //! Command was entered @@ -57,7 +56,7 @@ namespace BlackGui void validateCommand(); //! Command tooltip - void setCommandTooltip(); + void setCommandToolTip(); //! Simulator plugin loaded / unloaded (default info) void onSimulatorPluginChanged(const BlackMisc::Simulation::CSimulatorPluginInfo &info); @@ -65,7 +64,8 @@ namespace BlackGui //! Connected network server has been changed void onConnectedServerChanged(const BlackMisc::Network::CServer &server); - BlackMisc::CDigestSignal m_dsCommandTooltip { this, &CCommandInput::setCommandTooltip, 5000, 2 }; + bool m_showToolTip = true; + BlackMisc::CDigestSignal m_dsCommandTooltip { this, &CCommandInput::setCommandToolTip, 5000, 2 }; }; } // ns } // ns diff --git a/src/blackmisc/simplecommandparser.cpp b/src/blackmisc/simplecommandparser.cpp index 5c2b0825e..cd917ca39 100644 --- a/src/blackmisc/simplecommandparser.cpp +++ b/src/blackmisc/simplecommandparser.cpp @@ -14,7 +14,7 @@ #include #include #include - +#include #include using namespace BlackMisc::PhysicalQuantities; @@ -168,14 +168,13 @@ namespace BlackMisc static const QString cmdCol(QString().fill('-', 20)); static const QString textCol(QString().fill('-', 40)); - rows += "" + rowHeader.arg("command", "synopsis", "command", "synopsis") + "\n"; - rows += "" + rowHeader.arg(cmdCol, textCol, cmdCol, textCol) + "\n"; + rows += u"" % rowHeader.arg("command", "synopsis", "command", "synopsis") % u"\n" % + u"" % rowHeader.arg(cmdCol, textCol, cmdCol, textCol) % u"\n"; for (int i = 0; i < cmds.size(); i++) { CommandHtmlHelp help = cmds[i]; - rows += ""; - rows += row.arg(help.command, help.help); + rows += u"" % row.arg(help.command, help.help); i++; if (i < cmds.size()) {