-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobjectcodepane.cpp
More file actions
115 lines (93 loc) · 3.2 KB
/
objectcodepane.cpp
File metadata and controls
115 lines (93 loc) · 3.2 KB
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
// File: objectcodepane.cpp
/*
Pep8CPU is a CPU simulator for executing microcode sequences to
implement instructions in the instruction set of the Pep/8 computer.
Copyright (C) 2010 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 "objectcodepane.h"
#include "ui_objectcodepane.h"
#include "sim.h"
#include "pep.h"
#include <QPainter>
#include <QDebug>
ObjectCodePane::ObjectCodePane(QWidget *parent) :
QWidget(parent),
ui(new Ui::ObjectCodePane)
{
ui->setupUi(this);
QFont font(Pep::codeFont);
font.setPointSize(Pep::codeFontSize);
font.setStyleHint(QFont::TypeWriter);
ui->plainTextEdit->setFont(font);
cpuLabel = new ObjectCodeLabel(this);
ui->verticalLayout->insertWidget(1, cpuLabel);
cpuLabel->setFont(QFont(Pep::codeFont, Pep::codeFontSize));
cpuLabel->setMinimumHeight(QFontMetrics(cpuLabel->font()).averageCharWidth() * 8 + 3); // +3 for padding
}
ObjectCodePane::~ObjectCodePane()
{
delete ui;
}
void ObjectCodePane::setObjectCode(QString string)
{
ui->plainTextEdit->setPlainText(string);
}
void ObjectCodePane::highlightCurrentInstruction()
{
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
selection.format.setBackground(QColor(56, 117, 215)); // dark blue
selection.format.setForeground(Qt::white);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
QTextCursor cursor = QTextCursor(ui->plainTextEdit->document());
cursor.setPosition(0);
for (int i = 0; i < Sim::microProgramCounter; i++) {
cursor.movePosition(QTextCursor::NextBlock);
}
// this chunk moves the cursor down and scrolls the text edit to it:
ui->plainTextEdit->setTextCursor(cursor);
ui->plainTextEdit->ensureCursorVisible();
selection.cursor = cursor;
selection.cursor.clearSelection();
extraSelections.append(selection);
ui->plainTextEdit->setExtraSelections(extraSelections);
}
void ObjectCodePane::clearSimulationView()
{
QList<QTextEdit::ExtraSelection> extraSelections;
ui->plainTextEdit->setExtraSelections(extraSelections);
}
void ObjectCodePane::copy()
{
ui->plainTextEdit->copy();
}
void ObjectCodePane::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ObjectCodePane::highlightOnFocus()
{
if (ui->plainTextEdit->hasFocus()) {
ui->label->setAutoFillBackground(true);
}
else {
ui->label->setAutoFillBackground(false);
}
}