From 7262d30e9e689aaacd7926c90d953ab86cd9cfa7 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 2 Jul 2019 18:07:37 +0200 Subject: Implement load of sources in emscripten build and minor fixes. Signed-off-by: Pavel Pisa --- qtmips_gui/mainwindow.cpp | 17 ++++++++++++++++- qtmips_gui/srceditor.cpp | 23 +++++++++++++++++++++-- qtmips_gui/srceditor.h | 2 ++ 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'qtmips_gui') diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 58a0173..e3ad8dd 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -51,6 +51,11 @@ #include "gotosymboldialog.h" #include "fixmatheval.h" +#ifdef __EMSCRIPTEN__ +#include +#include "qhtml5file.h" +#endif + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { machine = nullptr; corescene = nullptr; @@ -491,6 +496,7 @@ void MainWindow::new_source() { } void MainWindow::open_source() { +#ifndef __EMSCRIPTEN__ QString file_name = ""; file_name = QFileDialog::getOpenFileName(this, tr("Open File"), "", "Source Files (*.asm *.S *.s)"); @@ -506,6 +512,15 @@ void MainWindow::open_source() { delete(editor); } } +#else + QHtml5File::load("*", [&](const QByteArray &content, const QString &filename) { + SrcEditor *editor = new SrcEditor(); + editor->loadByteArray(content, filename); + central_window->addTab(editor, editor->title()); + central_window->setCurrentWidget(editor); + connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(tab_widget_destroyed(QObject*))); + }); +#endif } void MainWindow::save_source_as() { @@ -584,7 +599,7 @@ static std::uint64_t string_to_uint64(QString str, int base, } void MainWindow::compile_source() { - SymbolTableDb symtab(machine->symbol_table()); + SymbolTableDb symtab(machine->symbol_table(true)); int error_line = 0; if (current_srceditor == nullptr) return; diff --git a/qtmips_gui/srceditor.cpp b/qtmips_gui/srceditor.cpp index 2f4d3a6..e8bdb85 100644 --- a/qtmips_gui/srceditor.cpp +++ b/qtmips_gui/srceditor.cpp @@ -41,12 +41,21 @@ #include "srceditor.h" -SrcEditor::SrcEditor(QWidget *parent) : Super(parent) { +void SrcEditor::setup_common() { + QFont font; + font.setFamily("Courier"); + font.setFixedPitch(true); + font.setPointSize(10); + setFont(font); tname = "Unknown"; } +SrcEditor::SrcEditor(QWidget *parent) : Super(parent) { + setup_common(); +} + SrcEditor::SrcEditor(const QString &text, QWidget *parent) : Super(text, parent) { - tname = "Unknown"; + setup_common(); } SrcEditor::~SrcEditor() { @@ -74,6 +83,16 @@ bool SrcEditor::loadFile(QString filename) { } } +bool SrcEditor::loadByteArray(const QByteArray &content, QString filename) { + setPlainText(QString::fromUtf8(content.data(), content.size())); + if (!filename.isEmpty()) { + QFileInfo fi(filename); + fname = filename; + tname = fi.fileName(); + } + return true; +} + bool SrcEditor::saveFile(QString filename) { if (filename.isEmpty()) filename = this->filename(); diff --git a/qtmips_gui/srceditor.h b/qtmips_gui/srceditor.h index a727f99..9d25be7 100644 --- a/qtmips_gui/srceditor.h +++ b/qtmips_gui/srceditor.h @@ -51,8 +51,10 @@ public: QString title(); bool loadFile(QString filename); bool saveFile(QString filename = ""); + bool loadByteArray(const QByteArray &content, QString filename = ""); void setCursorToLine(int ln); private: + void setup_common(); QString fname; QString tname; }; -- cgit v1.2.3