#define INCLUDE__BasicBlockWidget_hxx
#include "gui/qt.hxx"
-#include "disassembler/BasicBlock.hxx"
#include <vector>
#include <cassert>
#include <tuple>
+#include <array>
+#include <memory>
+#include <log4cxx/logger.h>
-class BasicBlockWidget : public QGraphicsItem
-{
-public:
- BasicBlockWidget(const QString& name, BasicBlock * block);
-
- void addItem(uint8_t* bytes, size_t num_bytes, const QString& line);
+#include "disassembler/Instruction.hxx"
- QRectF boundingRect() const {
- qreal penWidth = 1;
- QRectF result(- penWidth / 2, - penWidth / 2,
- width + penWidth, height + penWidth);
- return result;
- }
+class Mainwindow;
+class CustomQGraphicsTextItem;
+class BasicBlock;
+class RenameFunctionEvent;
+class ChangeCommentEvent;
- void mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
- QGraphicsItem::mouseMoveEvent(event);
- scene()->update();
- }
+class BasicBlockWidget : public QObject, public QGraphicsItem
+{
+ Q_OBJECT
+ friend class CustomQGraphicsTextItem;
+public:
+ BasicBlockWidget(const QString& name, BasicBlock * block, Mainwindow * mainwindow);
- QPointF getEntry() const {
- return mapToScene(QPointF(width/2, 0));
- }
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+ QRectF boundingRect() const;
+ std::array<QPointF, 3> getExits() const;
- std::array<QPointF, 3> getExits() const {
- return { { mapToScene(QPointF( width/3, height)),
- mapToScene(QPointF( width/2, height)),
- mapToScene(QPointF(2*width/3, height)) } };
- }
+ void mouseMoveEvent(QGraphicsSceneMouseEvent * event)
+ { QGraphicsItem::mouseMoveEvent(event); scene()->update(); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget) {
- painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff));
- painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
- painter->drawRect(0, 0, width, height);
- painter->drawText(5, 15, name);
- if (_widget.rowCount() != 0)
- _widget.render(painter, QPoint(5, 20));
- }
+ QPointF getEntry() const
+ { return mapToScene(QPointF(width/2, 0)); }
- void addPrevious(BasicBlockWidget * widget) {
- previous.push_back(widget);
- }
+ void addPrevious(BasicBlockWidget * widget)
+ { previous.push_back(widget); }
- void addNext(BasicBlockWidget * left, BasicBlockWidget * right) {
- next[0] = left;
- next[1] = right;
- }
+ void addNext(BasicBlockWidget * left, BasicBlockWidget * right)
+ { next[0] = left; next[1] = right; }
- BasicBlockWidget ** getNext() {
- return next;
- }
+ BasicBlockWidget ** getNext()
+ { return next; }
+ QString getName() const
+ { return name; }
private:
- uint32_t width, height;
- QTableWidget _widget;
+ void updateFunctionName(RenameFunctionEvent* event);
+ void populateWidget();
+ void changeCommentHandler(ChangeCommentEvent* event);
+ QString formatComments(Instruction* inst);
+
+ uint32_t width, height;
QString name;
- BasicBlock * block;
+ std::unique_ptr<QGraphicsTextItem> _widget;
+ QTextTable* _table;
+ BasicBlock* block;
+ std::vector<Instruction> instructions;
+ Mainwindow* mainwindow;
std::vector<BasicBlockWidget*> previous;
BasicBlockWidget* next[2];
+ log4cxx::LoggerPtr logger;
};
#endif