aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/coreview/logicblock.h
blob: 4c1310c412b767cc5efdf96c771fbf8698d6b353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef LOGICBLOCK_H
#define LOGICBLOCK_H

#include <QGraphicsItem>
#include <QPainter>
#include <QGraphicsSimpleTextItem>
#include <QVector>
#include "connection.h"

namespace coreview {

class LogicBlock : public QGraphicsItem {
public:
    LogicBlock(QString name);
    LogicBlock(QVector<QString> name);
    ~LogicBlock();

    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setPos(qreal x, qreal y);
    void setSize(qreal width, qreal height);

    // This creates new connector
    // Position is determined by x and y in 0 to 1 range and is mapped to real size of this block
    // Using x=y and x=-y coordinates is not supported
    const Connector *new_connector(qreal x, qreal y);

private:
    QVector<QGraphicsSimpleTextItem*> text;
    QRectF box;

    struct Con {
        Connector *con;
        qreal x, y;
        QPointF p;
    };
    QVector<struct Con> connectors;
    QPointF con_pos(qreal x, qreal y);
};

}

#endif // LOGICBLOCK_H