Allow to disable tooltip by dot command ".tooltip"

This commit is contained in:
Klaus Basan
2019-04-04 00:09:29 +02:00
committed by Mat Sutcliffe
parent d247d40358
commit 6296feac19
3 changed files with 31 additions and 22 deletions

View File

@@ -42,27 +42,30 @@ namespace BlackGui
{ {
if (sGui->getIContextSimulator()) if (sGui->getIContextSimulator())
{ {
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CCommandInput::onSimulatorPluginChanged); connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CCommandInput::onSimulatorPluginChanged, Qt::QueuedConnection);
} }
if (sGui->getIContextNetwork()) 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); connect(this, &CCommandInput::returnPressed, this, &CCommandInput::validateCommand);
} }
void CCommandInput::showToolTip(bool show)
{
m_showToolTip = show;
this->setCommandToolTip();
}
void CCommandInput::validateCommand() void CCommandInput::validateCommand()
{ {
const QString c(this->getLastEnteredLineFormatted()); const QString c(this->getLastEnteredLineFormatted());
if (c.isEmpty()) { return; } if (c.isEmpty()) { return; }
if (c.startsWith('.')) if (c.startsWith('.'))
{ {
if (c.contains("help", Qt::CaseInsensitive)) if (c.contains("help", Qt::CaseInsensitive)) { this->setCommandToolTip(); return; }
{ if (c.contains("tooltip", Qt::CaseInsensitive)) { this->showToolTip(!m_showToolTip); return; }
this->setCommandTooltip();
return;
}
emit this->commandEntered(c, this->identifier()); emit this->commandEntered(c, this->identifier());
} }
else else
@@ -71,13 +74,20 @@ namespace BlackGui
} }
} }
void CCommandInput::setCommandTooltip() void CCommandInput::setCommandToolTip()
{ {
const bool context = (sGui && sGui->getIContextApplication()); const bool context = (sGui && sGui->getIContextApplication());
if (m_showToolTip)
{
this->setToolTip(context ? this->setToolTip(context ?
sGui->getIContextApplication()->dotCommandsHtmlHelp() : sGui->getIContextApplication()->dotCommandsHtmlHelp() :
CSimpleCommandParser::commandsHtmlHelp()); CSimpleCommandParser::commandsHtmlHelp());
} }
else
{
this->setToolTip("");
}
}
void CCommandInput::onSimulatorPluginChanged(const CSimulatorPluginInfo &info) void CCommandInput::onSimulatorPluginChanged(const CSimulatorPluginInfo &info)
{ {

View File

@@ -21,7 +21,6 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
class QWidget;
namespace BlackMisc namespace BlackMisc
{ {
namespace Network { class CServer; } namespace Network { class CServer; }
@@ -33,7 +32,7 @@ namespace BlackGui
{ {
//! Specialized line edit for command inputs //! Specialized line edit for command inputs
class BLACKGUI_EXPORT CCommandInput : class BLACKGUI_EXPORT CCommandInput :
public BlackGui::CLineEditHistory, public CLineEditHistory,
public BlackMisc::CIdentifiable public BlackMisc::CIdentifiable
{ {
Q_OBJECT Q_OBJECT
@@ -42,8 +41,8 @@ namespace BlackGui
//! Constructor //! Constructor
CCommandInput(QWidget *parent = nullptr); CCommandInput(QWidget *parent = nullptr);
//! Destructor //! Show tooltip
virtual ~CCommandInput() {} void showToolTip(bool show);
signals: signals:
//! Command was entered //! Command was entered
@@ -57,7 +56,7 @@ namespace BlackGui
void validateCommand(); void validateCommand();
//! Command tooltip //! Command tooltip
void setCommandTooltip(); void setCommandToolTip();
//! Simulator plugin loaded / unloaded (default info) //! Simulator plugin loaded / unloaded (default info)
void onSimulatorPluginChanged(const BlackMisc::Simulation::CSimulatorPluginInfo &info); void onSimulatorPluginChanged(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
@@ -65,7 +64,8 @@ namespace BlackGui
//! Connected network server has been changed //! Connected network server has been changed
void onConnectedServerChanged(const BlackMisc::Network::CServer &server); 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
} // ns } // ns

View File

@@ -14,7 +14,7 @@
#include <QSet> #include <QSet>
#include <Qt> #include <Qt>
#include <QtGlobal> #include <QtGlobal>
#include <QStringBuilder>
#include <algorithm> #include <algorithm>
using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::PhysicalQuantities;
@@ -168,14 +168,13 @@ namespace BlackMisc
static const QString cmdCol(QString().fill('-', 20)); static const QString cmdCol(QString().fill('-', 20));
static const QString textCol(QString().fill('-', 40)); static const QString textCol(QString().fill('-', 40));
rows += "<tr>" + rowHeader.arg("command", "synopsis", "command", "synopsis") + "</tr>\n"; rows += u"<tr>" % rowHeader.arg("command", "synopsis", "command", "synopsis") % u"</tr>\n" %
rows += "<tr>" + rowHeader.arg(cmdCol, textCol, cmdCol, textCol) + "</tr>\n"; u"<tr>" % rowHeader.arg(cmdCol, textCol, cmdCol, textCol) % u"</tr>\n";
for (int i = 0; i < cmds.size(); i++) for (int i = 0; i < cmds.size(); i++)
{ {
CommandHtmlHelp help = cmds[i]; CommandHtmlHelp help = cmds[i];
rows += "<tr>"; rows += u"<tr>" % row.arg(help.command, help.help);
rows += row.arg(help.command, help.help);
i++; i++;
if (i < cmds.size()) if (i < cmds.size())
{ {