forked from Dman95/SASM
/
debuganycommandwidget.cpp
83 lines (71 loc) · 2.24 KB
/
debuganycommandwidget.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "debuganycommandwidget.h"
DebugAnyCommandWidget::DebugAnyCommandWidget(QWidget *parent) :
QWidget(parent)
{
currentCommandPos = -1;
anyCommandLabel = new QLabel(tr("GDB command:"));
command = new QLineEdit;
performButton = new QPushButton(tr("Perform"));
printCheckBox = new QCheckBox(tr("Print"));
printCheckBox->setChecked(false);
layout = new QHBoxLayout;
layout->addWidget(anyCommandLabel);
layout->addWidget(command);
layout->addWidget(printCheckBox);
layout->addWidget(performButton);
setLayout(layout);
connect(performButton, SIGNAL(clicked()), this, SLOT(processCommand()));
}
void DebugAnyCommandWidget::showPreviousCommand()
{
if (currentCommandPos > 0)
currentCommandPos--;
if (currentCommandPos >= 0 && currentCommandPos < commands.size())
command->setText(commands[currentCommandPos]);
}
void DebugAnyCommandWidget::showNextCommand()
{
if (currentCommandPos < commands.size() - 1)
currentCommandPos++;
if (currentCommandPos >= 0 && currentCommandPos < commands.size())
command->setText(commands[currentCommandPos]);
}
void DebugAnyCommandWidget::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
processCommand();
if (event->key() == Qt::Key_Up)
showPreviousCommand();
if (event->key() == Qt::Key_Down)
showNextCommand();
QWidget::keyPressEvent(event);
}
void DebugAnyCommandWidget::processCommand()
{
if (! command->text().isEmpty()) {
if (commands.isEmpty() || command->text() != commands.last())
commands.append(command->text());
currentCommandPos = commands.size();
emit performCommand(command->text(), printCheckBox->isChecked());
command->clear();
} else {
if (!commands.isEmpty())
emit performCommand(commands.last(), printCheckBox->isChecked());
}
}
void DebugAnyCommandWidget::setFocusOnLineEdit()
{
command->setFocus();
}
int DebugAnyCommandWidget::height()
{
return command->sizeHint().height();
}
DebugAnyCommandWidget::~DebugAnyCommandWidget()
{
delete printCheckBox;
delete anyCommandLabel;
delete command;
delete performButton;
delete layout;
}