From fae0fc8f1d90f5f36cfc336a92aa9d488471332d Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Sat, 29 Nov 2014 00:19:58 +0100 Subject: [PATCH] Horizontally distribute BasicBlockWidgets We still need to add a bit of space between them but the currently used QT API doesn't trivially allow that --- src/gui/Mainwindow.cxx | 5 ++++- src/gui/widgets/CFGScene.cxx | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 9a8310c..f98cd60 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -102,10 +102,13 @@ namespace { BasicBlockWidget *tmp, *nextl(NULL), *nextr(NULL); BasicBlock * tmpblock; if (block->getNextBlock(0) != 0) { + int xshift = 0; + if (block->getNextBlock(1) != 0) + xshift = 1; tmpblock = dis->getBasicBlock(block->getNextBlock(0)); tmp = local__add_basic_block(tmpblock, dis, known_blocks, - scene, starty, startx+1); + scene, starty, startx+xshift); nextl = tmp; tmp->addPrevious(widget); } diff --git a/src/gui/widgets/CFGScene.cxx b/src/gui/widgets/CFGScene.cxx index 7bed8f1..a297c85 100644 --- a/src/gui/widgets/CFGScene.cxx +++ b/src/gui/widgets/CFGScene.cxx @@ -59,4 +59,15 @@ void CFGScene::spaceWidgets() { } } } while (changed); + + for (BasicBlockWidget * widget : widgets) { + for (QGraphicsItem * item : widget->collidingItems()) { + while (widget->collidesWithItem(item)) { + if (widget->scenePos().x() > item->scenePos().x()) + widget->moveBy(1, 0); + else + item->moveBy(1, 0); + } + } + } } -- 2.39.2