Work on program file tab
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -109,6 +109,7 @@ void MainWindow::on_actionLoadAssemblyFile_triggered() {
void MainWindow::loadBinaryFile(QString filename) {
const QString& output = Parser::getParser()->loadBinaryFile(filename);
+ m_ui->programfiletab->setInputMode(false);
m_ui->programfiletab->setDisassemblerText(output);
emit update();
}
@@ -116,6 +117,7 @@ void MainWindow::loadBinaryFile(QString filename) {
void MainWindow::loadAssemblyFile(QString fileName) {
// ... load file
QFile file(fileName);
+ m_ui->programfiletab->setInputMode(true);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->programfiletab->setAssemblyText(file.readAll());
file.close();

MODIFY
src/mainwindow.ui
src/mainwindow.ui
</property>
<widget class="QMenu" name="menuExamples">
<property name="title">
- <string>Load example...</string>
+ <string>Load Example...</string>
</property>
</widget>
<addaction name="actionLoadBinaryFile"/>
<addaction name="separator"/>
<addaction name="menuExamples"/>
<addaction name="separator"/>
+ <addaction name="actionSave_Assembly_File"/>
+ <addaction name="separator"/>
<addaction name="actionexit"/>
</widget>
<widget class="QMenu" name="menuSettings">
<normaloff>:/icons/loadfile.svg</normaloff>:/icons/loadfile.svg</iconset>
</property>
<property name="text">
- <string>Load binary file</string>
+ <string>Load Binary File</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
<string>Documentation</string>
</property>
</action>
+ <action name="actionSave_Assembly_File">
+ <property name="icon">
+ <iconset resource="../resources/images.qrc">
+ <normaloff>:/icons/save.svg</normaloff>:/icons/save.svg</iconset>
+ </property>
+ <property name="text">
+ <string>Save Assembly File</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>

MODIFY
src/programfiletab.cpp
src/programfiletab.cpp
@@ -10,6 +10,12 @@ ProgramfileTab::ProgramfileTab(QWidget* parent) : QWidget(parent), m_ui(new Ui::
m_ui->binaryedit->setReadOnly(true);
// enable breakpoint area for the translated code only
m_ui->binaryedit->enableBreakpointArea();
+
+ // Link scrollbars together for pleasant navigation
+ connect(m_ui->assemblyedit->verticalScrollBar(), &QScrollBar::valueChanged, m_ui->binaryedit->verticalScrollBar(),
+ &QScrollBar::setValue);
+ connect(m_ui->binaryedit->verticalScrollBar(), &QScrollBar::valueChanged, m_ui->assemblyedit->verticalScrollBar(),
+ &QScrollBar::setValue);
}
ProgramfileTab::~ProgramfileTab() {
@@ -34,3 +40,26 @@ void ProgramfileTab::setDisassemblerText(const QString& text) {
m_ui->binaryedit->clearBreakpoints();
m_ui->binaryedit->setPlainText(text);
}
+
+void ProgramfileTab::on_assemblyfile_toggled(bool checked) {
+ // handles toggling between assembly input and binary input
+ if (checked) {
+ m_ui->assemblyedit->setEnabled(true);
+ } else {
+ // Disable when loading binary files
+ m_ui->assemblyedit->setEnabled(false);
+ }
+
+ // clear both editors when switching input mode and reset the highlighter for the assembly editor
+ m_ui->assemblyedit->clear();
+ m_ui->assemblyedit->reset();
+ m_ui->binaryedit->clear();
+}
+
+void ProgramfileTab::setInputMode(bool isAssembly) {
+ if (isAssembly) {
+ m_ui->assemblyfile->setChecked(true);
+ } else {
+ m_ui->binaryfile->setChecked(true);
+ }
+}

MODIFY
src/programfiletab.h
src/programfiletab.h
@@ -17,6 +17,7 @@ public:
void setAssemblyText(const QString& text);
void setDisassemblerText(const QString& text);
+ void setInputMode(bool isAssembly);
signals:
void loadBinaryFile();
@@ -25,6 +26,8 @@ signals:
private slots:
void on_pushButton_clicked();
+ void on_assemblyfile_toggled(bool checked);
+
private:
Ui::ProgramfileTab* m_ui;
};

MODIFY
src/programfiletab.ui
src/programfiletab.ui
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
- <string>File type</string>
+ <string>Input type</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
- <widget class="QRadioButton" name="binaryfile">
+ <widget class="QRadioButton" name="assemblyfile">
<property name="text">
- <string>Binary file</string>
+ <string>Assembly</string>
</property>
<property name="checked">
<bool>true</bool>
</widget>
</item>
<item>
- <widget class="QRadioButton" name="assemblyfile">
+ <widget class="QRadioButton" name="binaryfile">
<property name="text">
- <string>Assembly file</string>
+ <string>Binary file</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
- <string>Translated code</string>
+ <string>Disassembled code</string>
</property>
</widget>
</item>

Work on program file tab