2019-01-24 17:13:04 +00:00
|
|
|
#include "OverviewView.h"
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2019-01-24 17:13:04 +00:00
|
|
|
#include "common/Colors.h"
|
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/TempConfig.h"
|
|
|
|
|
|
|
|
OverviewView::OverviewView(QWidget *parent)
|
|
|
|
: GraphView(parent)
|
|
|
|
{
|
|
|
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
|
|
|
colorsUpdatedSlot();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::setData(int baseWidth, int baseHeight, std::unordered_map<ut64, GraphBlock> baseBlocks)
|
|
|
|
{
|
|
|
|
width = baseWidth;
|
|
|
|
height = baseHeight;
|
|
|
|
blocks = baseBlocks;
|
2019-03-12 07:37:10 +00:00
|
|
|
scaleAndCenter();
|
2019-01-24 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OverviewView::~OverviewView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-12 07:37:10 +00:00
|
|
|
void OverviewView::scaleAndCenter()
|
2019-01-24 17:13:04 +00:00
|
|
|
{
|
2019-02-16 17:17:11 +00:00
|
|
|
current_scale = (qreal)viewport()->width() / width;
|
|
|
|
qreal h_scale = (qreal)viewport()->height() / height;
|
|
|
|
if (current_scale > h_scale) {
|
|
|
|
current_scale = h_scale;
|
2019-01-24 17:13:04 +00:00
|
|
|
}
|
2019-02-16 17:17:11 +00:00
|
|
|
center();
|
2019-03-12 07:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::refreshView()
|
|
|
|
{
|
|
|
|
scaleAndCenter();
|
2019-01-24 17:13:04 +00:00
|
|
|
viewport()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
|
|
|
{
|
2019-03-23 08:21:06 +00:00
|
|
|
int blockX = block.x - offset.x();
|
|
|
|
int blockY = block.y - offset.y();
|
2019-02-16 17:17:11 +00:00
|
|
|
|
2019-01-24 17:13:04 +00:00
|
|
|
p.setPen(Qt::black);
|
|
|
|
p.setBrush(Qt::gray);
|
2019-02-16 17:17:11 +00:00
|
|
|
p.drawRect(blockX, blockY, block.width, block.height);
|
2019-01-24 17:13:04 +00:00
|
|
|
p.setBrush(QColor(0, 0, 0, 100));
|
2019-02-16 17:17:11 +00:00
|
|
|
p.drawRect(blockX + 2, blockY + 2,
|
2019-01-24 17:13:04 +00:00
|
|
|
block.width, block.height);
|
2019-03-26 11:07:17 +00:00
|
|
|
|
2019-02-19 18:56:59 +00:00
|
|
|
// Draw basic block highlighting/tracing
|
|
|
|
auto bb = Core()->getBBHighlighter()->getBasicBlock(block.entry);
|
|
|
|
if (bb) {
|
|
|
|
QColor color(bb->color);
|
|
|
|
color.setAlphaF(0.5);
|
|
|
|
p.setBrush(color);
|
2019-03-26 11:07:17 +00:00
|
|
|
} else {
|
|
|
|
p.setBrush(disassemblyBackgroundColor);
|
2019-02-19 18:56:59 +00:00
|
|
|
}
|
2019-03-26 11:07:17 +00:00
|
|
|
p.setPen(QPen(graphNodeColor, 1));
|
|
|
|
p.drawRect(blockX, blockY,
|
|
|
|
block.width, block.height);
|
2019-01-24 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
GraphView::paintEvent(event);
|
|
|
|
if (rangeRect.width() == 0 && rangeRect.height() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPainter p(viewport());
|
|
|
|
p.setPen(Qt::red);
|
|
|
|
p.drawRect(rangeRect);
|
|
|
|
}
|
|
|
|
|
2019-02-03 07:54:28 +00:00
|
|
|
bool OverviewView::mouseContainsRect(QMouseEvent *event)
|
2019-01-24 17:13:04 +00:00
|
|
|
{
|
|
|
|
if (rangeRect.contains(event->pos())) {
|
|
|
|
mouseActive = true;
|
|
|
|
initialDiff = QPointF(event->localPos().x() - rangeRect.x(), event->localPos().y() - rangeRect.y());
|
2019-02-03 07:54:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (mouseContainsRect(event)) {
|
2019-01-24 17:13:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
qreal w = rangeRect.width();
|
|
|
|
qreal h = rangeRect.height();
|
2019-02-16 17:17:11 +00:00
|
|
|
qreal x = event->localPos().x() - w / 2;
|
|
|
|
qreal y = event->localPos().y() - h / 2;
|
2019-01-24 17:13:04 +00:00
|
|
|
rangeRect = QRectF(x, y, w, h);
|
2019-03-12 07:37:10 +00:00
|
|
|
useCache = true;
|
2019-01-24 17:13:04 +00:00
|
|
|
viewport()->update();
|
|
|
|
emit mouseMoved();
|
2019-02-03 07:54:28 +00:00
|
|
|
mouseContainsRect(event);
|
2019-01-24 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
mouseActive = false;
|
|
|
|
GraphView::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!mouseActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qreal x = event->localPos().x() - initialDiff.x();
|
|
|
|
qreal y = event->localPos().y() - initialDiff.y();
|
2019-02-16 17:17:11 +00:00
|
|
|
rangeRect = QRectF(x, y, rangeRect.width(), rangeRect.height());
|
2019-03-12 07:37:10 +00:00
|
|
|
useCache = true;
|
2019-01-24 17:13:04 +00:00
|
|
|
viewport()->update();
|
|
|
|
emit mouseMoved();
|
|
|
|
}
|
|
|
|
|
2019-02-16 17:17:11 +00:00
|
|
|
void OverviewView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2019-01-24 17:13:04 +00:00
|
|
|
GraphView::EdgeConfiguration OverviewView::edgeConfiguration(GraphView::GraphBlock &from,
|
|
|
|
GraphView::GraphBlock *to)
|
|
|
|
{
|
|
|
|
Q_UNUSED(from);
|
|
|
|
Q_UNUSED(to);
|
|
|
|
EdgeConfiguration ec;
|
|
|
|
ec.width_scale = current_scale;
|
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::colorsUpdatedSlot()
|
|
|
|
{
|
|
|
|
disassemblyBackgroundColor = ConfigColor("gui.overview.node");
|
|
|
|
graphNodeColor = ConfigColor("gui.border");
|
|
|
|
backgroundColor = ConfigColor("gui.background");
|
|
|
|
refreshView();
|
|
|
|
}
|