diff options
author | Karel Kočí <cynerd@email.cz> | 2017-12-15 22:45:28 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-12-15 22:45:28 +0100 |
commit | e6ca4b4568e311b47239bfe83de15ed9e91c57b9 (patch) | |
tree | 3da2f72faf360058bae02c35b0c724233bd64d61 /qtmips_gui/coreview/programcounter.cpp | |
parent | bbea996112eb7ac81ec50d2af08f4bd681d0e50d (diff) | |
download | qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.tar.gz qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.tar.bz2 qtmips-e6ca4b4568e311b47239bfe83de15ed9e91c57b9.zip |
Implement few initial graphic elements
Diffstat (limited to 'qtmips_gui/coreview/programcounter.cpp')
-rw-r--r-- | qtmips_gui/coreview/programcounter.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/qtmips_gui/coreview/programcounter.cpp b/qtmips_gui/coreview/programcounter.cpp new file mode 100644 index 0000000..32c907c --- /dev/null +++ b/qtmips_gui/coreview/programcounter.cpp @@ -0,0 +1,48 @@ +#include "programcounter.h" + +using namespace coreview; + +////////////////////// +#define WIDTH 80 +#define HEIGHT 100 +#define PENW 1 +////////////////////// + +ProgramCounter::ProgramCounter(QtMipsMachine *machine) : QGraphicsObject(nullptr), value(this), name(this) { + value.setText(QString("0x") + QString::number(machine->registers()->read_pc(), 16)); + value.setPos(0, HEIGHT/2 - value.boundingRect().height()/2); + name.setText(QString("PC")); + name.setPos(WIDTH/2 - name.boundingRect().width()/2, 0); + + connect(machine->registers(), SIGNAL(pc_update(std::uint32_t)), this, SLOT(pc_update(std::uint32_t))); + + con_in = new Connector(); + con_out = new Connector(); + setPos(x(), y()); // To set initial connectors positions +} + +QRectF ProgramCounter::boundingRect() const { + return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); +} + +void ProgramCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + painter->drawRect(0, 0, WIDTH, HEIGHT); +} + +void ProgramCounter::setPos(qreal x, qreal y) { + QGraphicsObject::setPos(x, y); + con_in->setPos(x, y + HEIGHT/2); + con_out->setPos(x + WIDTH, y + HEIGHT/2); +} + +const Connector *ProgramCounter::connector_in() const { + return con_in; +} + +const Connector *ProgramCounter::connector_out() const { + return con_out; +} + +void ProgramCounter::pc_update(std::uint32_t val) { + value.setText(QString("0x") + QString::number(val, 16)); +} |