Ref T166, command input uses history line edit

* tooltip handling
* emit commandEntered
This commit is contained in:
Klaus Basan
2017-09-28 04:30:33 +02:00
parent 3ca352a2a1
commit 92bb17364a
3 changed files with 44 additions and 15 deletions

View File

@@ -8,8 +8,9 @@
*/ */
#include "blackgui/components/commandinput.h" #include "blackgui/components/commandinput.h"
#include "blackgui/guiapplication.h"
class QWidget; #include "blackcore/context/contextapplication.h"
#include "blackmisc/simplecommandparser.h"
using namespace BlackMisc; using namespace BlackMisc;
@@ -18,20 +19,42 @@ namespace BlackGui
namespace Components namespace Components
{ {
CCommandInput::CCommandInput(QWidget *parent) : CCommandInput::CCommandInput(QWidget *parent) :
QLineEdit(parent), CLineEditHistory(parent),
CIdentifiable(this) 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()); const QString c(this->getLastEnteredLineFormatted());
this->setText(QString()); if (c.isEmpty()) { return; }
if (commandLine.startsWith('.')) 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
} // ns } // ns

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_COMPONENTS_COMMANDINPUT_H #ifndef BLACKGUI_COMPONENTS_COMMANDINPUT_H
#define BLACKGUI_COMPONENTS_COMMANDINPUT_H #define BLACKGUI_COMPONENTS_COMMANDINPUT_H
#include "blackgui/lineedithistory.h"
#include "blackgui/blackguiexport.h" #include "blackgui/blackguiexport.h"
#include "blackmisc/identifiable.h" #include "blackmisc/identifiable.h"
#include "blackmisc/identifier.h" #include "blackmisc/identifier.h"
@@ -26,9 +27,9 @@ namespace BlackGui
{ {
namespace Components namespace Components
{ {
//! Specialized LineEdit for command inputs //! Specialized line edit for command inputs
class BLACKGUI_EXPORT CCommandInput : class BLACKGUI_EXPORT CCommandInput :
public QLineEdit, public BlackGui::CLineEditHistory,
public BlackMisc::CIdentifiable public BlackMisc::CIdentifiable
{ {
Q_OBJECT Q_OBJECT
@@ -38,15 +39,18 @@ namespace BlackGui
CCommandInput(QWidget *parent = nullptr); CCommandInput(QWidget *parent = nullptr);
//! Destructor //! Destructor
~CCommandInput() {} virtual ~CCommandInput() {}
signals: signals:
//! Command was entered //! Command was entered
void commandEntered(const QString &command, const BlackMisc::CIdentifier &originator); void commandEntered(const QString &command, const BlackMisc::CIdentifier &originator);
private slots: private:
//! Basic command validation //! Basic command validation
void ps_validateCommand(); void validateCommand();
//! Command tooltip
void setCommandTooltip();
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_LINEEDITHISTORY_H #ifndef BLACKGUI_LINEEDITHISTORY_H
#define BLACKGUI_LINEEDITHISTORY_H #define BLACKGUI_LINEEDITHISTORY_H
#include "blackgui/blackguiexport.h"
#include <QLineEdit> #include <QLineEdit>
#include <QStringList> #include <QStringList>
@@ -20,7 +21,7 @@ namespace BlackGui
/*! /*!
* Line edit with history * Line edit with history
*/ */
class CLineEditHistory : public QLineEdit class BLACKGUI_EXPORT CLineEditHistory : public QLineEdit
{ {
public: public:
//! Constructors //! Constructors
@@ -41,4 +42,5 @@ namespace BlackGui
int m_position = 0; int m_position = 0;
}; };
} // ns } // ns
#endif // guard #endif // guard