-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMemWindow.cpp
216 lines (178 loc) · 5.88 KB
/
MemWindow.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "MemWindow.h"
#include "QVBoxLayout"
#include "QHBoxLayout"
#include "QString"
#include "QCompleter"
#include "Utility.h"
MemWindow::MemWindow(modeler *model, HighlightScrollBar* scroll, QWidget *parent,QString* buttonName) : QWidget(parent)
{
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->setContentsMargins(0,0,0,0);
Label = new QLabel("Memory View");
Label->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
Input = new QLineEdit(this);
Input->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
Input->setMaximumHeight(20);
setupInput();
GotoButton = new QPushButton("GOTO",this);
GotoButton->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Fixed);
GotoButton->setMinimumWidth(40);
GotoButton->setContentsMargins(0,0,0,0);
/*
* What I am about to initialize is a "Follow Button".
*
* The only difference between a Follow Button and a Push Button is that
* the Follow Button sends out a signal whenever it is double clicked.
*/
SpecialButton = new FollowButton(*buttonName);
SpecialButton->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed);
SpecialButton->setMaximumWidth(23);
SpecialButton->setMaximumHeight(23);
Label->setContentsMargins(0,0,0,0);
hLayout->addWidget(Label);
hLayout->addWidget(Input);
hLayout->addWidget(GotoButton);
hLayout->addWidget(SpecialButton);
View = new MemTable(model,this);
View->setContentsMargins(0,0,0,0);
View->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
View->setMinimumHeight(10);
QVBoxLayout* vLayout = new QVBoxLayout(this);
vLayout->addLayout(hLayout);
vLayout->setContentsMargins(0,0,0,0);
vLayout->addWidget(View);
setLayout(vLayout);
vLayout->setSpacing(0);
hLayout->setSpacing(0);
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
/*
* Connections
*/
//Since it feels natural to hit enter to enter the number
connect(Input,SIGNAL(returnPressed()),GotoButton,SLOT(click()));
//Making the Input Buttons Function
connect(SpecialButton,SIGNAL(pressed()),this,SLOT(handleSRPress()));
connect(GotoButton,SIGNAL(pressed()),this,SLOT(handleGotoPress()));
connect(SpecialButton,SIGNAL(doubleClicked()), this,SLOT(handleTracking()));
//
SpecialButton->setStyleSheet(QString::fromUtf8("QPushButton:pressed"
"{ color: yellow }"
));
}
void MemWindow::setupInput()
{
labelDict = std::map<QString,uint16_t>();
QStringList suggestions;
#define SUGGEST(KEY,VALUE)\
suggestions<<(KEY);\
labelDict[KEY] = (VALUE);
for(val_t i = 0;i!=MEMSIZE;i++)
{
label_t* lab = Computer::getDefault()->getMemLabel(i);
if(lab)
{
SUGGEST(lab->name,i)
}
}
for(int i =0;i<8/*number of general purpose registers*/;i++)
{
const QString reg ="r"+QString().setNum(i);
SUGGEST(reg,Computer::getDefault()->getRegister((reg_t)i))
// suggestions<<reg;
// labelDict[reg]= Computer::getDefault()->getRegister((reg_t)i);
}
SUGGEST("PC",Computer::getDefault()->getRegister(PC))
SUGGEST("SP",Computer::getDefault()->getRegister(SPR))
QCompleter searchCompleter(suggestions,this);
searchCompleter.setCaseSensitivity(Qt::CaseInsensitive);
searchCompleter.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
Input->setCompleter(&searchCompleter);
// connect(searchCompleter,&QCompleter::activated)
}
MemTable *MemWindow::getMemView()
{
return View;
}
void MemWindow::setFlipped(bool upIsDown)
{
View->setFlipped(upIsDown);
if(upIsDown)
{
SpecialReg = SPR;
SpecialButton->setText("SP");
QString red = QString().setNum(R6COLOR.red());
QString green = QString().setNum(R6COLOR.green());
QString blue = QString().setNum(R6COLOR.blue());
SpecialButton->setStyleSheet("QPushButton:pressed{ color: rgb(" +red + "," + green + "," + blue +")}");
}
else
{
SpecialReg = PC;
SpecialButton->setText("PC");
SpecialButton->setStyleSheet(QString::fromUtf8("QPushButton:pressed"
"{ color: yellow }"
));
}
}
void MemWindow::handleSRPress()
{
val_t target_address = Computer::getDefault()->getRegister(SpecialReg);
View->scrollToRow(target_address);
}
void MemWindow::handleGotoPress()
{
bool ok = true;
int target = Utility::unifiedInput2Val(Input->text(),&ok);
if(ok)
{
View->scrollToRow(target);
}
else
{
const QString text = Input->text();
if(labelDict.find(text)!=labelDict.end())
{
View->scrollToRow(labelDict[text]);
}
}
CLEAR(Input);
}
void MemWindow::handleTracking()
{
qDebug("double");
followmode=!followmode;
QString red = QString().setNum(R6COLOR.red());
QString green = QString().setNum(R6COLOR.green());
QString blue = QString().setNum(R6COLOR.blue());
QString r6colorString = "rgb(" +red + "," + green + "," + blue +")}";
QString color;
switch(SpecialReg)
{
case PC:
color = "yellow";
break;
case R6:
color = r6colorString;
break;
default:
color = "white";
}
SpecialButton->setStyleSheet(QString("QPushButton:enabled"
"{ Background-color: ")+QString((followmode)?color:"light grey")+QString("}")
);
// PCButton->setStyleSheet("{background-color:rgb(150,150,255)}");
}
void MemWindow::setSpecialReg(reg_t reg)
{
SpecialReg = reg;
}
void MemWindow::kick()
{
View->hide();
View->show();
if(followmode)
{
handleSRPress();
}
setupInput();
}