Debian Codegraph @

objectcodepane.cpp

raw symbols SCIP
1 // File: objectcodepane.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 #include <QFontDialog>
22 #include "objectcodepane.h"
23 #include "ui_objectcodepane.h"
24 #include "pep.h"
25
26 ObjectCodePane::ObjectCodePane(QWidget *parent) :
27 QWidget(parent),
28 ui(new Ui::ObjectCodePane)
29 {
30 ui->setupUi(this);
31
32 connect(ui->textEdit->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setLabelToModified(bool)));
33
34 connect(ui->textEdit, SIGNAL(undoAvailable(bool)), this, SIGNAL(undoAvailable(bool)));
35 connect(ui->textEdit, SIGNAL(redoAvailable(bool)), this, SIGNAL(redoAvailable(bool)));
36
37 ui->label->setFont(QFont(Pep::labelFont, Pep::labelFontSize));
38 ui->textEdit->setFont(QFont(Pep::codeFont, Pep::codeFontSize));
39 }
40
41 ObjectCodePane::~ObjectCodePane()
42 {
43 delete ui;
44 }
45
46 void ObjectCodePane::setObjectCode(QList<int> objectCode)
47 {
48 QString objectCodeString = "";
49 for (int i = 0; i < objectCode.length(); i++) {
50 objectCodeString.append(QString("%1").arg(objectCode[i], 2, 16, QLatin1Char('0')).toUpper());
51 objectCodeString.append((i % 16) == 15 ? '\n' : ' ');
52 }
53 objectCodeString.append("zz");
54 ui->textEdit->clear();
55 ui->textEdit->setText(objectCodeString);
56 }
57
58 void ObjectCodePane::setObjectCodePaneText(QString string)
59 {
60 ui->textEdit->setText(string);
61 }
62
63 bool ObjectCodePane::getObjectCode(QList<int> &objectCodeList)
64 {
65 QString objectString = ui->textEdit->toPlainText();
66 while (objectString.length() > 0) {
67 if (objectString.at(1) == QChar('z')) {
68 return true;
69 }
70 if (objectString.length() < 3) {
71 return false;
72 }
73 QString s = objectString.left(2); // Get the two-char hex number
74 objectString.remove(0, 3); // Removes the number and trailing whitespace
75 bool ok;
76 objectCodeList.append(s.toInt(&ok, 16));
77 if (!ok) {
78 return false;
79 }
80 }
81 return false;
82 }
83
84 void ObjectCodePane::clearObjectCode()
85 {
86 ui->textEdit->clear();
87 }
88
89 bool ObjectCodePane::isModified()
90 {
91 return ui->textEdit->document()->isModified();
92 }
93
94 void ObjectCodePane::setModifiedFalse()
95 {
96 ui->textEdit->document()->setModified(false);
97 }
98
99 QString ObjectCodePane::toPlainText()
100 {
101 return ui->textEdit->toPlainText();
102 }
103
104 void ObjectCodePane::setCurrentFile(QString string)
105 {
106 if (!string.isEmpty()) {
107 ui->label->setText("Object Code - " + string);
108 }
109 else {
110 ui->label->setText("Object Code - untitled.pepo");
111 }
112 }
113
114 void ObjectCodePane::highlightOnFocus()
115 {
116 if (ui->textEdit->hasFocus()) {
117 ui->label->setAutoFillBackground(true);
118 }
119 else {
120 ui->label->setAutoFillBackground(false);
121 }
122 }
123
124 bool ObjectCodePane::hasFocus()
125 {
126 return ui->textEdit->hasFocus();
127 }
128
129 void ObjectCodePane::undo()
130 {
131 ui->textEdit->undo();
132 }
133
134 void ObjectCodePane::redo()
135 {
136 ui->textEdit->redo();
137 }
138
139 bool ObjectCodePane::isUndoable()
140 {
141 return ui->textEdit->document()->isUndoAvailable();
142 }
143
144 bool ObjectCodePane::isRedoable()
145 {
146 return ui->textEdit->document()->isRedoAvailable();
147 }
148
149 void ObjectCodePane::cut()
150 {
151 ui->textEdit->cut();
152 }
153
154 void ObjectCodePane::copy()
155 {
156 ui->textEdit->copy();
157 }
158
159 void ObjectCodePane::paste()
160 {
161 ui->textEdit->paste();
162 }
163
164 void ObjectCodePane::setReadOnly(bool b)
165 {
166 ui->textEdit->setReadOnly(b);
167 }
168
169 void ObjectCodePane::onFontChanged(QFont font)
170 {
171 ui->textEdit->setFont(font);
172 }
173
174 void ObjectCodePane::mouseReleaseEvent(QMouseEvent *)
175 {
176 ui->textEdit->setFocus();
177 }
178
179 void ObjectCodePane::mouseDoubleClickEvent(QMouseEvent *)
180 {
181 emit labelDoubleClicked(Enu::EObject);
182 }
183
184 void ObjectCodePane::setLabelToModified(bool modified)
185 {
186 QString temp = ui->label->text();
187 if (modified) {
188 ui->label->setText(temp.append(temp.endsWith(QChar('*')) ? "" : "*"));
189 }
190 else if (temp.endsWith(QChar('*'))) {
191 temp.chop(1);
192 ui->label->setText(temp);
193 }
194 }
195