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"
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

View File

@@ -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

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_LINEEDITHISTORY_H
#define BLACKGUI_LINEEDITHISTORY_H
#include "blackgui/blackguiexport.h"
#include <QLineEdit>
#include <QStringList>
@@ -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