diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6dce720a..88929bf6 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -50,7 +50,7 @@ #include "widgets/SectionsDock.h" #include "widgets/RelocsWidget.h" #include "widgets/FlagsWidget.h" -#include "widgets/CodeGraphic.h" +#include "widgets/VisualNavbar.h" #include "widgets/Dashboard.h" #include "widgets/Notepad.h" #include "widgets/Sidebar.h" @@ -90,7 +90,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow), highlighter(nullptr), hex_highlighter(nullptr), - graphicsBar(nullptr), + visualNavbar(nullptr), entrypointDock(nullptr), functionsDock(nullptr), importsDock(nullptr), @@ -171,11 +171,11 @@ void MainWindow::initUI() spacer->setMinimumSize(20, 20); ui->mainToolBar->addWidget(spacer); - // codeGraphics tool bar - this->graphicsBar = new GraphicsBar(this); - this->graphicsBar->setMovable(false); + // Visual navigation tool bar + this->visualNavbar = new VisualNavbar(this); + this->visualNavbar->setMovable(false); addToolBarBreak(Qt::TopToolBarArea); - addToolBar(graphicsBar); + addToolBar(visualNavbar); /* * Dock Widgets diff --git a/src/MainWindow.h b/src/MainWindow.h index 87878433..9b34c82c 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -20,7 +20,7 @@ class PreviewWidget; class Notepad; class Highlighter; class AsciiHighlighter; -class GraphicsBar; +class VisualNavbar; class FunctionsWidget; class ImportsWidget; class ExportsWidget; @@ -187,7 +187,7 @@ private: std::unique_ptr ui; Highlighter *highlighter; AsciiHighlighter *hex_highlighter; - GraphicsBar *graphicsBar; + VisualNavbar *visualNavbar; EntrypointWidget *entrypointDock; FunctionsWidget *functionsDock; ImportsWidget *importsDock; diff --git a/src/cutter.pro b/src/cutter.pro index 11be9e4d..0cc26a6a 100644 --- a/src/cutter.pro +++ b/src/cutter.pro @@ -52,7 +52,6 @@ SOURCES += \ dialogs/CreateNewDialog.cpp \ dialogs/NewFileDialog.cpp \ AnalThread.cpp \ - widgets/CodeGraphic.cpp \ widgets/CommentsWidget.cpp \ widgets/ConsoleWidget.cpp \ widgets/Dashboard.cpp \ @@ -80,7 +79,8 @@ SOURCES += \ dialogs/SaveProjectDialog.cpp \ utils/TempConfig.cpp \ utils/SvgIconEngine.cpp \ - widgets/PseudocodeWidget.cpp + widgets/PseudocodeWidget.cpp \ + widgets/VisualNavbar.cpp HEADERS += \ cutter.h \ @@ -103,7 +103,6 @@ HEADERS += \ dialogs/CreateNewDialog.h \ dialogs/NewFileDialog.h \ AnalThread.h \ - widgets/CodeGraphic.h \ widgets/CommentsWidget.h \ widgets/ConsoleWidget.h \ widgets/Dashboard.h \ @@ -131,7 +130,8 @@ HEADERS += \ dialogs/SaveProjectDialog.h \ utils/TempConfig.h \ utils/SvgIconEngine.h \ - widgets/PseudocodeWidget.h + widgets/PseudocodeWidget.h \ + widgets/VisualNavbar.h FORMS += \ dialogs/AboutDialog.ui \ diff --git a/src/widgets/CodeGraphic.cpp b/src/widgets/VisualNavbar.cpp similarity index 81% rename from src/widgets/CodeGraphic.cpp rename to src/widgets/VisualNavbar.cpp index bf9c721c..9c21e7d9 100644 --- a/src/widgets/CodeGraphic.cpp +++ b/src/widgets/VisualNavbar.cpp @@ -1,4 +1,4 @@ -#include "CodeGraphic.h" +#include "VisualNavbar.h" #include "MainWindow.h" #include "utils/TempConfig.h" @@ -12,60 +12,68 @@ #include #include -GraphicsBar::GraphicsBar(MainWindow *main, QWidget *parent) : +VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) : QToolBar(main), - codeGraphic(new QGraphicsView), + graphicsView(new QGraphicsView), main(main) { Q_UNUSED(parent); - setObjectName("codeGraphics"); - setWindowTitle(tr("Code bar")); + setObjectName("visualNavbar"); + setWindowTitle(tr("Visual navigation bar")); // setMovable(false); setContentsMargins(0, 0, 0, 0); // If line below is used, with the dark theme the paintEvent is not called // and the result is wrong. Something to do with overwriting the style sheet :/ //setStyleSheet("QToolBar { border: 0px; border-bottom: 0px; border-top: 0px; border-width: 0px;}"); - this->codeGraphic->setAlignment(Qt::AlignLeft); - this->codeGraphic->setMinimumHeight(20); - this->codeGraphic->setMaximumHeight(20); - this->codeGraphic->setFrameShape(QFrame::NoFrame); - /* QComboBox *addsCombo = new QComboBox(); addsCombo->addItem(""); addsCombo->addItem("Entry points"); addsCombo->addItem("Marks"); */ - addWidget(this->codeGraphic); + addWidget(this->graphicsView); //addWidget(addsCombo); connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData())); graphicsScene = new QGraphicsScene(this); + + const QBrush bg = QBrush(QColor(74, 74, 74)); + + graphicsScene->setBackgroundBrush(bg); + + this->graphicsView->setAlignment(Qt::AlignLeft); + this->graphicsView->setMinimumHeight(20); + this->graphicsView->setMaximumHeight(20); + this->graphicsView->setFrameShape(QFrame::NoFrame); + this->graphicsView->setRenderHints(0); + this->graphicsView->setScene(graphicsScene); + this->graphicsView->setRenderHints(QPainter::Antialiasing); + this->graphicsView->setToolTip("gap"); } -void GraphicsBar::paintEvent(QPaintEvent *event) +void VisualNavbar::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); - if(previousWidth != this->codeGraphic->width()) + if(previousWidth != this->width()) { this->fillData(); - previousWidth = this->codeGraphic->width(); + previousWidth = this->width(); } } -void GraphicsBar::fetchAndPaintData() +void VisualNavbar::fetchAndPaintData() { fetchData(); fillData(); } -void GraphicsBar::fetchData() +void VisualNavbar::fetchData() { TempConfig tempConfig; tempConfig.set("search.in", QString("io.section")); @@ -84,26 +92,19 @@ void GraphicsBar::fetchData() } } -void GraphicsBar::fillData() +void VisualNavbar::fillData() { - qDeleteAll(graphicsScene->items()); +// qDeleteAll(graphicsScene->items()); + graphicsScene->clear(); cursorGraphicsItem = nullptr; int from = blockMaps.first()["from"].toInt(); int to = blockMaps.first()["to"].toInt(); // Prepare the graph scene - int w = this->codeGraphic->width(); - int h = this->codeGraphic->height(); + int w = this->graphicsView->width(); + int h = this->graphicsView->height(); - const QBrush bg = QBrush(QColor(74, 74, 74)); - - graphicsScene->setBackgroundBrush(bg); - this->codeGraphic->setRenderHints(0); - this->codeGraphic->setScene(graphicsScene); - this->codeGraphic->setRenderHints(QPainter::Antialiasing); - this->codeGraphic->setToolTip("gap"); - RVA current_address = Core()->getOffset(); @@ -195,11 +196,14 @@ void GraphicsBar::fillData() } x_start = x_end; } + // Update scene width + graphicsScene->setSceneRect(graphicsScene->itemsBoundingRect()); + // Draw cursor drawCursor(); } -void GraphicsBar::drawCursor() +void VisualNavbar::drawCursor() { RVA offset = Core()->getOffset(); double cursor_x = addressToLocalX(offset); @@ -207,19 +211,20 @@ void GraphicsBar::drawCursor() { graphicsScene->removeItem(cursorGraphicsItem); delete cursorGraphicsItem; + cursorGraphicsItem = nullptr; } - if (cursor_x == nan("")) + if (isnan(cursor_x)) { return; } - int h = this->codeGraphic->height(); + int h = this->graphicsView->height(); cursorGraphicsItem = new QGraphicsRectItem(cursor_x, 0, 2, h); cursorGraphicsItem->setPen(Qt::NoPen); cursorGraphicsItem->setBrush(QBrush(QColor(255, 0, 0))); graphicsScene->addItem(cursorGraphicsItem); } -QString GraphicsBar::generateTooltip(QString section_name, QMap map) +QString VisualNavbar::generateTooltip(QString section_name, QMap map) { QString ret = ""; ret += "Offset: 0x" + QString::number(map["offset"].toInt(), 16) + "\n"; @@ -235,26 +240,26 @@ QString GraphicsBar::generateTooltip(QString section_name, QMapdrawCursor(); } -void GraphicsBar::mousePressEvent(QMouseEvent *event) +void VisualNavbar::mousePressEvent(QMouseEvent *event) { event->accept(); // Convert the local X coordinate to an address. qreal x = event->localPos().x(); RVA address = localXToAddress(x); - if(address != 0) + if(address != RVA_INVALID) { Core()->seek(address); } } -RVA GraphicsBar::localXToAddress(double x) +RVA VisualNavbar::localXToAddress(double x) { for(auto x2a : xToAddress) { @@ -265,10 +270,10 @@ RVA GraphicsBar::localXToAddress(double x) return x2a.address_from + (offset * size); } } - return 0; + return RVA_INVALID; } -double GraphicsBar::addressToLocalX(RVA address) +double VisualNavbar::addressToLocalX(RVA address) { for(auto x2a : xToAddress) { diff --git a/src/widgets/CodeGraphic.h b/src/widgets/VisualNavbar.h similarity index 83% rename from src/widgets/CodeGraphic.h rename to src/widgets/VisualNavbar.h index ee95e9da..d7b4d26f 100644 --- a/src/widgets/CodeGraphic.h +++ b/src/widgets/VisualNavbar.h @@ -1,5 +1,5 @@ -#ifndef GRAPHICSBAR_H -#define GRAPHICSBAR_H +#ifndef VISUALNAVBAR_H +#define VISUALNAVBAR_H #include #include @@ -9,7 +9,7 @@ class MainWindow; class QGraphicsView; -class GraphicsBar : public QToolBar +class VisualNavbar : public QToolBar { Q_OBJECT @@ -21,7 +21,7 @@ class GraphicsBar : public QToolBar }; public: - explicit GraphicsBar(MainWindow *main, QWidget *parent = 0); + explicit VisualNavbar(MainWindow *main, QWidget *parent = 0); public slots: void paintEvent(QPaintEvent *event) override; @@ -34,7 +34,7 @@ private slots: void on_seekChanged(RVA addr); private: - QGraphicsView *codeGraphic; + QGraphicsView *graphicsView; QGraphicsScene *graphicsScene; QGraphicsRectItem *cursorGraphicsItem; MainWindow *main; @@ -54,4 +54,4 @@ private: void mousePressEvent(QMouseEvent *event) override; }; -#endif // GRAPHICSBAR_H +#endif // VISUALNAVBAR_H