From e6ca4b4568e311b47239bfe83de15ed9e91c57b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 15 Dec 2017 22:45:28 +0100 Subject: Implement few initial graphic elements --- qtmips_gui/coreview/multiplexer.cpp | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 qtmips_gui/coreview/multiplexer.cpp (limited to 'qtmips_gui/coreview/multiplexer.cpp') diff --git a/qtmips_gui/coreview/multiplexer.cpp b/qtmips_gui/coreview/multiplexer.cpp new file mode 100644 index 0000000..57fa443 --- /dev/null +++ b/qtmips_gui/coreview/multiplexer.cpp @@ -0,0 +1,79 @@ +#include "multiplexer.h" + +using namespace coreview; + +////////////////////// +#define WIDTH 20 +#define HEIGHT 20 +#define PENW 1 +////////////////////// + +Multiplexer::Multiplexer(unsigned size) { + this->size = size; + seton = 0; + ctlfrom = false; + con_ctl = new Connector(); + con_out = new Connector(); + con_in = new Connector*[size]; + for (unsigned i = 0; i < size; i++) + con_in[i] = new Connector(); + setPos(x(), y()); // Set connectors possitions +} + +Multiplexer::~Multiplexer() { + delete con_ctl; + delete con_out; + for (unsigned i = 0; i < size; i++) + delete con_in[i]; + delete con_in; +} + +QRectF Multiplexer::boundingRect() const { + return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, (HEIGHT * size) + PENW); +} + +void Multiplexer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + // Draw pointing line first so it isn't over the border lines + painter->setPen(QColor(200, 200, 200)); + painter->drawLine(0, (HEIGHT / 2) + (seton * HEIGHT), WIDTH, (HEIGHT * size) / 2); + + painter->setPen(QColor()); + painter->drawLine(0, 0, 0, (HEIGHT * size)); // (|) + painter->drawLine(0, 0, WIDTH, WIDTH); // (\) + painter->drawLine(0, (HEIGHT * size), WIDTH, (HEIGHT * size) - WIDTH); // (/) + painter->drawLine(WIDTH, WIDTH, WIDTH, (HEIGHT * size) - WIDTH); // (|) +} + +void Multiplexer::setPos(qreal x, qreal y) { + QGraphicsItem::setPos(x, y); + if (ctlfrom) + con_ctl->setPos(x + (WIDTH / 2), y + (WIDTH / 2)); + else + con_ctl->setPos(x + (WIDTH / 2), y + (HEIGHT * size) - (WIDTH / 2)); + con_out->setPos(x + WIDTH, y + ((HEIGHT *size) / 2)); + for (unsigned i = 0; i < size; i++) + con_in[i]->setPos(x, y + (HEIGHT / 2) + (i * HEIGHT)); +} + +const Connector *Multiplexer::connector_ctl() const { + return con_ctl; +} + +const Connector *Multiplexer::connector_out() const { + return con_out; +} + +const Connector *Multiplexer::connector_in(unsigned i) const { + SANITY_ASSERT(i < size, "Multiplexer: requested out of range input connector"); + return con_in[i]; +} + +void Multiplexer::set(unsigned i) { + seton = i; + update(boundingRect()); +} + +void Multiplexer::setCtl(bool up) { + ctlfrom = up; + setPos(x(), y()); // Update connectors +} -- cgit v1.2.3