diff --git a/src/blackgui/components/commandinput.cpp b/src/blackgui/components/commandinput.cpp index 3ee5031db..ee810af2c 100644 --- a/src/blackgui/components/commandinput.cpp +++ b/src/blackgui/components/commandinput.cpp @@ -8,8 +8,9 @@ */ #include "blackgui/components/commandinput.h" - -class QWidget; +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextapplication.h" +#include "blackmisc/simplecommandparser.h" using namespace BlackMisc; @@ -18,20 +19,42 @@ namespace BlackGui namespace Components { CCommandInput::CCommandInput(QWidget *parent) : - QLineEdit(parent), + CLineEditHistory(parent), CIdentifiable(this) { - connect(this, &CCommandInput::returnPressed, this, &CCommandInput::ps_validateCommand); + if (this->placeholderText().isEmpty()) + { + this->setPlaceholderText(".dot commands"); + } + + connect(this, &CCommandInput::returnPressed, this, &CCommandInput::validateCommand); + + // set tooltip: shorty after, and later when application is initialized + QTimer::singleShot(5000, this, &CCommandInput::setCommandTooltip); + QTimer::singleShot(30000, this, &CCommandInput::setCommandTooltip); } - void CCommandInput::ps_validateCommand() + void CCommandInput::validateCommand() { - QString commandLine(this->text().trimmed()); - this->setText(QString()); - if (commandLine.startsWith('.')) + const QString c(this->getLastEnteredLineFormatted()); + if (c.isEmpty()) { return; } + if (c.toLower().contains("help")) { - emit commandEntered(commandLine, identifier()); + this->setCommandTooltip(); + return; } + if (c.startsWith('.')) + { + emit this->commandEntered(c, this->identifier()); + } + } + + void CCommandInput::setCommandTooltip() + { + const bool context = (sGui && sGui->getIContextApplication()); + this->setToolTip(context ? + sGui->getIContextApplication()->dotCommandsHtmlHelp() : + CSimpleCommandParser::commandsHtmlHelp()); } } // ns } // ns diff --git a/src/blackgui/components/commandinput.h b/src/blackgui/components/commandinput.h index 4a20d77a0..8d7807a66 100644 --- a/src/blackgui/components/commandinput.h +++ b/src/blackgui/components/commandinput.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_COMPONENTS_COMMANDINPUT_H #define BLACKGUI_COMPONENTS_COMMANDINPUT_H +#include "blackgui/lineedithistory.h" #include "blackgui/blackguiexport.h" #include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" @@ -26,9 +27,9 @@ namespace BlackGui { namespace Components { - //! Specialized LineEdit for command inputs + //! Specialized line edit for command inputs class BLACKGUI_EXPORT CCommandInput : - public QLineEdit, + public BlackGui::CLineEditHistory, public BlackMisc::CIdentifiable { Q_OBJECT @@ -38,15 +39,18 @@ namespace BlackGui CCommandInput(QWidget *parent = nullptr); //! Destructor - ~CCommandInput() {} + virtual ~CCommandInput() {} signals: //! Command was entered void commandEntered(const QString &command, const BlackMisc::CIdentifier &originator); - private slots: + private: //! Basic command validation - void ps_validateCommand(); + void validateCommand(); + + //! Command tooltip + void setCommandTooltip(); }; } // ns } // ns diff --git a/src/blackgui/lineedithistory.h b/src/blackgui/lineedithistory.h index 3ffd37c60..99f42cffb 100644 --- a/src/blackgui/lineedithistory.h +++ b/src/blackgui/lineedithistory.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_LINEEDITHISTORY_H #define BLACKGUI_LINEEDITHISTORY_H +#include "blackgui/blackguiexport.h" #include #include @@ -20,7 +21,7 @@ namespace BlackGui /*! * Line edit with history */ - class CLineEditHistory : public QLineEdit + class BLACKGUI_EXPORT CLineEditHistory : public QLineEdit { public: //! Constructors @@ -41,4 +42,5 @@ namespace BlackGui int m_position = 0; }; } // ns + #endif // guard