Use QGraphicsProxyWidget
authorChristoph Egger <Christoph.Egger@cs.fau.de>
Wed, 7 Jan 2015 20:41:22 +0000 (21:41 +0100)
committerChristoph Egger <Christoph.Egger@cs.fau.de>
Wed, 7 Jan 2015 20:41:22 +0000 (21:41 +0100)
This way the qlabel widget can be accessed properly (clicking and stuff)

src/gui/widgets/BasicBlockWidget.cxx
src/gui/widgets/BasicBlockWidget.hxx
src/gui/widgets/CFGScene.cxx

index ab06f88d83bff3c9df2f018f92f28e173087293d..2003458d8733a2deb3e7e15d4b5a426209833c0c 100644 (file)
@@ -2,9 +2,13 @@
 
 BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block)
        : width(270), height(45)
-       , name(name), block(block) {
+       , name(name), block(block)
+       , _proxy(this) {
        next[0] = NULL; next[1] = NULL;
-       _widget.move(5, 20);
+       _proxy.setWidget(&_widget);
+       _widget.setTextInteractionFlags(Qt::TextSelectableByMouse|Qt::LinksAccessibleByMouse);
+
+       _proxy.setPos(5, 20);
 
        if (width < 270) width = 270;
 }
@@ -22,7 +26,7 @@ void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes,
 
        QString old_text = _widget.text();
        if (old_text == "") {
-               old_text = "<table style=\"background-color: #ccccff;\">";
+               old_text = "<table style=\"background-color: #ddddff;\">";
        }
        QString new_text =
                old_text.remove("</table>") +
@@ -32,6 +36,7 @@ void BasicBlockWidget::addItem(uint8_t* bytes, size_t num_bytes,
                "</td></tr></table>";
 
        _widget.setText(new_text);
+       _widget.resize(_widget.sizeHint().width(), _widget.sizeHint().height());
        width = 12 + _widget.sizeHint().width();
        height = 25 + _widget.sizeHint().height();
 
index 2dcc80c237b0890e5cfe3e1ecd39c617d73244b5..8aa182f671f94c130f923729ec4ef01a90053997 100644 (file)
@@ -43,8 +43,6 @@ public:
                painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
                painter->drawRect(0, 0, width, height);
                painter->drawText(5, 15, name);
-               if (_widget.text() != "")
-                       _widget.render(painter, QPoint(5, 20));
        }
 
        void addPrevious(BasicBlockWidget * widget) {
@@ -62,6 +60,7 @@ public:
 
 private:
        uint32_t width, height;
+       QGraphicsProxyWidget _proxy;
        QLabel _widget;
        QString name;
        BasicBlock * block;
index ec33463c835c5c1a3ee8856e1bf8dc445bb55835..4e7428d340f93c822c3ed0d48e907a7136e79742 100644 (file)
@@ -93,6 +93,7 @@ void CFGScene::spaceWidgets() {
                relevantRect.adjust(-20, -20, 20, 20);
                for (QGraphicsItem * item : items(relevantRect)) {
                        if (item == widget) continue;
+                       if (std::find(widgets.begin(), widgets.end(), item) == widgets.end()) continue;
                        QRectF itemrect = item->boundingRect();
                        itemrect.moveTo(item->scenePos());
                        while (relevantRect.intersects(itemrect)) {