| 1 | /**************************************************************************** |
| 2 | ** SASM - simple IDE for assembler development |
| 3 | ** Copyright (C) 2013 Dmitriy Manushin |
| 4 | ** Contact: site: http://dman95.github.io/SASM/ |
| 5 | ** e-mail: [email protected] |
| 6 | ** |
| 7 | ** This file is part of SASM. |
| 8 | ** |
| 9 | ** SASM is free software: you can redistribute it and/or modify |
| 10 | ** it under the terms of the GNU General Public License as published by |
| 11 | ** the Free Software Foundation, either version 3 of the License, or |
| 12 | ** (at your option) any later version. |
| 13 | ** |
| 14 | ** SASM is distributed in the hope that it will be useful, |
| 15 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | ** GNU General Public License for more details. |
| 18 | ** |
| 19 | ** You should have received a copy of the GNU General Public License |
| 20 | ** along with SASM. If not, see <http://www.gnu.org/licenses/>. |
| 21 | ** |
| 22 | ** Этот файл — часть SASM. |
| 23 | ** |
| 24 | ** SASM - свободная программа: вы можете перераспространять ее и/или |
| 25 | ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде, |
| 26 | ** в каком она была опубликована Фондом свободного программного обеспечения; |
| 27 | ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней |
| 28 | ** версии. |
| 29 | ** |
| 30 | ** SASM распространяется в надежде, что она будет полезной, |
| 31 | ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА |
| 32 | ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной |
| 33 | ** общественной лицензии GNU. |
| 34 | ** |
| 35 | ** Вы должны были получить копию Стандартной общественной лицензии GNU |
| 36 | ** вместе с этой программой. Если это не так, см. |
| 37 | ** <http://www.gnu.org/licenses/>.) |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #include "debuganycommandwidget.h" |
| 42 | |
| 43 | /** |
| 44 | * @file debuganycommandwidget.cpp |
| 45 | * Implements the GDB arbitrary command widget. |
| 46 | */ |
| 47 | |
| 48 | DebugAnyCommandWidget::DebugAnyCommandWidget(QWidget *parent) : |
| 49 | QWidget(parent) |
| 50 | { |
| 51 | currentCommandPos = -1; |
| 52 | |
| 53 | anyCommandLabel = new QLabel(tr("GDB command:")); |
| 54 | command = new QLineEdit; |
| 55 | performButton = new QPushButton(tr("Perform")); |
| 56 | printCheckBox = new QCheckBox(tr("Print")); |
| 57 | printCheckBox->setChecked(false); |
| 58 | |
| 59 | layout = new QHBoxLayout; |
| 60 | layout->addWidget(anyCommandLabel); |
| 61 | layout->addWidget(command); |
| 62 | layout->addWidget(printCheckBox); |
| 63 | layout->addWidget(performButton); |
| 64 | |
| 65 | setLayout(layout); |
| 66 | |
| 67 | connect(performButton, SIGNAL(clicked()), this, SLOT(processCommand())); |
| 68 | } |
| 69 | |
| 70 | void DebugAnyCommandWidget::showPreviousCommand() |
| 71 | { |
| 72 | if (currentCommandPos > 0) |
| 73 | currentCommandPos--; |
| 74 | if (currentCommandPos >= 0 && currentCommandPos < commands.size()) |
| 75 | command->setText(commands[currentCommandPos]); |
| 76 | } |
| 77 | |
| 78 | void DebugAnyCommandWidget::showNextCommand() |
| 79 | { |
| 80 | if (currentCommandPos < commands.size() - 1) |
| 81 | currentCommandPos++; |
| 82 | if (currentCommandPos >= 0 && currentCommandPos < commands.size()) |
| 83 | command->setText(commands[currentCommandPos]); |
| 84 | } |
| 85 | |
| 86 | void DebugAnyCommandWidget::keyPressEvent(QKeyEvent *event) |
| 87 | { |
| 88 | if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) |
| 89 | processCommand(); |
| 90 | if (event->key() == Qt::Key_Up) |
| 91 | showPreviousCommand(); |
| 92 | if (event->key() == Qt::Key_Down) |
| 93 | showNextCommand(); |
| 94 | QWidget::keyPressEvent(event); |
| 95 | } |
| 96 | |
| 97 | void DebugAnyCommandWidget::processCommand() |
| 98 | { |
| 99 | if (! command->text().isEmpty()) { |
| 100 | if (commands.isEmpty() || command->text() != commands.last()) |
| 101 | commands.append(command->text()); |
| 102 | currentCommandPos = commands.size(); |
| 103 | emit performCommand(command->text(), printCheckBox->isChecked()); |
| 104 | command->clear(); |
| 105 | } else { |
| 106 | if (!commands.isEmpty()) |
| 107 | emit performCommand(commands.last(), printCheckBox->isChecked()); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void DebugAnyCommandWidget::setFocusOnLineEdit() |
| 112 | { |
| 113 | command->setFocus(); |
| 114 | } |
| 115 | |
| 116 | int DebugAnyCommandWidget::height() |
| 117 | { |
| 118 | return command->sizeHint().height(); |
| 119 | } |
| 120 | |
| 121 | DebugAnyCommandWidget::~DebugAnyCommandWidget() |
| 122 | { |
| 123 | delete printCheckBox; |
| 124 | delete anyCommandLabel; |
| 125 | delete command; |
| 126 | delete performButton; |
| 127 | delete layout; |
| 128 | } |