aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/coreview
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui/coreview')
-rw-r--r--qtmips_gui/coreview/instructionview.cpp34
-rw-r--r--qtmips_gui/coreview/instructionview.h9
2 files changed, 37 insertions, 6 deletions
diff --git a/qtmips_gui/coreview/instructionview.cpp b/qtmips_gui/coreview/instructionview.cpp
index bab9bc8..0c9ec68 100644
--- a/qtmips_gui/coreview/instructionview.cpp
+++ b/qtmips_gui/coreview/instructionview.cpp
@@ -1,15 +1,39 @@
#include "instructionview.h"
+#include <QPainter>
#include <QFont>
using namespace coreview;
-InstructionView::InstructionView() : QObject(), QGraphicsSimpleTextItem() {
+//////////////////////
+#define WIDTH 120
+#define HEIGHT 14
+#define ROUND 5
+#define GAP 2
+#define PENW 1
+//////////////////////
+
+InstructionView::InstructionView() : QGraphicsObject(nullptr), text(this) {
QFont f;
- f.setPointSize(8);
- setFont(f);
- instruction_update(machine::Instruction());
+ f.setPointSize(6);
+ text.setFont(f);
+
+ instruction_update(machine::Instruction()); // Initialize to NOP
+}
+
+QRectF InstructionView::boundingRect() const {
+ return QRectF(-WIDTH/2 - PENW/2, -PENW/2, WIDTH + PENW, HEIGHT + PENW);
+}
+
+void InstructionView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __attribute__((unused)), QWidget *widget __attribute__((unused))) {
+ painter->setPen(QPen(QColor(240, 240, 240)));
+ painter->setBrush(QBrush(QColor(240, 240, 240)));
+ painter->drawRoundRect(-WIDTH/2, 0, WIDTH, HEIGHT, ROUND, ROUND);
}
void InstructionView::instruction_update(const machine::Instruction &i) {
- setText(i.to_str());
+ QRectF prev_box = boundingRect();
+ text.setText(i.to_str());
+ QRectF box = text.boundingRect();
+ text.setPos(-box.width()/2, GAP);
+ update(prev_box.united(boundingRect()));
}
diff --git a/qtmips_gui/coreview/instructionview.h b/qtmips_gui/coreview/instructionview.h
index 4b7d171..2b0e340 100644
--- a/qtmips_gui/coreview/instructionview.h
+++ b/qtmips_gui/coreview/instructionview.h
@@ -1,18 +1,25 @@
#ifndef INSTRUCTIONVIEW_H
#define INSTRUCTIONVIEW_H
+#include <QGraphicsObject>
#include <QGraphicsSimpleTextItem>
#include "qtmipsmachine.h"
namespace coreview {
-class InstructionView : public QObject, public QGraphicsSimpleTextItem {
+class InstructionView : public QGraphicsObject {
Q_OBJECT
public:
InstructionView();
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
public slots:
void instruction_update(const machine::Instruction &i);
+
+private:
+ QGraphicsSimpleTextItem text;
};
}