aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/coreview/latch.cpp27
-rw-r--r--qtmips_gui/coreview/latch.h10
2 files changed, 33 insertions, 4 deletions
diff --git a/qtmips_gui/coreview/latch.cpp b/qtmips_gui/coreview/latch.cpp
index 5f2727b..13351a2 100644
--- a/qtmips_gui/coreview/latch.cpp
+++ b/qtmips_gui/coreview/latch.cpp
@@ -7,8 +7,15 @@ using namespace coreview;
#define PENW 1
//////////////////////
-Latch::Latch(machine::QtMipsMachine *machine, qreal height) {
+Latch::Latch(machine::QtMipsMachine *machine, qreal height) : QGraphicsObject(nullptr) {
this->height = height;
+
+ wedge_animation = new QPropertyAnimation(this, "wedge_clr");
+ wedge_animation->setDuration(100);
+ wedge_animation->setStartValue(QColor(0, 0, 0));
+ wedge_animation->setEndValue(QColor(255, 255, 255));
+ wedge_clr = QColor(255, 255, 255);
+
connect(machine, SIGNAL(tick()), this, SLOT(tick()));
}
@@ -21,12 +28,22 @@ void Latch::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __at
// Now tick rectangle
const QPointF tickPolygon[] = {
QPointF(0, 0),
- QPointF(WIDTH/2, WIDTH/2),
- QPointF(WIDTH, 0)
+ QPointF(WIDTH, 0),
+ QPointF(WIDTH/2, WIDTH/2)
};
+ painter->setBrush(QBrush(wedge_color()));
painter->drawPolygon(tickPolygon, sizeof(tickPolygon) / sizeof(QPointF));
}
+QColor Latch::wedge_color() {
+ return wedge_clr;
+}
+
+void Latch::set_wedge_color(QColor &c) {
+ wedge_clr = c;
+ update();
+}
+
void Latch::setPos(qreal x, qreal y) {
QGraphicsObject::setPos(x, y);
for (int i = 0; i < connectors.size(); i++) {
@@ -47,5 +64,7 @@ struct Latch::ConnectorPair Latch::new_connector(qreal cy) {
}
void Latch::tick() {
- // TODO animate
+ wedge_clr = QColor(0, 0, 0);
+ wedge_animation->start();
+ update();
}
diff --git a/qtmips_gui/coreview/latch.h b/qtmips_gui/coreview/latch.h
index ff1ff6e..951f16a 100644
--- a/qtmips_gui/coreview/latch.h
+++ b/qtmips_gui/coreview/latch.h
@@ -3,6 +3,7 @@
#include <QGraphicsObject>
#include <QList>
+#include <QPropertyAnimation>
#include "qtmipsexception.h"
#include "qtmipsmachine.h"
#include "../coreview.h"
@@ -12,18 +13,25 @@ namespace coreview {
class Latch : public QGraphicsObject {
Q_OBJECT
+ Q_PROPERTY(QColor wedge_clr READ wedge_color WRITE set_wedge_color)
public:
Latch(machine::QtMipsMachine *machine, qreal height);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QColor wedge_color();
+ void set_wedge_color(QColor &c);
+
void setPos(qreal x, qreal y);
struct ConnectorPair { Connector *in, *out; };
struct ConnectorPair new_connector(qreal y); // Create new connectors pair that is given y from top of latch
+protected:
+ void updateCurrentValue(const QColor &color);
+
private slots:
void tick();
@@ -32,6 +40,8 @@ private:
QList<ConnectorPair> connectors;
QList<qreal> connectors_off;
+ QPropertyAnimation *wedge_animation;
+ QColor wedge_clr;
};
}