| 1 | // File: assemblerlistingpane.cpp |
| 2 | /* |
| 3 | Pep8-1 is a virtual machine for writing machine language and assembly |
| 4 | language programs. |
| 5 | |
| 6 | Copyright (C) 2009 J. Stanley Warford, Pepperdine University |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include <QScrollBar> |
| 23 | #include <QFontDialog> |
| 24 | #include "assemblerlistingpane.h" |
| 25 | #include "ui_assemblerlistingpane.h" |
| 26 | #include "pep.h" |
| 27 | |
| 28 | #include <QMouseEvent> |
| 29 | |
| 30 | AssemblerListingPane::AssemblerListingPane(QWidget *parent) : |
| 31 | QWidget(parent), |
| 32 | ui(new Ui::AssemblerListingPane) |
| 33 | { |
| 34 | ui->setupUi(this); |
| 35 | |
| 36 | pepHighlighter = new PepHighlighter(ui->textEdit->document()); |
| 37 | |
| 38 | ui->label->setFont(QFont(Pep::labelFont, Pep::labelFontSize)); |
| 39 | ui->textEdit->setFont(QFont(Pep::codeFont, Pep::codeFontSize)); |
| 40 | } |
| 41 | |
| 42 | AssemblerListingPane::~AssemblerListingPane() |
| 43 | { |
| 44 | delete ui; |
| 45 | } |
| 46 | |
| 47 | void AssemblerListingPane::setAssemblerListing(QStringList assemblerListingList) { |
| 48 | clearAssemblerListing(); |
| 49 | ui->textEdit->append("-------------------------------------------------------------------------------"); |
| 50 | ui->textEdit->append(" Object"); |
| 51 | ui->textEdit->append("Addr code Symbol Mnemon Operand Comment"); |
| 52 | ui->textEdit->append("-------------------------------------------------------------------------------"); |
| 53 | ui->textEdit->append(assemblerListingList.join("\n")); |
| 54 | ui->textEdit->append("-------------------------------------------------------------------------------"); |
| 55 | if (Pep::symbolTable.size() > 0) { |
| 56 | ui->textEdit->append(""); |
| 57 | ui->textEdit->append(""); |
| 58 | ui->textEdit->append("Symbol table"); |
| 59 | ui->textEdit->append("--------------------------------------"); |
| 60 | ui->textEdit->append("Symbol Value Symbol Value"); |
| 61 | ui->textEdit->append("--------------------------------------"); |
| 62 | QMapIterator<QString, int> i(Pep::symbolTable); |
| 63 | QString symbolTableLine = ""; |
| 64 | QString hexString; |
| 65 | while (i.hasNext()) { |
| 66 | i.next(); |
| 67 | hexString = QString("%1").arg(i.value(), 4, 16, QLatin1Char('0')).toUpper(); |
| 68 | if (symbolTableLine.length() == 0) { |
| 69 | symbolTableLine = QString("%1%2").arg(i.key(), -10).arg(hexString, -13); |
| 70 | } |
| 71 | else { |
| 72 | symbolTableLine.append(QString("%1%2").arg(i.key(), -10).arg(hexString, -4)); |
| 73 | ui->textEdit->append(symbolTableLine); |
| 74 | symbolTableLine = ""; |
| 75 | } |
| 76 | } |
| 77 | if (symbolTableLine.length() > 0) { |
| 78 | ui->textEdit->append(symbolTableLine); |
| 79 | } |
| 80 | ui->textEdit->append("--------------------------------------"); |
| 81 | } |
| 82 | ui->textEdit->verticalScrollBar()->setValue(ui->textEdit->verticalScrollBar()->minimum()); |
| 83 | } |
| 84 | |
| 85 | void AssemblerListingPane::clearAssemblerListing() |
| 86 | { |
| 87 | ui->textEdit->clear(); |
| 88 | } |
| 89 | |
| 90 | bool AssemblerListingPane::isModified() |
| 91 | { |
| 92 | return ui->textEdit->document()->isModified(); |
| 93 | } |
| 94 | |
| 95 | QString AssemblerListingPane::toPlainText() |
| 96 | { |
| 97 | return ui->textEdit->toPlainText(); |
| 98 | } |
| 99 | |
| 100 | void AssemblerListingPane::setCurrentFile(QString string) |
| 101 | { |
| 102 | if (!string.isEmpty()) { |
| 103 | ui->label->setText("Assembler Listing - " + string); |
| 104 | } |
| 105 | else { |
| 106 | ui->label->setText("Assembler Listing - untitled.pepl"); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void AssemblerListingPane::highlightOnFocus() |
| 111 | { |
| 112 | if (ui->textEdit->hasFocus()) { |
| 113 | ui->label->setAutoFillBackground(true); |
| 114 | } |
| 115 | else { |
| 116 | ui->label->setAutoFillBackground(false); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | bool AssemblerListingPane::hasFocus() |
| 121 | { |
| 122 | return ui->textEdit->hasFocus(); |
| 123 | } |
| 124 | |
| 125 | void AssemblerListingPane::copy() |
| 126 | { |
| 127 | ui->textEdit->copy(); |
| 128 | } |
| 129 | |
| 130 | void AssemblerListingPane::setFocus() |
| 131 | { |
| 132 | ui->textEdit->setFocus(); |
| 133 | } |
| 134 | |
| 135 | bool AssemblerListingPane::isEmpty() |
| 136 | { |
| 137 | return ui->textEdit->toPlainText() == ""; |
| 138 | } |
| 139 | |
| 140 | void AssemblerListingPane::onFontChanged(QFont font) |
| 141 | { |
| 142 | ui->textEdit->setFont(font); |
| 143 | } |
| 144 | |
| 145 | void AssemblerListingPane::mouseReleaseEvent(QMouseEvent *) |
| 146 | { |
| 147 | ui->textEdit->setFocus(); |
| 148 | } |
| 149 | |
| 150 | void AssemblerListingPane::mouseDoubleClickEvent(QMouseEvent *) |
| 151 | { |
| 152 | emit labelDoubleClicked(Enu::EListing); |
| 153 | } |