mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
refs #412 command input widget
This commit is contained in:
42
src/blackgui/commandinput.cpp
Normal file
42
src/blackgui/commandinput.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "commandinput.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
CCommandInput::CCommandInput(QWidget *parent) :
|
||||||
|
QLineEdit(parent)
|
||||||
|
{
|
||||||
|
connect(this, &CCommandInput::returnPressed, this, &CCommandInput::validateCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCommandInput::validateCommand()
|
||||||
|
{
|
||||||
|
QString commandLine = text();
|
||||||
|
setText(QStringLiteral(""));
|
||||||
|
|
||||||
|
if (commandLine.startsWith('.'))
|
||||||
|
{
|
||||||
|
emit commandEntered(commandLine, commandInputOriginator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CCommandInput::commandInputOriginator()
|
||||||
|
{
|
||||||
|
// string is generated once, the timestamp allows to use multiple
|
||||||
|
// components (as long as they are not generated at the same ms)
|
||||||
|
static const QString o = QStringLiteral("COMMANDINPUT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
52
src/blackgui/commandinput.h
Normal file
52
src/blackgui/commandinput.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKGUI_COMMANDINPUT_H
|
||||||
|
#define BLACKGUI_COMMANDINPUT_H
|
||||||
|
|
||||||
|
#include "blackguiexport.h"
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Specialized LineEdit for command inputs
|
||||||
|
class BLACKGUI_EXPORT CCommandInput : public QLineEdit
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor
|
||||||
|
CCommandInput(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~CCommandInput() {}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
//! Command was entered
|
||||||
|
void commandEntered(const QString &command, const QString &originator);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
//! Basic command validation
|
||||||
|
void validateCommand();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const QString &commandInputOriginator();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CCOMMANDINPUT_H
|
||||||
Reference in New Issue
Block a user