aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/coreview
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-12-17 13:44:26 +0100
committerKarel Kočí <cynerd@email.cz>2017-12-17 13:44:26 +0100
commit21da0f6723f3887d200917b4720dd22261e4420a (patch)
tree2146344bc1966cd248e21000c922cf0a127b0bde /qtmips_gui/coreview
parent63163510aecfe19d976a9125ff2151698c4efb51 (diff)
downloadqtmips-21da0f6723f3887d200917b4720dd22261e4420a.tar.gz
qtmips-21da0f6723f3887d200917b4720dd22261e4420a.tar.bz2
qtmips-21da0f6723f3887d200917b4720dd22261e4420a.zip
Implement alu for coreview
Diffstat (limited to 'qtmips_gui/coreview')
-rw-r--r--qtmips_gui/coreview/alu.cpp62
-rw-r--r--qtmips_gui/coreview/alu.h37
2 files changed, 99 insertions, 0 deletions
diff --git a/qtmips_gui/coreview/alu.cpp b/qtmips_gui/coreview/alu.cpp
new file mode 100644
index 0000000..76cf8ad
--- /dev/null
+++ b/qtmips_gui/coreview/alu.cpp
@@ -0,0 +1,62 @@
+#include "alu.h"
+
+//////////////////////
+#define WIDTH 40
+#define HEIGHT 120
+#define DENT 10
+#define PENW 1
+//////////////////////
+
+coreview::Alu::Alu() : QGraphicsObject(nullptr), name(this) {
+ name.setText("ALU");
+ name.setPos(3, 25);
+
+ con_in_a = new Connector();
+ con_in_b = new Connector();
+ con_out = new Connector();
+ con_ctl = new Connector();
+
+ setPos(x(), y()); // set connector's position
+}
+
+QRectF coreview::Alu::boundingRect() const {
+ return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW);
+}
+
+void coreview::Alu::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+ const QPointF poly[] = {
+ QPointF(0, 0),
+ QPointF(WIDTH, WIDTH),
+ QPointF(WIDTH, HEIGHT - WIDTH),
+ QPointF(0, HEIGHT),
+ QPointF(0, (HEIGHT/2) + DENT),
+ QPointF(DENT, HEIGHT / 2),
+ QPointF(0, (HEIGHT / 2) - DENT)
+ };
+ painter->drawPolygon(poly, sizeof(poly) / sizeof(QPointF));
+}
+
+void coreview::Alu::setPos(qreal x, qreal y) {
+ QGraphicsObject::setPos(x, y);
+ qreal off = ((HEIGHT/2) - DENT) / 2;
+ con_in_a->setPos(0, off);
+ con_in_b->setPos(0, HEIGHT - off);
+ con_out->setPos(WIDTH, HEIGHT/2);
+ con_ctl->setPos(WIDTH/2, HEIGHT - (WIDTH/2));
+}
+
+const coreview::Connector *coreview::Alu::connector_in_a() const {
+ return con_in_a;
+}
+
+const coreview::Connector *coreview::Alu::connector_in_b() const {
+ return con_in_b;
+}
+
+const coreview::Connector *coreview::Alu::connector_out() const {
+ return con_out;
+}
+
+const coreview::Connector *coreview::Alu::connector_ctl() const {
+ return con_ctl;
+}
diff --git a/qtmips_gui/coreview/alu.h b/qtmips_gui/coreview/alu.h
new file mode 100644
index 0000000..4c9a73b
--- /dev/null
+++ b/qtmips_gui/coreview/alu.h
@@ -0,0 +1,37 @@
+#ifndef COREVIEW_ALU_H
+#define COREVIEW_ALU_H
+
+#include <QGraphicsObject>
+#include <qtmipsmachine.h>
+#include "../coreview.h"
+#include "connection.h"
+
+namespace coreview {
+
+class Alu : public QGraphicsObject {
+public:
+ Alu();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+ void setPos(qreal x, qreal y);
+ const Connector *connector_in_a() const;
+ const Connector *connector_in_b() const;
+ const Connector *connector_out() const;
+ const Connector *connector_ctl() const;
+
+private:
+ QGraphicsSimpleTextItem name;
+ Connector *con_in_a, *con_in_b, *con_out, *con_ctl;
+};
+
+}
+
+#else
+
+namespace coreview {
+ class Alu;
+}
+
+#endif // COREVIEW_ALU_H