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();
|
|
|
|
}
|
|
|
|
|
2019-04-04 05:54:42 +00:00
|
|
|
void OverviewView::setData(int baseWidth, int baseHeight,
|
|
|
|
std::unordered_map<ut64, GraphBlock> baseBlocks,
|
|
|
|
DisassemblerGraphView::EdgeConfigurationMapping baseEdgeConfigurations)
|
2019-01-24 17:13:04 +00:00
|
|
|
{
|
|
|
|
width = baseWidth;
|
|
|
|
height = baseHeight;
|
|
|
|
blocks = baseBlocks;
|
2019-04-04 05:54:42 +00:00
|
|
|
edgeConfigurations = baseEdgeConfigurations;
|
2019-03-12 07:37:10 +00:00
|
|
|
scaleAndCenter();
|
2019-04-08 06:59:16 +00:00
|
|
|
setCacheDirty();
|
2019-04-14 12:18:24 +00:00
|
|
|
viewport()->update();
|
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-04-14 12:18:24 +00:00
|
|
|
qreal wScale = (qreal)viewport()->width() / width;
|
|
|
|
qreal hScale = (qreal)viewport()->height() / height;
|
|
|
|
setViewScale(std::min(wScale, hScale));
|
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-04-14 12:18:24 +00:00
|
|
|
int blockX = block.x - getViewOffset().x();
|
|
|
|
int blockY = block.y - getViewOffset().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-05-16 12:17:38 +00:00
|
|
|
void OverviewView::mousePressEvent(QMouseEvent *event)
|
2019-01-24 17:13:04 +00:00
|
|
|
{
|
2019-05-16 12:17:38 +00:00
|
|
|
mouseActive = true;
|
2019-01-24 17:13:04 +00:00
|
|
|
if (rangeRect.contains(event->pos())) {
|
|
|
|
initialDiff = QPointF(event->localPos().x() - rangeRect.x(), event->localPos().y() - rangeRect.y());
|
2019-05-16 12:17:38 +00:00
|
|
|
} else {
|
|
|
|
qreal w = rangeRect.width();
|
|
|
|
qreal h = rangeRect.height();
|
|
|
|
qreal x = event->localPos().x() - w / 2;
|
|
|
|
qreal y = event->localPos().y() - h / 2;
|
|
|
|
rangeRect = QRectF(x, y, w, h);
|
|
|
|
initialDiff = QPointF(w / 2, h / 2);
|
|
|
|
viewport()->update();
|
|
|
|
emit mouseMoved();
|
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-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,
|
2019-04-04 05:54:42 +00:00
|
|
|
GraphView::GraphBlock *to)
|
2019-01-24 17:13:04 +00:00
|
|
|
{
|
|
|
|
EdgeConfiguration ec;
|
2019-04-04 05:54:42 +00:00
|
|
|
auto baseEcIt = edgeConfigurations.find({from.entry, to->entry});
|
|
|
|
if (baseEcIt != edgeConfigurations.end())
|
|
|
|
ec = baseEcIt->second;
|
2019-04-14 12:18:24 +00:00
|
|
|
ec.width_scale = getViewScale();
|
2019-01-24 17:13:04 +00:00
|
|
|
return ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OverviewView::colorsUpdatedSlot()
|
|
|
|
{
|
|
|
|
disassemblyBackgroundColor = ConfigColor("gui.overview.node");
|
|
|
|
graphNodeColor = ConfigColor("gui.border");
|
|
|
|
backgroundColor = ConfigColor("gui.background");
|
2019-05-06 08:30:49 +00:00
|
|
|
setCacheDirty();
|
2019-01-24 17:13:04 +00:00
|
|
|
refreshView();
|
|
|
|
}
|
2019-04-14 12:18:24 +00:00
|
|
|
|
|
|
|
void OverviewView::setRangeRect(QRectF rect)
|
|
|
|
{
|
|
|
|
rangeRect = rect;
|
|
|
|
viewport()->update();
|
|
|
|
}
|