-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreferencesWin.cpp
777 lines (702 loc) · 33.3 KB
/
PreferencesWin.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
/** Copyright (C) 2010, J.M.Reneau
**
** 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 2 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, write to the Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**/
#include <iostream>
#include "PreferencesWin.h"
#include "Settings.h"
#include "MainWindow.h"
#include "md5.h"
PreferencesWin::PreferencesWin (QWidget * parent, bool showAdvanced)
:QDialog(parent) {
settingsbrowser = NULL;
int r=0, i;
SETTINGS;
// *******************************************************************************************
// build the advanced tab
if (showAdvanced) {
advancedtablayout = new QGridLayout(this);
advancedtabwidget = new QWidget(this);
advancedtabwidget->setLayout(advancedtablayout);
r=0;
//
passwordlabel = new QLabel(tr("Advanced Preferences Password:"),this);
passwordinput = new QLineEdit(QString(),this);
passwordinput->setText(settings.value(SETTINGSPREFPASSWORD, "").toString());
passwordinput->setMaxLength(32);
passwordinput->setEchoMode(QLineEdit::Password);
advancedtablayout->addWidget(passwordlabel,r,1,1,1);
advancedtablayout->addWidget(passwordinput,r,2,1,2);
//
r++;
allowsystemlabel = new QLabel(tr("Allow SYSTEM statement:"), this);
advancedtablayout->addWidget(allowsystemlabel,r,1,1,1);
allowsystemcombo = new QComboBox(this);
//allowsystemcombo->addItem(tr("Ignore"), -1);
allowsystemcombo->addItem(tr("Do not allow"), 0);
allowsystemcombo->addItem(tr("Ask confirmation from user"), 1);
allowsystemcombo->addItem(tr("Allow"), 2);
int s = settings.value(SETTINGSALLOWSYSTEM, SETTINGSALLOWSYSTEMDEFAULT).toInt();
int system = allowsystemcombo->findData(s);
if (system != -1) allowsystemcombo->setCurrentIndex(system);
advancedtablayout->addWidget(allowsystemcombo,r,2,1,2);
//
#ifdef WIN32
#ifndef WIN32PORTABLE
r++;
allowportlabel = new QLabel(tr("Allow PORTIN/PORTOUT statements:"), this);
advancedtablayout->addWidget(allowportlabel,r,1,1,1);
allowportcombo = new QComboBox(this);
//allowportcombo->addItem(tr("Ignore"), -1);
allowportcombo->addItem(tr("Do not allow"), 0);
allowportcombo->addItem(tr("Ask confirmation from user"), 1);
allowportcombo->addItem(tr("Allow"), 2);
int p = settings.value(SETTINGSALLOWPORT, SETTINGSALLOWPORTDEFAULT).toInt();
int port = allowportcombo->findData(p);
if (port != -1) allowportcombo->setCurrentIndex(port);
advancedtablayout->addWidget(allowportcombo,r,2,1,2);
#endif
#endif
//
/*
r++;
QFrame *separator = new QFrame;
separator->setFrameShape(QFrame::HLine);
separator->setFrameShadow(QFrame::Sunken);
advancedtablayout->addWidget(separator,r,1,1,3);
*/
//
r++;
settingsaccesslabel = new QLabel(tr("GETSETTING/SETSETTING access level:"), this);
advancedtablayout->addWidget(settingsaccesslabel,r,1,1,1);
settingsaccesscombo = new QComboBox(this);
settingsaccesscombo->addItem(tr("Get / set only owned settings"), 0);
settingsaccesscombo->addItem(tr("Get any settings / set only owned settings"), 1);
settingsaccesscombo->addItem(tr("Full access (get/set) to settings"), 2);
int l = settings.value(SETTINGSSETTINGSACCESS, SETTINGSSETTINGSACCESSDEFAULT).toInt();
int index = settingsaccesscombo->findData(l);
if (index != -1) settingsaccesscombo->setCurrentIndex(index);
advancedtablayout->addWidget(settingsaccesscombo,r,2,1,2);
//
r++;
settingcheckbox = new QCheckBox(tr("Allow programs to use persistent settings (SETSETTING statement)"),this);
settingcheckbox->setChecked(settings.value(SETTINGSALLOWSETTING, SETTINGSALLOWSETTINGDEFAULT).toBool());
advancedtablayout->addWidget(settingcheckbox,r,2,1,2);
//
r++;
browsesaveddata = new QPushButton(tr("Browse persistent settings"), this);
connect(browsesaveddata, SIGNAL(clicked()), this, SLOT (clickBrowseSavedData()));
advancedtablayout->addWidget(browsesaveddata,r,2,1,1);
clearsaveddata = new QPushButton(tr("Clear all persistent settings"), this);
connect(clearsaveddata, SIGNAL(clicked()), this, SLOT (clickClearSavedData()));
advancedtablayout->addWidget(clearsaveddata,r,3,1,1);
//
r++;
settingsmaxlabel = new QLabel(tr("Max number of settings for each program:"), this);
advancedtablayout->addWidget(settingsmaxlabel,r,1,1,1);
settingsmaxcombo = new QComboBox(this);
settingsmaxcombo->addItem(tr("No limit"), 0);
settingsmaxcombo->addItem(tr("50 keys"), 50);
settingsmaxcombo->addItem(tr("100 keys"), 100);
settingsmaxcombo->addItem(tr("200 keys"), 200);
int m = settings.value(SETTINGSSETTINGSMAX, SETTINGSSETTINGSMAXDEFAULT).toInt();
int max = settingsmaxcombo->findData(m);
if (max != -1) settingsmaxcombo->setCurrentIndex(max);
advancedtablayout->addWidget(settingsmaxcombo,r,2,1,2);
}
// *******************************************************************************************
// build the user tab
usertablayout = new QGridLayout(this);
usertabwidget = new QWidget(this);
usertabwidget->setLayout(usertablayout);
r=0;
// Startup - restore last windows position on start or check for update
r++;
startuplabel = new QLabel(tr("Startup"),this);
usertablayout->addWidget(startuplabel,r,1,1,1);
windowsrestorecheckbox = new QCheckBox(tr("Restore last windows position on start"),this);
windowsrestorecheckbox->setChecked(settings.value(SETTINGSWINDOWSRESTORE, SETTINGSWINDOWSRESTOREDEFAULT).toBool());
usertablayout->addWidget(windowsrestorecheckbox,r,2,1,1);
r++;
checkupdatecheckbox = new QCheckBox(tr("Check for an update on start"),this);
checkupdatecheckbox->setChecked(settings.value(SETTINGSCHECKFORUPDATE, SETTINGSCHECKFORUPDATEDEFAULT).toBool());
usertablayout->addWidget(checkupdatecheckbox,r,2,1,2);
//
r++;
{
int settypeconv;
typeconvlabel = new QLabel(tr("Runtime handling of bad type conversions:"), this);
usertablayout->addWidget(typeconvlabel,r,1,1,1);
typeconvcombo = new QComboBox(this);
typeconvcombo->addItem(tr("Ignore"), SETTINGSERRORNONE);
typeconvcombo->addItem(tr("Warn"), SETTINGSERRORWARN);
typeconvcombo->addItem(tr("Error"), SETTINGSERROR);
// set setting and select
settypeconv = settings.value(SETTINGSTYPECONV, SETTINGSTYPECONVDEFAULT).toInt();
int index = typeconvcombo->findData(settypeconv);
if ( index != -1 ) { // -1 for not found
typeconvcombo->setCurrentIndex(index);
}
// add to layout
usertablayout->addWidget(typeconvcombo,r,2,1,2);
}
//
r++;
{
int setvarnotassigned;
varnotassignedlabel = new QLabel(tr("Runtime handling of unassigned variables:"), this);
usertablayout->addWidget(varnotassignedlabel,r,1,1,1);
varnotassignedcombo = new QComboBox(this);
varnotassignedcombo->addItem(tr("Ignore"), SETTINGSERRORNONE);
varnotassignedcombo->addItem(tr("Warn"), SETTINGSERRORWARN);
varnotassignedcombo->addItem(tr("Error"), SETTINGSERROR);
// set setting and select
setvarnotassigned = settings.value(SETTINGSVARNOTASSIGNED, SETTINGSVARNOTASSIGNEDDEFAULT).toInt();
int index = varnotassignedcombo->findData(setvarnotassigned);
if ( index != -1 ) { // -1 for not found
varnotassignedcombo->setCurrentIndex(index);
}
// add to layout
usertablayout->addWidget(varnotassignedcombo,r,2,1,2);
}
//
r++;
saveonruncheckbox = new QCheckBox(tr("Automatically save program when it is successfully run"),this);
saveonruncheckbox->setChecked(settings.value(SETTINGSIDESAVEONRUN, SETTINGSIDESAVEONRUNDEFAULT).toBool());
usertablayout->addWidget(saveonruncheckbox,r,2,1,2);
//
// decimal digits slider
r++;
decdigslabel = new QLabel(tr("Number of digits to print numbers:"),this);
decdigsvalue = new QLabel("",this);
QHBoxLayout * decdigslabellayout = new QHBoxLayout();
decdigslabellayout->addWidget(decdigslabel);
decdigslabellayout->addWidget(decdigsvalue);
decdigslabellayout->addStretch();
decdigsslider = new QSlider(Qt::Horizontal, this);
decdigsslider->setMinimum(SETTINGSDECDIGSMIN);
decdigsslider->setMaximum(SETTINGSDECDIGSMAX);
decdigsslider->setSingleStep(1);
decdigsslider->setPageStep(1);
QLabel *decdigsbefore = new QLabel(QString::number(SETTINGSDECDIGSMIN),this);
QLabel *decdigsafter = new QLabel(QString::number(SETTINGSDECDIGSMAX),this);
connect(decdigsslider, SIGNAL(valueChanged(int)), this, SLOT(setDigitsValue(int)));
QHBoxLayout * decdigssliderlayout = new QHBoxLayout();
decdigssliderlayout->addWidget(decdigsbefore);
decdigssliderlayout->addWidget(decdigsslider);
decdigssliderlayout->addWidget(decdigsafter);
usertablayout->addLayout(decdigslabellayout,r,1,1,1);
usertablayout->addLayout(decdigssliderlayout,r,2,1,2);
i = settings.value(SETTINGSDECDIGS, SETTINGSDECDIGSDEFAULT).toInt();
decdigsslider->setValue(i);
setDigitsValue(i);
decdigsvalue->setText(decdigsvalue->text() + " "); //ensure space for label to grow without resizing window
// show trailing .0 on floatingpoint numbers (python style numbers)
r++;
floatlocalecheckbox = new QCheckBox(tr("Use localized decimal point on floating point numbers"),this);
floatlocalecheckbox->setChecked(settings.value(SETTINGSFLOATLOCALE, SETTINGSFLOATLOCALEDEFAULT).toBool());
usertablayout->addWidget(floatlocalecheckbox,r,2,1,2);
r++;
floattailcheckbox = new QCheckBox(tr("Always show decimal point on floating point numbers"),this);
floattailcheckbox->setChecked(settings.value(SETTINGSFLOATTAIL, SETTINGSFLOATTAILDEFAULT).toBool());
usertablayout->addWidget(floattailcheckbox,r,2,1,2);
//
// speed of next statement in run to breakpoint
r++;
debugspeedlabel = new QLabel(tr("Debugging Speed:"),this);
debugspeedvalue = new QLabel("",this);
QHBoxLayout * debugspeedlabellayout = new QHBoxLayout();
debugspeedlabellayout->addWidget(debugspeedlabel);
debugspeedlabellayout->addWidget(debugspeedvalue);
debugspeedlabellayout->addStretch();
debugspeedslider = new QSlider(Qt::Horizontal, this);
debugspeedslider->setMinimum(SETTINGSDEBUGSPEEDMIN);
debugspeedslider->setMaximum(SETTINGSDEBUGSPEEDMAX);
QLabel *debugspeedbefore = new QLabel(tr("Fast"),this);
QLabel *debugspeedafter = new QLabel(tr("Slow"),this);
connect(debugspeedslider, SIGNAL(valueChanged(int)), this, SLOT(setDebugSpeedValue(int)));
QHBoxLayout * debugspeedsliderlayout = new QHBoxLayout();
debugspeedsliderlayout->addWidget(debugspeedbefore);
debugspeedsliderlayout->addWidget(debugspeedslider);
debugspeedsliderlayout->addWidget(debugspeedafter);
usertablayout->addLayout(debugspeedlabellayout,r,1,1,1);
usertablayout->addLayout(debugspeedsliderlayout,r,2,1,2);
i = settings.value(SETTINGSDEBUGSPEED, SETTINGSDEBUGSPEEDDEFAULT).toInt();
debugspeedslider->setValue(i);
setDebugSpeedValue(i);
debugspeedvalue->setText(debugspeedvalue->text() + " "); //ensure space for label to grow without resizing window
//
// *******************************************************************************************
// build the sound tab
soundtablayout = new QGridLayout();
soundtabwidget = new QWidget(this);
soundtabwidget->setLayout(soundtablayout);
r=0;
// sound volume slider
r++;
soundvolumelabel = new QLabel(tr("Volume:"),this);
soundvolumevalue = new QLabel("",this);
QHBoxLayout * soundvolumelabellayout = new QHBoxLayout();
soundvolumelabellayout->addWidget(soundvolumelabel);
soundvolumelabellayout->addWidget(soundvolumevalue);
soundvolumelabellayout->addStretch();
soundvolumeslider = new QSlider(Qt::Horizontal,this);
soundvolumeslider->setMinimum(SETTINGSSOUNDVOLUMEMIN);
soundvolumeslider->setMaximum(SETTINGSSOUNDVOLUMEMAX);
soundvolumeslider->setSingleStep(1);
soundvolumeslider->setPageStep(1);
QLabel *soundvolumebefore = new QLabel(QString::number(SETTINGSSOUNDVOLUMEMIN),this);
QLabel *soundvolumeafter = new QLabel(QString::number(SETTINGSSOUNDVOLUMEMAX),this);
connect(soundvolumeslider, SIGNAL(valueChanged(int)), this, SLOT(setVolumeValue(int)));
QHBoxLayout * soundvolumesliderlayout = new QHBoxLayout();
soundvolumesliderlayout->addWidget(soundvolumebefore);
soundvolumesliderlayout->addWidget(soundvolumeslider);
soundvolumesliderlayout->addWidget(soundvolumeafter);
soundtablayout->addLayout(soundvolumelabellayout,r,1,1,1);
soundtablayout->addLayout(soundvolumesliderlayout,r,2,1,2);
i = settings.value(SETTINGSSOUNDVOLUME, SETTINGSSOUNDVOLUMEDEFAULT).toInt();
soundvolumeslider->setValue(i);
setVolumeValue(i);
soundvolumevalue->setText(soundvolumevalue->text() + " "); //ensure space for label to grow without resizing window
// sample rate
r++;
{
int setsoundsamplerate;
soundsampleratelabel = new QLabel(tr("Sound sample rate:"),this);
soundtablayout->addWidget(soundsampleratelabel,r,1,1,1);
soundsampleratecombo = new QComboBox(this);
soundsampleratecombo->addItem(tr("44100 Hz"), 44100);
soundsampleratecombo->addItem(tr("32000 Hz"), 32000);
soundsampleratecombo->addItem(tr("22050 Hz"), 22050);
soundsampleratecombo->addItem(tr("16000 Hz"), 16000);
soundsampleratecombo->addItem(tr("11025 Hz"), 11025);
soundsampleratecombo->addItem(tr("8000 Hz"), 8000);
soundsampleratecombo->addItem(tr("4400 Hz"), 4400);
// set setting and select
setsoundsamplerate = settings.value(SETTINGSSOUNDSAMPLERATE, SETTINGSSOUNDSAMPLERATEDEFAULT).toInt();
int index = soundsampleratecombo->findData(setsoundsamplerate);
if ( index != -1 ) { // -1 for not found
soundsampleratecombo->setCurrentIndex(index);
}
// add to layout
soundtablayout->addWidget(soundsampleratecombo,r,2,1,2);
}
// sound normalize slider
r++;
soundnormalizelabel = new QLabel(tr("Min. period to normalize louder sounds:"),this);
soundnormalizevalue = new QLabel("",this);
QHBoxLayout * soundnormalizelabellayout = new QHBoxLayout();
soundnormalizelabellayout->addWidget(soundnormalizelabel);
soundnormalizelabellayout->addWidget(soundnormalizevalue);
soundnormalizelabellayout->addStretch();
soundnormalizeslider = new QSlider(Qt::Horizontal, this);
soundnormalizeslider->setMinimum(SETTINGSSOUNDNORMALIZEMIN/10);
soundnormalizeslider->setMaximum(SETTINGSSOUNDNORMALIZEMAX/10);
soundnormalizeslider->setSingleStep(1);
soundnormalizeslider->setPageStep(10);
QLabel *soundnormalizebefore = new QLabel(QString::number(SETTINGSSOUNDNORMALIZEMIN),this);
QLabel *soundnormalizeafter = new QLabel(QString::number(SETTINGSSOUNDNORMALIZEMAX),this);
connect(soundnormalizeslider, SIGNAL(valueChanged(int)), this, SLOT(setNormalizeValue(int)));
QHBoxLayout * soundnormalizesliderlayout = new QHBoxLayout();
soundnormalizesliderlayout->addWidget(soundnormalizebefore);
soundnormalizesliderlayout->addWidget(soundnormalizeslider);
soundnormalizesliderlayout->addWidget(soundnormalizeafter);
soundtablayout->addLayout(soundnormalizelabellayout,r,1,1,1);
soundtablayout->addLayout(soundnormalizesliderlayout,r,2,1,2);
i = settings.value(SETTINGSSOUNDNORMALIZE, SETTINGSSOUNDNORMALIZEDEFAULT).toInt()/10;
soundnormalizeslider->setValue(i);
setNormalizeValue(i);
soundnormalizevalue->setText(soundnormalizevalue->text() + " "); //ensure space for label to grow without resizing window
// sound volume restore slider
r++;
soundvolumerestorelabel = new QLabel(tr("Period to restore volume after louder sound:"),this);
soundvolumerestorevalue = new QLabel("",this);
QHBoxLayout * soundvolumerestorelabellayout = new QHBoxLayout();
soundvolumerestorelabellayout->addWidget(soundvolumerestorelabel);
soundvolumerestorelabellayout->addWidget(soundvolumerestorevalue);
soundvolumerestorelabellayout->addStretch();
soundvolumerestoreslider = new QSlider(Qt::Horizontal,this);
soundvolumerestoreslider->setMinimum(SETTINGSSOUNDVOLUMERESTOREMIN/10);
soundvolumerestoreslider->setMaximum(SETTINGSSOUNDVOLUMERESTOREMAX/10);
soundvolumerestoreslider->setSingleStep(1);
soundvolumerestoreslider->setPageStep(10);
QLabel *soundvolumerestorebefore = new QLabel(QString::number(SETTINGSSOUNDVOLUMERESTOREMIN),this);
QLabel *soundvolumerestoreafter = new QLabel(QString::number(SETTINGSSOUNDVOLUMERESTOREMAX),this);
connect(soundvolumerestoreslider, SIGNAL(valueChanged(int)), this, SLOT(setVolumeRestoreValue(int)));
QHBoxLayout * soundvolumerestoresliderlayout = new QHBoxLayout();
soundvolumerestoresliderlayout->addWidget(soundvolumerestorebefore);
soundvolumerestoresliderlayout->addWidget(soundvolumerestoreslider);
soundvolumerestoresliderlayout->addWidget(soundvolumerestoreafter);
soundtablayout->addLayout(soundvolumerestorelabellayout,r,1,1,1);
soundtablayout->addLayout(soundvolumerestoresliderlayout,r,2,1,2);
i = settings.value(SETTINGSSOUNDVOLUMERESTORE, SETTINGSSOUNDVOLUMERESTOREDEFAULT).toInt()/10;
soundvolumerestoreslider->setValue(i);
setVolumeRestoreValue(i);
soundvolumerestorevalue->setText(soundvolumerestorevalue->text() + " "); //ensure space for label to grow without resizing wind
// TTS Settings added here some day
// *******************************************************************************************
// build the printer tab
printertablayout = new QGridLayout();
printertabwidget = new QWidget(this);
printertabwidget->setLayout(printertablayout);
r=0;
{
int dflt = -1;
int setprinter;
printerslabel = new QLabel(tr("Printer:"),this);
printertablayout->addWidget(printerslabel,r,1,1,1);
printerscombo = new QComboBox(this);
// build list of printers
QList<QPrinterInfo> printerList=QPrinterInfo::availablePrinters();
for (int i=0; i< printerList.count(); i++) {
printerscombo->addItem(printerList[i].printerName(),i);
if (printerList[i].isDefault()) dflt = i;
}
printerscombo->addItem(tr("PDF File Output"),-1);
// set setting and select
setprinter = settings.value(SETTINGSPRINTERPRINTER, dflt).toInt();
if (setprinter<-1||setprinter>=printerList.count()) setprinter = dflt;
int index = printerscombo->findData(setprinter);
if ( index != -1 ) { // -1 for not found
printerscombo->setCurrentIndex(index);
}
// add to layout
printertablayout->addWidget(printerscombo,r,2,1,2);
}
//
r++;
{
int setpaper;
paperlabel = new QLabel(tr("Paper:"),this);
printertablayout->addWidget(paperlabel,r,1,1,1);
papercombo = new QComboBox(this);
papercombo->addItem(tr("A0 (841 x 1189 mm)"), QPrinter::A0);
papercombo->addItem(tr("A1 (594 x 841 mm)"), QPrinter::A1);
papercombo->addItem(tr("A2 (420 x 594 mm)"), QPrinter::A2);
papercombo->addItem(tr("A3 (297 x 420 mm)"), QPrinter::A3);
papercombo->addItem(tr("A4 (210 x 297 mm, 8.26 x 11.69 inches)"), QPrinter::A4);
papercombo->addItem(tr("A5 (148 x 210 mm)"), QPrinter::A5);
papercombo->addItem(tr("A6 (105 x 148 mm)"), QPrinter::A6);
papercombo->addItem(tr("A7 (74 x 105 mm)"), QPrinter::A7);
papercombo->addItem(tr("A9 (52 x 74 mm)"), QPrinter::A8);
papercombo->addItem(tr("A9 (37 x 52 mm)"), QPrinter::A9);
papercombo->addItem(tr("B0 (1000 x 1414 mm)"), QPrinter::B0);
papercombo->addItem(tr("B1 (707 x 1000 mm)"), QPrinter::B1);
papercombo->addItem(tr("B2 (500 x 707 mm)"), QPrinter::B2);
papercombo->addItem(tr("B3 (353 x 500 mm)"), QPrinter::B3);
papercombo->addItem(tr("B4 (250 x 353 mm)"), QPrinter::B4);
papercombo->addItem(tr("B5 (176 x 250 mm, 6.93 x 9.84 inches)"), QPrinter::B5);
papercombo->addItem(tr("B6 (125 x 176 mm)"), QPrinter::B6);
papercombo->addItem(tr("B7 (88 x 125 mm)"), QPrinter::B7);
papercombo->addItem(tr("B8 (62 x 88 mm)"), QPrinter::B8);
papercombo->addItem(tr("B9 (33 x 62 mm)"), QPrinter::B9);
papercombo->addItem(tr("B10 (31 x 44 mm)"), QPrinter::B10);
papercombo->addItem(tr("#5 Envelope (163 x 229 mm)"), QPrinter::C5E);
papercombo->addItem(tr("#10 Envelope (105 x 241 mm)"), QPrinter::Comm10E);
papercombo->addItem(tr("DLE (110 x 220 mm)"), QPrinter::DLE);
papercombo->addItem(tr("Executive (7.5 x 10 inches, 190.5 x 254 mm)"), QPrinter::Executive);
papercombo->addItem(tr("Folio (210 x 330 mm)"), QPrinter::Folio);
papercombo->addItem(tr("Ledger (431.8 x 279.4 mm)"), QPrinter::Ledger);
papercombo->addItem(tr("Legal (8.5 x 14 inches, 215.9 x 355.6 mm)"), QPrinter::Legal);
papercombo->addItem(tr("Letter (8.5 x 11 inches, 215.9 x 279.4 mm)"), QPrinter::Letter);
papercombo->addItem(tr("Tabloid (279.4 x 431.8 mm)"), QPrinter::Tabloid);
// set setting and select
setpaper = settings.value(SETTINGSPRINTERPAPER, SETTINGSPRINTERPAPERDEFAULT).toInt();
int index = papercombo->findData(setpaper);
if ( index != -1 ) { // -1 for not found
papercombo->setCurrentIndex(index);
}
// add to layout
printertablayout->addWidget(papercombo,r,2,1,2);
}
//
r++;
{
pdffilelabel = new QLabel(tr("PDF File Name:"),this);
pdffileinput = new QLineEdit(QString(),this);
pdffileinput->setText(settings.value(SETTINGSPRINTERPDFFILE, "").toString());
pdffileinput->setMaxLength(96);
printertablayout->addWidget(pdffilelabel,r,1,1,1);
printertablayout->addWidget(pdffileinput,r,2,1,2);
}
//
r++;
{
resolutiongroup = new QGroupBox(tr("Printer Resolution:"),this);
resolutionhigh = new QRadioButton(tr("High"),this);
resolutionscreen = new QRadioButton(tr("Screen"),this);
QVBoxLayout *resolutionbox = new QVBoxLayout;
resolutionbox->addWidget(resolutionhigh);
resolutionbox->addWidget(resolutionscreen);
resolutiongroup->setLayout(resolutionbox);
printertablayout->addWidget(resolutiongroup,r,2,1,2);
resolutionhigh->setChecked(settings.value(SETTINGSPRINTERRESOLUTION, SETTINGSPRINTERRESOLUTIONDEFAULT)==QPrinter::HighResolution);
resolutionscreen->setChecked(settings.value(SETTINGSPRINTERRESOLUTION, SETTINGSPRINTERRESOLUTIONDEFAULT)==QPrinter::ScreenResolution);
}
//
r++;
{
orientgroup = new QGroupBox(tr("Orientation:"),this);
orientportrait = new QRadioButton(tr("Portrait"),this);
orientlandscape = new QRadioButton(tr("Landscape"),this);
QVBoxLayout *orientbox = new QVBoxLayout;
orientbox->addWidget(orientportrait);
orientbox->addWidget(orientlandscape);
orientgroup->setLayout(orientbox);
printertablayout->addWidget(orientgroup,r,2,1,2);
orientportrait->setChecked(settings.value(SETTINGSPRINTERORIENT, SETTINGSPRINTERORIENTDEFAULT)==QPrinter::Portrait);
orientlandscape->setChecked(settings.value(SETTINGSPRINTERORIENT, SETTINGSPRINTERORIENTDEFAULT)==QPrinter::Landscape);
}
// *******************************************************************************************
// *******************************************************************************************
// *******************************************************************************************
// now that we have the tab layouts built - make the main window
QTabWidget * tabs = new QTabWidget(this);
tabs->addTab(usertabwidget,tr("User"));
tabs->addTab(soundtabwidget,tr("Sound"));
tabs->addTab(printertabwidget,tr("Printing"));
if (showAdvanced) tabs->addTab(advancedtabwidget,tr("Advanced"));
QGridLayout * mainlayout = new QGridLayout();
mainlayout->addWidget(tabs,0,1,1,3);
cancelbutton = new QPushButton(tr("Cancel"), this);
connect(cancelbutton, SIGNAL(clicked()), this, SLOT (clickCancelButton()));
savebutton = new QPushButton(tr("Save"), this);
connect(savebutton, SIGNAL(clicked()), this, SLOT (clickSaveButton()));
mainlayout->addWidget(cancelbutton,1,2,1,1);
mainlayout->addWidget(savebutton,1,3,1,1);
savebutton->setDefault(true);
this->setLayout(mainlayout);
move(settings.value(SETTINGSPREFPOS, QPoint(200, 200)).toPoint());
setWindowTitle(tr("BASIC-256 Preferences and Settings"));
}
void PreferencesWin::clickCancelButton() {
close();
}
void PreferencesWin::clickSaveButton() {
bool validate = true;
SETTINGS;
// validate file name if PDF
if (printerscombo->itemData(printerscombo->currentIndex())==-1 && pdffileinput->text()=="") {
//
QMessageBox::information(this, tr(SETTINGSAPP), tr("File name required for PDF output."),QMessageBox::Ok, QMessageBox::Ok);
validate = false;
}
// add other validation here
if(validate) {
// *******************************************************************************************
// advanced settings
if(advancedtabwidget) {
// only changed advanced settings if they are shown
//
// if password has changed - digest and save
QString currentpw = settings.value(SETTINGSPREFPASSWORD, "").toString();
if(QString::compare(currentpw,passwordinput->text())!=0) {
QString pw("");
if(passwordinput->text().length()!=0) {
pw = MD5(passwordinput->text().toUtf8().data()).hexdigest();
}
settings.setValue(SETTINGSPREFPASSWORD, pw);
}
//
settings.setValue(SETTINGSALLOWSYSTEM, allowsystemcombo->itemData(allowsystemcombo->currentIndex()));
settings.setValue(SETTINGSALLOWSETTING, settingcheckbox->isChecked());
settings.setValue(SETTINGSSETTINGSACCESS, settingsaccesscombo->itemData(settingsaccesscombo->currentIndex()));
settings.setValue(SETTINGSSETTINGSMAX, settingsmaxcombo->itemData(settingsmaxcombo->currentIndex()));
#ifdef WIN32
#ifndef WIN32PORTABLE
settings.setValue(SETTINGSALLOWPORT, allowportcombo->itemData(allowportcombo->currentIndex()));
//settings.setValue(SETTINGSALLOWPORT, portcheckbox->isChecked());
#endif
#endif
}
// *******************************************************************************************
// user settings
settings.setValue(SETTINGSIDESAVEONRUN, saveonruncheckbox->isChecked());
if (typeconvcombo->currentIndex()!=-1) {
settings.setValue(SETTINGSTYPECONV, typeconvcombo->itemData(typeconvcombo->currentIndex()));
}
if (varnotassignedcombo->currentIndex()!=-1) {
settings.setValue(SETTINGSVARNOTASSIGNED, varnotassignedcombo->itemData(varnotassignedcombo->currentIndex()));
}
settings.setValue(SETTINGSDECDIGS, decdigsslider->value());
settings.setValue(SETTINGSDEBUGSPEED, debugspeedslider->value());
settings.setValue(SETTINGSFLOATTAIL, floattailcheckbox->isChecked());
settings.setValue(SETTINGSFLOATLOCALE, floatlocalecheckbox->isChecked());
settings.setValue(SETTINGSWINDOWSRESTORE, windowsrestorecheckbox->isChecked());
settings.setValue(SETTINGSCHECKFORUPDATE, checkupdatecheckbox->isChecked());
// *******************************************************************************************
// sound settings
settings.setValue(SETTINGSSOUNDVOLUME, soundvolumeslider->value());
settings.setValue(SETTINGSSOUNDNORMALIZE, soundnormalizeslider->value()*10);
settings.setValue(SETTINGSSOUNDVOLUMERESTORE, soundvolumerestoreslider->value()*10);
if (soundsampleratecombo->currentIndex()!=-1) {
settings.setValue(SETTINGSSOUNDSAMPLERATE, soundsampleratecombo->itemData(soundsampleratecombo->currentIndex()));
}
// *******************************************************************************************
// printer settings
if (printerscombo->currentIndex()!=-1) {
settings.setValue(SETTINGSPRINTERPRINTER, printerscombo->itemData(printerscombo->currentIndex()));
}
//
if (papercombo->currentIndex()!=-1) {
settings.setValue(SETTINGSPRINTERPAPER, papercombo->itemData(papercombo->currentIndex()));
}
//
settings.setValue(SETTINGSPRINTERPDFFILE, pdffileinput->text());
//
if (resolutionhigh->isChecked()) settings.setValue(SETTINGSPRINTERRESOLUTION, QPrinter::HighResolution);
if (resolutionscreen->isChecked()) settings.setValue(SETTINGSPRINTERRESOLUTION, QPrinter::ScreenResolution);
//
if (orientportrait->isChecked()) settings.setValue(SETTINGSPRINTERORIENT, QPrinter::Portrait);
if (orientlandscape->isChecked()) settings.setValue(SETTINGSPRINTERORIENT, QPrinter::Landscape);
// *******************************************************************************************
// all done
QMessageBox::information(this, tr(SETTINGSAPP), tr("Preferences and settings have been saved."),QMessageBox::Ok, QMessageBox::Ok);
//
close();
}
}
void PreferencesWin::closeEvent(QCloseEvent *e) {
(void) e;
// save current screen posision
SETTINGS;
//settings.setValue(SETTINGSPREFSIZE, size());
settings.setValue(SETTINGSPREFPOS, pos());
}
void PreferencesWin::setDigitsValue(int i){
QString t = QString::number(i) + " " + tr("digits");
QToolTip::showText(QCursor::pos(), t);
decdigsvalue->setText(t);
decdigsslider->setToolTip(t);
}
void PreferencesWin::setDebugSpeedValue(int i){
QString t = tr("pause") + " " + QString::number(i) + " " + tr("ms");
QToolTip::showText(QCursor::pos(),t);
debugspeedvalue->setText(t);
debugspeedslider->setToolTip(t);
}
void PreferencesWin::setVolumeValue(int i){
QString t = QString::number(i);
QToolTip::showText(QCursor::pos(), t);
soundvolumevalue->setText(t);
soundvolumeslider->setToolTip(t);
}
void PreferencesWin::setNormalizeValue(int i){
QString t = QString::number(i*10) + " " + tr("ms");
QToolTip::showText(QCursor::pos(), t);
soundnormalizevalue->setText(t);
soundnormalizeslider->setToolTip(t);
}
void PreferencesWin::setVolumeRestoreValue(int i){
QString t = QString::number(i*10) + " " + tr("ms");
QToolTip::showText(QCursor::pos(), t);
soundvolumerestorevalue->setText(t);
soundvolumerestoreslider->setToolTip(t);
}
void PreferencesWin::clickClearSavedData() {
if(QMessageBox::Yes == QMessageBox::question(this, tr("Delete persistent settings"), tr("Do you really want to delete persistent settings for all programs?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No)){
SETTINGS;
settings.beginGroup(SETTINGSGROUPUSER);
settings.remove("");
settings.endGroup();
}
}
void PreferencesWin::clickBrowseSavedData() {
settingsbrowser = new SettingsBrowser(this);
settingsbrowser->exec();
delete settingsbrowser;
}
SettingsBrowser::SettingsBrowser (QWidget * parent):QDialog(parent) {
setWindowTitle(tr("BASIC-256 Persistent settings"));
QGridLayout *layout = new QGridLayout(this);
setLayout(layout);
QFileIconProvider iconProvider;
treeWidgetSettings = new QTreeWidget(this);
treeWidgetSettings->setColumnCount(2);
treeWidgetSettings->setHeaderLabels(QStringList() << tr("Program/Key") << tr("Value"));
QList<QTreeWidgetItem *> items;
SETTINGS;
settings.beginGroup(SETTINGSGROUPUSER);
QStringList applications = settings.childGroups();
for (int p = 0; p < applications.size(); p++){
QString app(applications.at(p));
settings.beginGroup(app);
QStringList keys = settings.childKeys();
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidgetSettings, (QStringList() << app << QString::number(keys.count())) );
item->setFlags(item->flags() | Qt::ItemIsTristate | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Unchecked);
item->setIcon(0,iconProvider.icon(QFileIconProvider::Folder));
for (int k = 0; k < keys.size(); k++){
QString key(keys.at(k));
QTreeWidgetItem *i = new QTreeWidgetItem(item, QStringList() << key << settings.value(key, "").toString());
i->setCheckState(0, Qt::Unchecked);
item->addChild(i);
}
settings.endGroup();
items.append(item);
}
settings.endGroup();
treeWidgetSettings->insertTopLevelItems(0, items);
treeWidgetSettings->setSortingEnabled(true);
treeWidgetSettings->sortItems(0, Qt::AscendingOrder);
treeWidgetSettings->resizeColumnToContents(0);
layout->addWidget(treeWidgetSettings, 1, 1, 1, 2);
deleteselectedsettings = new QPushButton(tr("Delete selected settings"), this);
deleteselectedsettings->setEnabled(false);
connect(deleteselectedsettings, SIGNAL(clicked()), this, SLOT (clickDeleteButton()));
layout->addWidget(deleteselectedsettings, 2, 1);
canceldeletesettings = new QPushButton(tr("Cancel"), this);
canceldeletesettings->setDefault(true);
connect(canceldeletesettings, SIGNAL(clicked()), this, SLOT (reject()));
layout->addWidget(canceldeletesettings,2,2);
connect(treeWidgetSettings, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT (treeWidgetCheckboxChanged()));
}
void SettingsBrowser::treeWidgetCheckboxChanged() {
QTreeWidgetItemIterator it(treeWidgetSettings);
while (*it) {
if ((*it)->checkState(0) != Qt::Unchecked){
deleteselectedsettings->setEnabled(true);
return;
}
++it;
}
deleteselectedsettings->setEnabled(false);
}
void SettingsBrowser::clickDeleteButton() {
if(QMessageBox::Yes == QMessageBox::question(this, tr("Delete selected settings"), tr("Do you really want to delete selected persistent settings?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No)){
SETTINGS;
settings.beginGroup(SETTINGSGROUPUSER);
deleteselectedsettings->setEnabled(false);
int top=treeWidgetSettings->topLevelItemCount()-1;
while(top>=0){
QTreeWidgetItem *topitem = treeWidgetSettings->topLevelItem(top);
if(topitem->checkState(0) == Qt::Checked){
settings.remove(topitem->text(0));
delete topitem;
}
top--;
}
QTreeWidgetItemIterator it(treeWidgetSettings);
while (*it) {
QTreeWidgetItem * item = (*it);
++it;
if (item->checkState(0) == Qt::Checked){
settings.remove(item->parent()->text(0) + QString("/") + item->text(0));
delete item;
}
}
settings.endGroup();
}
}