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