mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 17:55:45 +08:00
Ref T166, command input uses history line edit
* tooltip handling * emit commandEntered
This commit is contained in:
@@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCommandInput::ps_validateCommand()
|
connect(this, &CCommandInput::returnPressed, this, &CCommandInput::validateCommand);
|
||||||
{
|
|
||||||
QString commandLine(this->text().trimmed());
|
// set tooltip: shorty after, and later when application is initialized
|
||||||
this->setText(QString());
|
QTimer::singleShot(5000, this, &CCommandInput::setCommandTooltip);
|
||||||
if (commandLine.startsWith('.'))
|
QTimer::singleShot(30000, this, &CCommandInput::setCommandTooltip);
|
||||||
{
|
|
||||||
emit commandEntered(commandLine, identifier());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCommandInput::validateCommand()
|
||||||
|
{
|
||||||
|
const QString c(this->getLastEnteredLineFormatted());
|
||||||
|
if (c.isEmpty()) { return; }
|
||||||
|
if (c.toLower().contains("help"))
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user