mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 22:23:46 +00:00
Create PseudocodeWidget from .ui file, Refresh only on Button
This commit is contained in:
parent
84102a9d32
commit
3c2a7189bf
@ -1,4 +1,5 @@
|
|||||||
#include "PseudocodeWidget.h"
|
#include "PseudocodeWidget.h"
|
||||||
|
#include "ui_PseudocodeWidget.h"
|
||||||
|
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
@ -7,19 +8,16 @@
|
|||||||
#include "utils/SyntaxHighlighter.h"
|
#include "utils/SyntaxHighlighter.h"
|
||||||
#include "utils/TempConfig.h"
|
#include "utils/TempConfig.h"
|
||||||
|
|
||||||
PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags)
|
PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags) :
|
||||||
: QDockWidget(parent, flags)
|
QDockWidget(parent, flags),
|
||||||
, textEditWidget(new QTextEdit(this))
|
ui(new Ui::PseudocodeWidget)
|
||||||
, syntaxHighLighter( new SyntaxHighlighter(textEditWidget->document()))
|
|
||||||
{
|
{
|
||||||
setObjectName("PseudocodeWidget");
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
syntaxHighLighter = new SyntaxHighlighter(ui->textEdit->document());
|
||||||
|
|
||||||
textEditWidget->setParent(this);
|
|
||||||
setWidget(textEditWidget);
|
|
||||||
setupFonts();
|
setupFonts();
|
||||||
colorsUpdatedSlot();
|
colorsUpdatedSlot();
|
||||||
textEditWidget->setReadOnly(true);
|
|
||||||
textEditWidget->setLineWrapMode(QTextEdit::NoWrap);
|
|
||||||
|
|
||||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdated()));
|
||||||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
||||||
@ -34,7 +32,6 @@ PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags)
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
|
|
||||||
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
|
||||||
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
connect(this, &QDockWidget::visibilityChanged, this, [](bool visibility) {
|
||||||
if (visibility)
|
if (visibility)
|
||||||
@ -43,12 +40,11 @@ PseudocodeWidget::PseudocodeWidget(QWidget *parent, Qt::WindowFlags flags)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get alerted when there's a refresh
|
connect(ui->refreshButton, &QAbstractButton::clicked, this, [this]() {
|
||||||
connect(Core(), &CutterCore::refreshAll, this, [this]() {
|
|
||||||
refresh(Core()->getOffset());
|
refresh(Core()->getOffset());
|
||||||
});
|
});
|
||||||
|
|
||||||
refresh(Core()->getOffset());
|
refresh(RVA_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
PseudocodeWidget::PseudocodeWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
|
PseudocodeWidget::PseudocodeWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
|
||||||
@ -60,20 +56,21 @@ PseudocodeWidget::PseudocodeWidget(const QString &title, QWidget *parent, Qt::Wi
|
|||||||
PseudocodeWidget::~PseudocodeWidget() {}
|
PseudocodeWidget::~PseudocodeWidget() {}
|
||||||
|
|
||||||
|
|
||||||
void PseudocodeWidget::on_seekChanged(RVA addr)
|
|
||||||
{
|
|
||||||
refresh(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PseudocodeWidget::refresh(RVA addr)
|
void PseudocodeWidget::refresh(RVA addr)
|
||||||
{
|
{
|
||||||
|
if (addr == RVA_INVALID)
|
||||||
|
{
|
||||||
|
ui->textEdit->setText(tr("Click Refresh to generate Pseudocode from current offset."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const QString& decompiledCode = Core()->getDecompiledCode(addr);
|
const QString& decompiledCode = Core()->getDecompiledCode(addr);
|
||||||
if (decompiledCode.length() == 0)
|
if (decompiledCode.length() == 0)
|
||||||
{
|
{
|
||||||
textEditWidget->setText(tr("Cannot decompile at") + " " + RAddressString(addr) + " " + tr("(Not a function?)"));
|
ui->textEdit->setText(tr("Cannot decompile at") + " " + RAddressString(addr) + " " + tr("(Not a function?)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
textEditWidget->setText(decompiledCode);
|
ui->textEdit->setText(decompiledCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PseudocodeWidget::refreshPseudocode()
|
void PseudocodeWidget::refreshPseudocode()
|
||||||
@ -92,7 +89,7 @@ void PseudocodeWidget::raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType
|
|||||||
void PseudocodeWidget::setupFonts()
|
void PseudocodeWidget::setupFonts()
|
||||||
{
|
{
|
||||||
QFont font = Config()->getFont();
|
QFont font = Config()->getFont();
|
||||||
textEditWidget->setFont(font);
|
ui->textEdit->setFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PseudocodeWidget::fontsUpdated()
|
void PseudocodeWidget::fontsUpdated()
|
||||||
@ -102,9 +99,9 @@ void PseudocodeWidget::fontsUpdated()
|
|||||||
|
|
||||||
void PseudocodeWidget::colorsUpdatedSlot()
|
void PseudocodeWidget::colorsUpdatedSlot()
|
||||||
{
|
{
|
||||||
const QString textEditClassName(textEditWidget->metaObject()->className());
|
const QString textEditClassName(ui->textEdit->metaObject()->className());
|
||||||
QString styleSheet = QString(textEditClassName + " { background-color: %1; color: %2; }")
|
QString styleSheet = QString(textEditClassName + " { background-color: %1; color: %2; }")
|
||||||
.arg(ConfigColor("gui.background").name())
|
.arg(ConfigColor("gui.background").name())
|
||||||
.arg(ConfigColor("btext").name());
|
.arg(ConfigColor("btext").name());
|
||||||
textEditWidget->setStyleSheet(styleSheet);
|
ui->textEdit->setStyleSheet(styleSheet);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#include "cutter.h"
|
#include "cutter.h"
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class PseudocodeWidget;
|
||||||
|
}
|
||||||
|
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class SyntaxHighlighter;
|
class SyntaxHighlighter;
|
||||||
@ -20,19 +24,18 @@ public:
|
|||||||
~PseudocodeWidget();
|
~PseudocodeWidget();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_seekChanged(RVA addr);
|
|
||||||
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type);
|
||||||
void fontsUpdated();
|
void fontsUpdated();
|
||||||
void colorsUpdatedSlot();
|
void colorsUpdatedSlot();
|
||||||
void refreshPseudocode();
|
void refreshPseudocode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<Ui::PseudocodeWidget> ui;
|
||||||
|
|
||||||
|
SyntaxHighlighter *syntaxHighLighter;
|
||||||
|
|
||||||
void refresh(RVA addr);
|
void refresh(RVA addr);
|
||||||
void setupFonts();
|
void setupFonts();
|
||||||
|
|
||||||
private:
|
|
||||||
QTextEdit* textEditWidget;
|
|
||||||
SyntaxHighlighter* syntaxHighLighter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PSEUDOCODEWIDGET_H
|
#endif // PSEUDOCODEWIDGET_H
|
||||||
|
72
src/widgets/PseudocodeWidget.ui
Normal file
72
src/widgets/PseudocodeWidget.ui
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>PseudocodeWidget</class>
|
||||||
|
<widget class="QDockWidget" name="PseudocodeWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>DockWidget</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="textEdit">
|
||||||
|
<property name="lineWrapMode">
|
||||||
|
<enum>QTextEdit::NoWrap</enum>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="refreshButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Refresh</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user