-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopdialog.cpp
More file actions
221 lines (205 loc) · 7.65 KB
/
Copy pathshopdialog.cpp
File metadata and controls
221 lines (205 loc) · 7.65 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
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
215
216
217
218
219
220
221
#include <QDebug>
#include <QFont>
#include "shopdialog.h"
#include "ui_shopdialog.h"
ShopDialog::ShopDialog(Settings* settings,QWidget *parent) :
QDialog(parent),
ui(new Ui::ShopDialog)
{
ui->setupUi(this);
s = settings;
checkBoxes["fontSize1"]=ui->checkBoxFontSize1;
checkBoxes["fontSize2"]=ui->checkBoxFontSize2;
checkBoxes["fontSize3"]=ui->checkBoxFontSize3;
checkBoxes["wordSpacing"]=ui->checkBoxWordSpacing;
checkBoxes["fontFamily1"]=ui->checkBoxFontFamily1;
checkBoxes["fontFamily2"]=ui->checkBoxFontFamily2;
checkBoxes["contrast1"]=ui->checkBoxContrast1;
checkBoxes["contrast2"]=ui->checkBoxContrast2;
checkBoxes["contrast3"]=ui->checkBoxContrast3;
checkBoxes["pageUpDown"]=ui->checkBoxPageUpDown;
checkBoxes["keyboardInteraction"]=ui->checkBoxKeyboardNavigation;
checkBoxes["mouseInteraction"]=ui->checkBoxMouseNavigation;
checkBoxes["statusBar"]=ui->checkBoxStatusBar;
checkBoxes["lineNumber"]=ui->checkBoxLineNumber;
checkBoxes["columnNumber"]=ui->checkBoxColumnNumber;
checkBoxes["credits"]=ui->checkBoxCredits;
checkBoxes["paste"]=ui->checkBoxPaste;
checkBoxes["undoRedo"]=ui->checkBoxUndoRedo;
checkBoxes["backspace"]=ui->checkBoxBackspace;
checkBoxes["showPrices"]=ui->checkBoxShowPrices;
checkBoxes["cheaperKeystrokes1"]=ui->checkBoxCheaperKeystrokes1;
checkBoxes["cheaperKeystrokes2"]=ui->checkBoxCheaperKeystrokes2;
checkBoxes["readOnly"]=ui->checkBoxReadOnly;
checkBoxes["saveOnSubmit"]=ui->checkBoxSaveOnSubmit;
checkBoxes["showCompilationStatus"]=ui->checkBoxShowCompilationStatus;
checkBoxes["showCompilationWarnings"]=ui->checkBoxShowCompilationWarnings;
checkBoxes["compileOnly"]=ui->checkBoxCompileOnly;
checkBoxes["manualTest"]=ui->checkBoxManualTest;
checkBoxes["showLog"]=ui->checkBoxShowLog;
checkBoxes["showFullLog"]=ui->checkBoxFullLog;
checkBoxes["showTaskDescription"]=ui->checkBoxShowProblemStatement;
checkBoxes["ctrln"]=ui->checkBoxCtrln;
checkBoxes["resizeVertical"]=ui->checkBoxResizeVertical;
checkBoxes["resizeHorizontal"]=ui->checkBoxResizeHorizontal;
checkBoxes["screensaver"]=ui->checkBoxScreensaver;
checkBoxes["delay1"]=ui->checkBoxDelay1;
checkBoxes["delay2"]=ui->checkBoxDelay2;
checkBoxes["synchronize"]=ui->checkBoxSynchronize;
checkBoxes["memoryLimit"]=ui->checkBoxMemoryLimit;
QFont font("Arial", 10);
QMapIterator<QString, QCheckBox*> i(checkBoxes);
while(i.hasNext()){
i.next();
connect(i.value(),SIGNAL(toggled(bool)),this,SLOT(reload()));
i.value()->raise();
i.value()->setFont(font);
i.value()->adjustSize();
}
reqs["lineNumber"] << "statusBar";
reqs["columnNumber"] << "statusBar";
reqs["credits"] << "statusBar";
reqs["fontSize2"] << "fontSize1";
reqs["fontSize3"] << "fontSize1" << "fontSize2";
reqs["fontFamily2"] << "fontFamily1";
reqs["contrast2"] << "contrast1";
reqs["contrast3"] << "contrast1" << "contrast2";
reqs["cheaperKeystrokes2"] << "cheaperKeystrokes1";
reqs["showCompilationWarnings"] << "showCompilationStatus";
reqs["compileOnly"] << "showCompilationStatus";
reqs["manualTest"] << "compileOnly";
reqs["showLog"] << "showCompilationStatus";
reqs["showFullLog"] << "showLog" << "manualTest";
reqs["keyboardInteraction"] << "pageUpDown";
reqs["backspace"] << "ctrln";
reqs["resizeHorizontal"] << "resizeVertical";
reqs["delay2"] << "delay1" << "synchronize";
if(s->getBool("upgrades/showPrices"))
addPrices();
}
ShopDialog::~ShopDialog()
{
delete ui;
}
void ShopDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void ShopDialog::addPrices(){
QMapIterator<QString, QCheckBox*> i(checkBoxes);
while(i.hasNext()){
i.next();
i.value()->setText(i.value()->text() + " (" + QString::number(s->getInt("prices/"+i.key())) + ")");
i.value()->adjustSize();
}
}
void ShopDialog::show(){
reset();
checkAvailability();
QDialog::show();
}
void ShopDialog::reload(){
QString propClicked = "";
if(this->sender()){
propClicked = this->checkBoxToPropName((QCheckBox*)this->sender());
}
if(!checkBoxes.keys().contains(propClicked))qDebug("Zle priradenie checkboxu");
if(checkBoxes[propClicked]->isChecked())
credits -= s->getInt("prices/"+propClicked);
else
credits += s->getInt("prices/"+propClicked);
// credits sa upravuje len lokalne, aby sa upravilo availability, realne sa znizia credits az vo fcii accept
checkAvailability();
}
void ShopDialog::accept(){
QMapIterator<QString, QCheckBox*> i(checkBoxes);
while(i.hasNext()){
i.next();
if(i.value()->isChecked() && !s->getBool("upgrades/"+i.key())){
upgrade(i.key());
}
}
s->setProp("credits/count",credits);
QDialog::accept();
}
void ShopDialog::checkAvailability(){
/*
podla tabulky:
zaskrtnute mamNaTo mamTo-------DIS
zaskrtnute mamNaTo nemamTo-----OK (ale len ak to nie je req pre iny checknuty checkbox)
zaskrtnute nemamNaTo mamTo-----DIS
zaskrtnute nemamNaTo nemamTo---OK
nezaskrtnute mamNaTo mamTo-----WTF
nezaskrtnute mamNaTo nemamTo---OK
nezaskrtnute nemamNaTo mamTo---WTF
nezaskrtnute nemamNaTo nemamTo-DIS
*/
QMapIterator<QString, QCheckBox*> i(checkBoxes);
while(i.hasNext()){
i.next();
bool mamNaTo = bool(credits>=s->getInt("prices/"+i.key()));
if(reqs.value(i.key()).count()>0){
foreach(QString req,reqs.value(i.key())){
mamNaTo &= (checkBoxes[req]->isChecked());
}
}
if(i.value()->isChecked() && mamNaTo && s->getBool("upgrades/"+i.key()))
i.value()->setEnabled(false);
if(i.value()->isChecked() && !s->getBool("upgrades/"+i.key())){
i.value()->setEnabled(true);
QMapIterator<QString, QStringList> j(reqs);
while(j.hasNext()){
j.next();
if(j.value().contains(i.key()) && checkBoxes[j.key()]->isChecked())
i.value()->setEnabled(false);
}
}
if(i.value()->isChecked() && !mamNaTo && s->getBool("upgrades/"+i.key()))
i.value()->setEnabled(false);
if(!i.value()->isChecked() && mamNaTo && !s->getBool("upgrades/"+i.key()))
i.value()->setEnabled(true);
if(!i.value()->isChecked() && !mamNaTo && !s->getBool("upgrades/"+i.key()))
i.value()->setEnabled(false);
}
}
void ShopDialog::reset(){
QMapIterator<QString, QCheckBox*> i(checkBoxes);
while(i.hasNext()){
i.next();
i.value()->setChecked(s->getBool("upgrades/"+i.key()));
}
credits = s->getInt("credits/count");
}
void ShopDialog::upgrade(QString propName){
Logger::log("Upgrade "+propName+" purchased");
s->setProp("upgrades/"+propName,1);
if(propName=="fontSize1")s->setProp("font/size",80);
if(propName=="fontSize2")s->setProp("font/size",20);
if(propName=="fontSize3")s->setProp("font/size",10);
if(propName=="wordSpacing")s->setProp("font/word_spacing",0);
if(propName=="fontFamily1")s->setProp("font/family","Arial");
if(propName=="fontFamily2")s->setProp("font/family","Courier");
if(propName=="contrast1")s->setProp("color/text","#333333");
if(propName=="contrast2")s->setProp("color/text","#666666");
if(propName=="contrast3")s->setProp("color/text","#ffffff");
if(propName=="statusBar")s->setProp("statusbar/enabled",1);
if(propName=="lineNumber")s->setProp("statusbar/lineNumber",1);
if(propName=="columnNumber")s->setProp("statusbar/columnNumber",1);
if(propName=="credits")s->setProp("statusbar/credits",1);
if(propName=="showPrices"){
s->setProp("shopping/showPrices",1);
addPrices();
}
if(propName=="cheaperKeystrokes1")s->setProp("prices/keyStroke",4);
if(propName=="cheaperKeystrokes2")s->setProp("prices/keyStroke",1);
}
QString ShopDialog::checkBoxToPropName(QCheckBox *checkBox){
return checkBoxes.key(checkBox,"");
}