#include "BasicBlockWidget.hxx"
+#include "CFGScene.hxx"
#include "gui/Mainwindow.hxx"
#include "gui/dialogs/SimpleStringDialog.hxx"
#include "core/BasicBlock.hxx"
BasicBlockWidget::BasicBlockWidget(const QString& name, BasicBlock * block,
Mainwindow * mainwindow)
: width(200), height(45), name(name)
- , _table(NULL)
+ , currentColor(defaultColor), _table(NULL)
, block(block), mainwindow(mainwindow)
, logger(log4cxx::Logger::getLogger("gui.BasicBlockWidget." + name.toStdString())) {
next[0] = NULL; next[1] = NULL;
if (str.startsWith("function:")) {
QString address = str.remove("function:");
mainwindow->switchMainPlaneToAddress(address.toInt(NULL, 16));
+ } else if (str.startsWith("block:")) {
+ QString address = str.remove("block:");
+
+ /* next[0] is always the jumptarget. On a
+ * conditional jump, next[1] also
+ * contains the following instruction
+ *
+ * TODO: Verify we're switching to the
+ * right block -- the target
+ * address matches the next blocks
+ * start address
+ */
+ LOG4CXX_TRACE(logger, "Highlighting block at Address " << address.toStdString()
+ << " BasicBlockWidget " << std::hex << next[0]);
+ ((CFGScene*)this->scene())->highlightBlock(next[0]);
}
});
instructions = block->getInstructions();
height = 25 + _widget->boundingRect().height();
if (width < 250) width = 250;
- painter->fillRect(0, 0, width, height, QColor(0xcc, 0xcc, 0xff, 0xff));
+ painter->fillRect(0, 0, width, height, currentColor);
painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
painter->drawRect(0, 0, width, height);
painter->drawText(5, 15, name);
QString getName() const
{ return name; }
+
+ QColor setColor(const QColor& newColor) {
+ QColor lastcolor = currentColor;
+ currentColor = newColor;
+ return lastcolor;
+ }
+
+ const QColor defaultColor = QColor(0xcc, 0xcc, 0xff, 0xff);
+ const QColor highlightColor = QColor(0xff, 0x99, 0xff, 0xff);
private:
void updateFunctionName(RenameFunctionEvent* event);
void populateWidget();
uint32_t width, height;
QString name;
+ QColor currentColor;
std::unique_ptr<QGraphicsTextItem> _widget;
QTextTable* _table;
BasicBlock* block;
class CFGScene : public QGraphicsScene {
public:
CFGScene(QWidget * parent = 0)
- : QGraphicsScene(parent) {}
+ : QGraphicsScene(parent), highlightedBlock(NULL) {}
// Take special care when adding a BasicBlock to the scene as we
// need to draw arrows for it later on
}
virtual void drawBackground(QPainter* painter, const QRectF & rect);
+ void highlightBlock(BasicBlockWidget* block);
private:
std::vector<BasicBlockWidget*> widgets;
void drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side = 0);
void spaceWidgets();
+
+ BasicBlockWidget* highlightedBlock;
};
#endif