mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 19:36:11 +00:00
Move graph header to GraphWidget. (#1628)
* prevents layout problems * fix header change when doubleclicking in unsynchronized function
This commit is contained in:
parent
5758ffcafb
commit
552021c38d
@ -157,19 +157,9 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent, CutterSeekable* se
|
||||
|
||||
connect(blockMenu, &DisassemblyContextMenu::copy, this, &DisassemblerGraphView::copySelection);
|
||||
|
||||
header = new QTextEdit();
|
||||
header->setFixedHeight(30);
|
||||
header->setReadOnly(true);
|
||||
header->setLineWrapMode(QTextEdit::NoWrap);
|
||||
|
||||
// Add header as widget to layout so it stretches to the layout width
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
layout->addWidget(header);
|
||||
|
||||
prepareHeader();
|
||||
|
||||
highlighter = new SyntaxHighlighter(header->document());
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::connectSeekChanged(bool disconn)
|
||||
@ -395,17 +385,6 @@ void DisassemblerGraphView::cleanupEdges()
|
||||
}
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::prepareHeader()
|
||||
{
|
||||
QString afcf = Core()->cmd("afcf").trimmed();
|
||||
if (afcf.isEmpty()) {
|
||||
header->hide();
|
||||
return;
|
||||
}
|
||||
header->show();
|
||||
header->setPlainText(afcf);
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::initFont()
|
||||
{
|
||||
setFont(Config()->getFont());
|
||||
@ -783,9 +762,6 @@ void DisassemblerGraphView::onSeekChanged(RVA addr)
|
||||
transition_dont_seek = true;
|
||||
showBlock(&blocks[db->entry], !switchFunction);
|
||||
showInstruction(blocks[db->entry], addr);
|
||||
prepareHeader();
|
||||
} else {
|
||||
header->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,6 @@ public:
|
||||
|
||||
void loadCurrentGraph();
|
||||
QString windowTitle;
|
||||
QTextEdit *header = nullptr;
|
||||
|
||||
int getWidth() { return width; }
|
||||
int getHeight() { return height; }
|
||||
@ -157,7 +156,6 @@ private:
|
||||
void initFont();
|
||||
void prepareGraphNode(GraphBlock &block);
|
||||
void cleanupEdges();
|
||||
void prepareHeader();
|
||||
Token *getToken(Instr *instr, int x);
|
||||
QPoint getTextOffset(int line) const;
|
||||
QPoint getInstructionOffset(const DisassemblyBlock &block, int line) const;
|
||||
@ -206,8 +204,6 @@ private:
|
||||
QAction actionSyncOffset;
|
||||
|
||||
QLabel *emptyText = nullptr;
|
||||
SyntaxHighlighter *highlighter = nullptr;
|
||||
|
||||
signals:
|
||||
void viewRefreshed();
|
||||
void viewZoomed();
|
||||
|
@ -424,10 +424,14 @@ void GraphView::showRectangle(const QRect &block, bool anywhere)
|
||||
if (height * current_scale <= viewport()->height()) {
|
||||
centerY(false);
|
||||
} else {
|
||||
static const int HEADER_HEIGHT = 35; // this could be handled better
|
||||
if (!anywhere || block.y() < offset.y() + HEADER_HEIGHT
|
||||
if (!anywhere || block.y() < offset.y()
|
||||
|| block.bottom() > offset.y() + renderSize.height()) {
|
||||
offset.ry() = block.y() - HEADER_HEIGHT / current_scale;
|
||||
offset.ry() = block.y();
|
||||
// Leave some space at top if possible
|
||||
const qreal topPadding = 10 / current_scale;
|
||||
if (block.height() + topPadding < renderSize.height()) {
|
||||
offset.ry() -= topPadding;
|
||||
}
|
||||
}
|
||||
}
|
||||
clampViewOffset();
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "GraphWidget.h"
|
||||
#include "DisassemblerGraphView.h"
|
||||
#include "WidgetShortcuts.h"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
||||
MemoryDockWidget(CutterCore::MemoryWidgetType::Graph, main, action)
|
||||
@ -11,8 +12,19 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
||||
: getWidgetType());
|
||||
|
||||
setAllowedAreas(Qt::AllDockWidgetAreas);
|
||||
graphView = new DisassemblerGraphView(this, seekable);
|
||||
setWidget(graphView);
|
||||
|
||||
auto *layoutWidget = new QWidget(this);
|
||||
setWidget(layoutWidget);
|
||||
auto *layout = new QVBoxLayout(layoutWidget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layoutWidget->setLayout(layout);
|
||||
|
||||
header = new QLineEdit(this);
|
||||
header->setReadOnly(true);
|
||||
layout->addWidget(header);
|
||||
|
||||
graphView = new DisassemblerGraphView(layoutWidget, seekable);
|
||||
layout->addWidget(graphView);
|
||||
|
||||
// getting the name of the class is implementation defined, and cannot be
|
||||
// used reliably across different compilers.
|
||||
@ -36,6 +48,8 @@ GraphWidget::GraphWidget(MainWindow *main, QAction *action) :
|
||||
connect(graphView, &DisassemblerGraphView::graphMoved, this, [ = ]() {
|
||||
main->toggleOverview(true, this);
|
||||
});
|
||||
connect(seekable, &CutterSeekable::seekableSeekChanged, this, &GraphWidget::prepareHeader);
|
||||
connect(Core(), &CutterCore::functionRenamed, this, &GraphWidget::prepareHeader);
|
||||
}
|
||||
|
||||
QWidget *GraphWidget::widgetToFocusOnRaise()
|
||||
@ -63,3 +77,15 @@ QString GraphWidget::getWidgetType()
|
||||
{
|
||||
return "Graph";
|
||||
}
|
||||
|
||||
void GraphWidget::prepareHeader()
|
||||
{
|
||||
QString afcf = Core()->cmd(QString("afcf @%1").arg(seekable->getOffset())).trimmed();
|
||||
if (afcf.isEmpty()) {
|
||||
header->hide();
|
||||
return;
|
||||
}
|
||||
header->show();
|
||||
header->setText(afcf);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define GRAPHWIDGET_H
|
||||
|
||||
#include "MemoryDockWidget.h"
|
||||
#include <QLineEdit>
|
||||
|
||||
class MainWindow;
|
||||
class DisassemblerGraphView;
|
||||
@ -28,8 +29,10 @@ private:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
QString getWindowTitle() const override;
|
||||
void prepareHeader();
|
||||
|
||||
DisassemblerGraphView *graphView;
|
||||
QLineEdit *header = nullptr;
|
||||
};
|
||||
|
||||
#endif // GRAPHWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user