-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQCmdWidget.cpp
More file actions
48 lines (43 loc) · 985 Bytes
/
QCmdWidget.cpp
File metadata and controls
48 lines (43 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "QCmdWidget.h"
#include <QLineEdit>
QCmdWidget::QCmdWidget(QWidget *papi) : QComboBox(papi)
{
}
/**
* @brief QCmdWidget::setHistorial
* Adds historial commands to combo box.
* @param cmds Command list.
*/
void QCmdWidget::setHistorial(const QStringList &cmds)
{
addItems(cmds);
}
/**
* @brief QCmdWidget::getHistorial
* To retrieve all commands typed in command.
* @return List of commands.
*/
QStringList QCmdWidget::getHistorial() const
{
QStringList rtn;
for( int i = 0; i < count(); i++ )
rtn += itemText(1);
return rtn;
}
/**
* @brief QCmdWidget::keyPressEvent
* override parent function to catch enter/return key to
* signal the command typed.
* @param e the key event.
*/
void QCmdWidget::keyPressEvent(QKeyEvent *e)
{
if( ((e->key() == Qt::Key_Return) || (e->key() == Qt::Key_Enter)) && !currentText().isEmpty() )
{
addItem(currentText());
lineEdit()->selectAll();
emit command(currentText());
}
else
QComboBox::keyPressEvent(e);
}