Skip to content

Commit

Permalink
contextual actions for the codeview
Browse files Browse the repository at this point in the history
  • Loading branch information
poechsel committed Sep 17, 2017
1 parent 47db137 commit 480cfd2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
55 changes: 55 additions & 0 deletions gui/codeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,63 @@ CodeView::CodeView(QWidget *parent):
QListWidget(parent), _machine(0)
{
this->setUniformItemSizes(true);

this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showContextMenu(const QPoint &)));
}
void CodeView::showContextMenu(const QPoint &pos)
{
QMenu contextMenu(tr("Context menu"), this);
QAction action1("Voir l'instruction en cours d'execution", this);
QAction action2("Voir l'instruction suivante", this);
connect(&action1, SIGNAL(triggered()), this, SLOT(setPositionToCurrent()));
connect(&action2, SIGNAL(triggered()), this, SLOT(setPositionToNext()));
contextMenu.addAction(&action1);
if (this->_machine) {
int index = this->currentRow();
if (0 <= index && index < 0x10000) {
uword opcode = this->_machine->memory[index];
int next_index = index + 1;
if ((opcode >> 12) == 0b0011 || (opcode == 0xb001)) {
} else {
contextMenu.addAction(&action2);
}
}
}
contextMenu.exec(mapToGlobal(pos));
}

void CodeView::setPositionToCurrent() {
if (this->_machine) {
this->setCurrentRow(this->_machine->pc);
}
}

void CodeView::setPositionToNext() {
if (this->_machine) {
int index = this->currentRow();
if (0 <= index && index < 0x10000) {
uword opcode = this->_machine->memory[index];
int next_index = index + 1;
if ((opcode >> 12) == 0b1010) {
next_index = (opcode & 0xfff) * 16;
} else if ((opcode >> 12) == 0b1011) {
word second_part = (opcode & 0xfff);
if (second_part == 1) {
next_index = _machine->registers[15];
} else {
next_index = index + second_part;
}
} else if ((opcode >> 12) == 0b0011) {
next_index = index;
}

if (0 <= index && index < 0x10000)
this->setCurrentRow(next_index);
}
}
}

void CodeView::update() {
QStringList code;
Expand Down
4 changes: 4 additions & 0 deletions gui/codeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QListWidget>
#include "../simulateur/structs.h"
#include "../simulateur/debug.h"
#include <QMenu>

class CodeView: public QListWidget
{
Expand All @@ -25,6 +26,9 @@ class CodeView: public QListWidget

public slots:
void updateCode(int row);
void showContextMenu(const QPoint &);
void setPositionToCurrent();
void setPositionToNext();
};

#endif // CODEVIEW_H
4 changes: 0 additions & 4 deletions gui/registersview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ RegistersView::RegistersView(QWidget *parent):
void RegistersView::showContextMenu(const QPoint &pos)
{
QMenu contextMenu(tr("Context menu"), this);

QAction action1("Accèder à cette zone mémoire", this);
connect(&action1, SIGNAL(triggered()), this, SLOT(switchToMemorySelected()));
_selected_row = this->itemAt(pos)->row();
contextMenu.addAction(&action1);



contextMenu.exec(mapToGlobal(pos));
}

Expand Down

0 comments on commit 480cfd2

Please sign in to comment.