Scene gets centered when viewing a new basic block
Zooming on graph happens on mouse position
This commit is contained in:
parent
40ebf00a54
commit
8bd7bdcf6a
|
|
@ -1,6 +1,8 @@
|
|||
#include "GraphNode.h"
|
||||
|
||||
GraphNode::GraphNode()
|
||||
#include <QStyleOption>
|
||||
|
||||
GraphNode::GraphNode() : QFrame()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +14,7 @@ GraphNode::GraphNode(std::vector<Instruction_t> &instructionsVector, duint addre
|
|||
|
||||
updateTokensVector();
|
||||
|
||||
setStyleSheet("border: 1px solid black;");
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setContentsMargins(0,0,0,0);
|
||||
setMouseTracking(true); // required for mouse move event
|
||||
installEventFilter(this);
|
||||
|
|
@ -41,17 +43,28 @@ void GraphNode::paintEvent(QPaintEvent* event)
|
|||
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(0, 0, mCachedWidth, mCachedHeight, Qt::white);
|
||||
|
||||
// Draw node borders
|
||||
painter.setPen(QPen(Qt::black, 1));
|
||||
painter.drawLine(0, mLineHeight, 0, mCachedHeight-1);
|
||||
painter.drawLine(mCachedWidth-1, mLineHeight, mCachedWidth-1, mCachedHeight-1);
|
||||
painter.drawLine(0, mCachedHeight-1, mCachedWidth-1, mCachedHeight-1);
|
||||
|
||||
// QStyleOption opt;
|
||||
// opt.init(this);
|
||||
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
|
||||
|
||||
//draw node contents
|
||||
painter.setPen(Qt::black);
|
||||
painter.setFont(this->mFont);
|
||||
int i = 0;
|
||||
|
||||
int x = mSpacingX/2, y = mLineHeight + mSpacingY/2;
|
||||
|
||||
// Block address
|
||||
painter.fillRect(0, 0, mCachedWidth, mLineHeight, QBrush(Qt::magenta));
|
||||
painter.fillRect(0, 0, mCachedWidth, mLineHeight, Qt::cyan);
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(0, 0, mCachedWidth, mLineHeight, Qt::AlignHCenter | Qt::AlignVCenter, "0x" + QString::number(mAddress, 16));
|
||||
painter.drawText(0, 0, mCachedWidth, mLineHeight, Qt::AlignHCenter | Qt::AlignVCenter, "0x" + QString::number(mAddress, 16).toUpper());
|
||||
|
||||
// Block instructions
|
||||
for(QList<RichTextPainter::CustomRichText_t> &richText : mRichTextVector)
|
||||
|
|
@ -64,6 +77,7 @@ void GraphNode::paintEvent(QPaintEvent* event)
|
|||
y += mLineHeight + mLineSpacingY;
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dsint GraphNode::getInstructionIndexAtPos(const QPoint &pos) const
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define _GRAPH_NODE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
#include <QMouseEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QFontMetrics>
|
||||
|
|
@ -11,7 +12,7 @@
|
|||
#include "capstone_gui.h"
|
||||
#include "QBeaEngine.h"
|
||||
|
||||
class GraphNode : public QWidget
|
||||
class GraphNode : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
#include "GraphView.h"
|
||||
#include "ui_GraphView.h"
|
||||
#include "GraphEdge.h"
|
||||
#include "Configuration.h"
|
||||
#include <QDebug>
|
||||
|
||||
#include "GraphEdge.h"
|
||||
|
||||
GraphView::GraphView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
|
@ -22,7 +23,7 @@ GraphView::GraphView(QWidget *parent) :
|
|||
mGraphNodeVector = new GRAPHNODEVECTOR;
|
||||
bProgramInitialized = false;
|
||||
|
||||
mScene->setBackgroundBrush(QBrush(Qt::black));
|
||||
mScene->setBackgroundBrush(ConfigColor("DisassemblyBackgroundColor"));
|
||||
// ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
// ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
ui->graphicsView->setScene(mScene);
|
||||
|
|
@ -155,7 +156,6 @@ void GraphView::addGraphToScene()
|
|||
using namespace ogdf;
|
||||
|
||||
mScene->clear();
|
||||
ui->graphicsView->viewport()->update();
|
||||
|
||||
// adjust node size
|
||||
node v;
|
||||
|
|
@ -217,12 +217,15 @@ void GraphView::addGraphToScene()
|
|||
|
||||
// mScene->setSceneRect(mScene->itemsBoundingRect());
|
||||
|
||||
// mScene->setSceneRect(0, 0, mGA->boundingBox().width(), mGA->boundingBox().height());
|
||||
QTextStream out(stdout);
|
||||
out << "*-----------------------------------*"<< endl;
|
||||
out << mScene->sceneRect().x() << endl;
|
||||
out << mScene->sceneRect().y() << endl;
|
||||
out << mScene->sceneRect().width() << endl;
|
||||
out << mScene->sceneRect().height() << endl;
|
||||
ui->graphicsView->ensureVisible(mScene->itemsBoundingRect());
|
||||
ui->graphicsView->setSceneRect(mScene->sceneRect());
|
||||
|
||||
// ui->graphicsView->fitInView(mScene->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
|
@ -354,13 +357,6 @@ void GraphView::dbgStateChangedSlot(DBGSTATE state)
|
|||
bProgramInitialized = false;
|
||||
}
|
||||
|
||||
void GraphView::sceneChangedSlot(QList<QRectF> rectList)
|
||||
{
|
||||
Q_UNUSED(rectList);
|
||||
// ui->graphicsView->fitInView(mScene->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
|
||||
bool GraphView::findBasicBlock(duint &va)
|
||||
{
|
||||
if(!mBasicBlockInfo)
|
||||
|
|
@ -394,7 +390,6 @@ bool GraphView::findBasicBlock(duint &va)
|
|||
|
||||
void GraphView::drawGraphAtSlot(duint va)
|
||||
{
|
||||
|
||||
bool bFound = findBasicBlock(va);
|
||||
|
||||
if(!bFound)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ public slots:
|
|||
void disassembleAtSlot(dsint parVA, dsint CIP);
|
||||
void setControlFlowInfosSlot(duint *controlFlowInfos);
|
||||
void dbgStateChangedSlot(DBGSTATE state);
|
||||
void sceneChangedSlot(QList<QRectF> rectList);
|
||||
|
||||
private:
|
||||
void setupGraph();
|
||||
|
|
@ -98,8 +97,6 @@ private:
|
|||
Tree<GraphNode*> *mTree;
|
||||
Ui::GraphView *ui;
|
||||
bool bProgramInitialized;
|
||||
int mIndex = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // GRAPHVIEW_H
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
#include "QGraphView.h"
|
||||
#include <QTimeLine>
|
||||
#include <iostream>
|
||||
|
||||
QGraphView::QGraphView(QWidget* parent)
|
||||
: QGraphicsView(parent)
|
||||
{
|
||||
|
||||
bAnimationFinished = false;
|
||||
}
|
||||
|
||||
void QGraphView::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
if(!(event->modifiers() & Qt::ControlModifier))
|
||||
QGraphicsView::wheelEvent(event);
|
||||
|
||||
int numDegrees = event->delta() / 8;
|
||||
int numSteps = numDegrees / 15; // see QWheelEvent documentation
|
||||
_numScheduledScalings += numSteps;
|
||||
|
|
@ -20,7 +24,15 @@ void QGraphView::wheelEvent(QWheelEvent* event)
|
|||
|
||||
connect(anim, SIGNAL (valueChanged(qreal)), SLOT (scalingTime(qreal)));
|
||||
connect(anim, SIGNAL (finished()), SLOT (animFinished()));
|
||||
|
||||
QPointF mappedMousePos = this->mapToScene(event->pos().x(), event->pos().y());
|
||||
if(scene()->itemsBoundingRect().contains(mappedMousePos.x(), mappedMousePos.y()))
|
||||
centerOn(mappedMousePos.x(), mappedMousePos.y());
|
||||
// std::cout << mappedMousePos.x() << " - " << mappedMousePos.y() << std::endl;
|
||||
|
||||
|
||||
anim->start();
|
||||
bAnimationFinished = false;
|
||||
}
|
||||
|
||||
void QGraphView::scalingTime(qreal x)
|
||||
|
|
@ -36,5 +48,7 @@ void QGraphView::animFinished()
|
|||
_numScheduledScalings--;
|
||||
else
|
||||
_numScheduledScalings++;
|
||||
|
||||
sender()->~QObject();
|
||||
bAnimationFinished = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ private slots:
|
|||
void animFinished();
|
||||
|
||||
private:
|
||||
QPoint mMousePos;
|
||||
bool bAnimationFinished;
|
||||
int _numScheduledScalings;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue