]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/widgets/BasicBlockWidget.hxx
Switch again BasicBlockWidget base -- to QGraphicsTextItem
[frida/frida.git] / src / gui / widgets / BasicBlockWidget.hxx
index 3c547b558ef10750c55d14201c30fb391565d858..8ee33a56f21a43e6bcccfb26bbde48b6e395f58f 100644 (file)
@@ -5,73 +5,48 @@
 #include "disassembler/BasicBlock.hxx"
 #include <vector>
 #include <cassert>
+#include <tuple>
+#include <array>
 
-class BasicBlockWidget : public QGraphicsItem
+class Mainwindow;
+
+class BasicBlockWidget : public QObject, public QGraphicsItem
 {
+       Q_OBJECT
 public:
-    BasicBlockWidget(const QString& name, BasicBlock * block);
-
-       void addItem(uint8_t* bytes, size_t num_bytes, const QString& line);
-
-    QRectF boundingRect() const  {
-        qreal penWidth = 1;
-               QRectF result(x - penWidth / 2, y - penWidth / 2,
-                      dx + penWidth, dy + penWidth);
+       BasicBlockWidget(const QString& name, BasicBlock * block, Mainwindow * mainwindow);
 
+       void addItem(uint8_t* bytes, size_t num_bytes, QString line, const QString& href);
 
-               if (next[0]) {
-                       if (next[1]) {
-                               result |= QRectF(QPointF(x + dx/3, y+dy),
-                                                                mapFromScene(next[0]->getEntry()));
-                       } else {
-                               result |= QRectF(QPointF(x + dx/2, y+dy),
-                                                                mapFromScene(next[0]->getEntry()));
-                       }
-               }
-               if (next[1])
-                       result |= QRectF(QPointF(x + 2*dx/3, y+dy),
-                                                        mapFromScene(next[1]->getEntry()));
+       QRectF boundingRect() const  {
+               qreal penWidth = 1;
+               QRectF result(- penWidth / 2, - penWidth / 2,
+                             width + penWidth, height + penWidth);
+               return result;
+       }
 
-        return result;
-    }
-       void mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+       void mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
                QGraphicsItem::mouseMoveEvent(event);
-               std::for_each(previous.begin(), previous.end(),
-                                         [&] (BasicBlockWidget * item) {
-                                                 item->update(boundingRect() | item->boundingRect());
-                                         });
+               scene()->update();
        }
 
        QPointF getEntry() const {
-               return mapToScene(QPointF(x + dx/2, y));
+               return mapToScene(QPointF(width/2, 0));
        }
 
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
-               QWidget *widget) {
-        painter->fillRect(x, y, dx, dy, QColor(0xcc, 0xcc, 0xff, 0xff));
-        painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
-        painter->drawRect(x, y, dx, dy);
-        painter->drawText(0, -5, name);
-               if (_widget.rowCount() != 0)
-                       _widget.render(painter);
-
-               if (next[0]) {
-                       if (next[1]) {
-                               painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
-                               painter->drawLine(QPointF(x + dx/3, y+dy),
-                                                                 mapFromScene(next[0]->getEntry()));
-                       } else {
-                               painter->setPen(QColor(0x00, 0x00, 0x00, 0xff));
-                               painter->drawLine(QPointF(x + dx/2, y+dy),
-                                                                 mapFromScene(next[0]->getEntry()));
-                       }
-               }
-               painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
-               if (next[1])
-                       painter->drawLine(QPointF(x + 2*dx/3, y+dy),
-                                                         mapFromScene(next[1]->getEntry()));
+       std::array<QPointF, 3> getExits() const {
+               return { { mapToScene(QPointF(  width/3, height)),
+                          mapToScene(QPointF(  width/2, height)),
+                          mapToScene(QPointF(2*width/3, height)) } };
+       }
 
-    }
+       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);
+       }
 
        void addPrevious(BasicBlockWidget * widget) {
                previous.push_back(widget);
@@ -82,11 +57,20 @@ public:
                next[1] = right;
        }
 
+       BasicBlockWidget ** getNext() {
+               return next;
+       }
+
+       QString getName() const {
+               return name;
+       }
 private:
-    int x, y, dx, dy;
-    QTableWidget _widget;
+       uint32_t width, height;
+       QGraphicsTextItem _widget;
+       QTextTable* _table;
        QString name;
        BasicBlock * block;
+       Mainwindow * mainwindow;
        std::vector<BasicBlockWidget*> previous;
        BasicBlockWidget* next[2];
 };