-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
1468 lines (1328 loc) · 58.1 KB
/
mainwindow.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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_inputdialog.h"
#include "ui_selectdialog.h"
#include "ui_rankdialog.h"
#include "cipherdialog.h"
#include "rankdialog.h"
#include "calwindow.h"
#include "httpdownload.h"
#include "headdialog.h"
#include <QtCore>
#include <QDate>
#include <QRegularExpression>
#include <QMessageBox>
#include <QKeyEvent>
#include <QUrl>
#include <QtNetwork>
#include <QFontDialog>
#include <QFileDialog>
//#include "gcalc.h"
using namespace std;
#define MAX_SIZE 1000005
int zerodays[8][250], linenumbers=0;
QString hmem[10];
vector<int> primes;
QString phrase = "<none>";
QString pwd = QDir::currentPath() + "/tmp.htm";
QFile *file = new QFile(pwd);
bool nightmode=true;
QString appgroup="GAnalyzer";
QString filesource;
QString labeltext,tmpstring;
int year,dd,mm,ns,d2,m2,y2,filter,hmempos = -1;
bool single_r_on=false,francis_on=false,satanic_on=false,jewish_on=false,sumerian_on=false,rev_sumerian_on=false;
void MainWindow::SieveOfEratosthenes(vector<int> &primes)
{
// Create a boolean array "IsPrime[0..MAX_SIZE]" and
// initialize all entries it as true. A value in
// IsPrime[i] will finally be false if i is
// Not a IsPrime, else true.
bool IsPrime[MAX_SIZE];
memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++)
{
// If IsPrime[p] is not changed, then it is a prime
if (IsPrime[p] == true)
{
// Update all multiples of p greater than or
// equal to the square of it
// numbers which are multiple of p and are
// less than p^2 are already been marked.
for (int i = p * p; i < MAX_SIZE; i += p)
IsPrime[i] = false;
}
}
// Store all prime numbers
for (int p = 2; p < MAX_SIZE; p++)
if (IsPrime[p])
primes.push_back(p);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
QDate cd = QDate::currentDate();
year = cd.year();
dd = cd.day();
mm = cd.month();
QString scomstr = "Active phrase : " +phrase+ " - Current date : " + QString::number(dd) + "/" + QString::number(mm) + "/" + QString::number(year);
ui->setupUi(this);
ui->lineEdit->installEventFilter(this);
ui->statusbar->installEventFilter(this);
//connect(ui->textBrowser, &QTextBrowser::anchorClicked,
// this, &MainWindow::handleAnchorClicked);
ui->actionSwap_dates->setDisabled(true);
if (eudate) ui->action_Eu_date->setText("Date DMY");
else ui->action_Eu_date->setText("Date MDY");
SieveOfEratosthenes(primes);
//QtSpell::TextEditChecker checker;
//m_checker = new QtSpell::TextEditChecker(this);
//checker.setLanguage("en_CH");
//checker.setTextEdit(ui->textBrowser);
QString historyfile = loadsettings("historyfile").toString();
if (historyfile == "") savesettings("historyfile","history.txt");
QString font = readSettings("settings.txt","font");
QString DMY = readSettings("settings.txt","DMY");
QString ciphers = readSettings("settings.txt","ciphers");
QString ssplit = readSettings("settings.txt","ssplit");
QString nightm = readSettings("settings.txt","nightmode");
QString DW = readSettings("settings.txt","DW"); //true
QString HistX = readSettings("settings.txt","HistX");
QString LNs = readSettings("settings.txt","LNs"); //false
if (ssplit == "false") ui->actionSentence_split->setChecked(false);
if (DW == "none") DW="true";
if (HistX == "none") HistX="true";
if (LNs == "none") LNs="false";
if (DW == "false") ui->actionDisplay_Welcome->setChecked(false);
if (HistX == "false") ui->actionRemove_view_history_on_exit->setChecked(false);
if (LNs == "true") {
ui->actionLine_numbers_in_view->setChecked(true);
linenumbers=1;
}
if (DMY == "false") {
eudate = false;
ui->action_Eu_date->setText("Date MDY");
ui->action_Eu_date->setChecked(false);
}
if (font != "none") {
QFont f1;
f1.fromString(font);
ui->textBrowser->setFont(f1);
}
if (ciphers.mid(0,1) == "1") single_r_on = true;
if (ciphers.mid(1,1) == "1") francis_on = true;
if (ciphers.mid(2,1) == "1") satanic_on = true;
if (ciphers.mid(3,1) == "1") jewish_on = true;
if (ciphers.mid(4,1) == "1") sumerian_on = true;
if (ciphers.mid(5,1) == "1") rev_sumerian_on = true;
if (nightm == "true") {
nightmode = true;
ui->actionNightmode->setChecked(true);
} else {
nightmode = false;
ui->actionNightmode->setChecked(false);
}
if (nightmode) ui->textBrowser->setStyleSheet("background-color: #1a1a1a; color: lightgrey");
if (nightmode) ui->lineEdit->setStyleSheet("background-color: #1a1a1a; color: white");
setCentralWidget(ui->groupBox);
//setCentralWidget(ui->centralwidget);
ui->lineEdit->focusWidget();
ui->statusbar->showMessage(scomstr);
if ( !file->open(QIODevice::ReadWrite) )
{
qDebug() << "tmp.htm not open";
} else file->close();
ui->textBrowser->setSource("file:///"+pwd);
std::setlocale(LC_ALL,"");
//QAbstractScrollArea(ui->textBrowser).scroll(60,60);
ui->textBrowser->scroll(0,6000);
//int curr_locale = QLocale().language();
//qDebug() << " String ="<< curr_locale << endl;
if (DW=="true") welcome();
//qDebug() << MainWindow::width() << " " << MainWindow::x() << " " << ui->textBrowser->width();
}
MainWindow::~MainWindow()
{
QString ciphers;
if (single_r_on) ciphers = "1";
else ciphers = "0";
if (francis_on) ciphers += "1";
else ciphers += "0";
if (satanic_on) ciphers += "1";
else ciphers += "0";
if (jewish_on) ciphers += "1";
else ciphers += "0";
if (sumerian_on) ciphers += "1";
else ciphers += "0";
if (rev_sumerian_on) ciphers += "1";
else ciphers += "0";
//qDebug() << ciphers;
char filename[13] = "settings.txt";
writeSettings(filename,"ciphers",ciphers.toUtf8().constData());
string ssplit="";
if (ui->actionDisplay_Welcome->isChecked()) writeSettings(filename,"DW","true");
else writeSettings(filename,"DW","false");
if (ui->actionLine_numbers_in_view->isChecked()) writeSettings(filename,"LNs","true");
else writeSettings(filename,"LNs","false");
if (ui->actionSentence_split->isChecked()) ssplit = "true";
else ssplit = "false";
writeSettings(filename,"ssplit",ssplit);
//qDebug() << MainWindow::width() << " " << MainWindow::x() << " " << ui->textBrowser->width();
//QString pwd = QDir::currentPath() + "/tmp.htm";
//QFile *File = new QFile(pwd);
if (ui->actionRemove_view_history_on_exit->isChecked()) {
writeSettings(filename,"HistX","true");
file->remove();
}
else writeSettings(filename,"HistX","false");
delete ui;
}
QVariant MainWindow::loadsettings(QString settings)
{
QVariant returnvar;
QSettings appsettings("QTinman",appgroup);
appsettings.beginGroup(appgroup);
returnvar = appsettings.value(settings);
appsettings.endGroup();
return returnvar;
}
void MainWindow::savesettings(QString settings, QVariant attr)
{
QSettings appsettings("QTinman",appgroup);
appsettings.beginGroup(appgroup);
appsettings.setValue(settings,QVariant::fromValue(attr));
appsettings.endGroup();
}
bool MainWindow::eventFilter(QObject* obj, QEvent *event)
{
if (obj == ui->lineEdit)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Up)
{
//ui->lineEdit->setText("Up Key");
if (hmempos > 0) {
hmempos --;
ui->lineEdit->setText(hmem[hmempos]);
//qDebug() << hmem[hmempos] << hmempos;
}
return true;
}
else if(keyEvent->key() == Qt::Key_Down)
{
//ui->lineEdit->setText("Down Key");
if (hmempos > -1) {
if (hmempos < 10 && hmem[hmempos] != "") {
if (hmem[hmempos] != "") hmempos ++;
//qDebug() << hmem[hmempos] << hmempos;
if(hmempos <= 9 ) ui->lineEdit->setText(hmem[hmempos]);
else ui->lineEdit->setText("");
//if (hmem[hmempos+2] == "") ui->lineEdit->setText("");
}
}
//if (hmempos == 10) ui->lineEdit->setText("");
return true;
}
}
return false;
}
if(obj == ui->statusbar) updatestatusbar();
//if(obj == ui->textBrowser) qDebug() << event;
return QMainWindow::eventFilter(obj, event);
}
void MainWindow::handleAnchorClicked(const QUrl &url)
{
/* QString msg = "new URL == ";
msg.append(url.toDisplayString());
msg.append("\nold URL == ");
msg.append(ui->textBrowser->source().toDisplayString());
QMessageBox::information(this, __FUNCTION__, msg);*/
int int1=url.toString().lastIndexOf(".");
int int2=url.toString().lastIndexOf("/");
QString number = url.toString().mid(int2+1,int1-int2-1);
//qDebug() << number;
}
void MainWindow::handleSourceChanged(const QUrl &url)
{
QString msg = "new URL == ";
msg.append(url.toDisplayString());
msg.append("\nold URL == ");
msg.append(ui->textBrowser->source().toDisplayString());
QMessageBox::information(this, __FUNCTION__, msg);
}
void MainWindow::keymem(QString memstr)
{
if (hmem[9] != "") {
for (int i=0;i<9;i++){
hmem[i] = hmem[i+1];
}
}
hmem[9] = "";
for (hmempos=1;hmempos<10;hmempos++){
if (hmem[hmempos-1] == "") break;
}
hmem[hmempos-1] = memstr;
}
void MainWindow::on_actionDate_Search_triggered() //Ctrl-S
{
labeltext = "Search number :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
QString html = loopYear(ns,dd,mm,year,1,eudate);
if (ns > 0) {
writetmpfile("<br>Searching dates for whole year starts<br>");
writetmpfile("<html>"+html+"</html>");
}
}
void MainWindow::updatestatusbar()
{
QString scombstr;
if (d2 == 0) {
if (eudate) scombstr = "Active phrase : " +phrase+ " - Current date : " + QString::number(dd) + "/" + QString::number(mm) + "/" + QString::number(year);
else scombstr = "Active phrase : " +phrase+ " - Current date : " + QString::number(mm) + "/" + QString::number(dd) + "/" + QString::number(year);
} else {
if (eudate) scombstr = "Active phrase : " +phrase+ " - Current date : " + QString::number(dd) + "/" + QString::number(mm) + "/" + QString::number(year) + " Second date : " + QString::number(d2) + "/" + QString::number(m2) + "/" + QString::number(y2);
else scombstr = "Active phrase : " +phrase+ " - Current date : " + QString::number(mm) + "/" + QString::number(dd) + "/" + QString::number(year) + " Second date : " + QString::number(m2) + "/" + QString::number(d2) + "/" + QString::number(y2);
}
//ui->statusbar->setStyleSheet("color: red");
ui->menu_File->menuAction()->setStatusTip(scombstr);
if (d2 != 0) ui->actionSwap_dates->setDisabled(false);
ui->statusbar->showMessage(scombstr);
}
inputDialog::inputDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::inputDialog)
{
ui->setupUi(this);
if (labeltext == "New date :") {
inputDialog::setWindowTitle("Enter new date");
ui->lineEdit->setInputMask("00-00");
}
if (labeltext == "Enter second date :") {
inputDialog::setWindowTitle("Enter second date for extended date details");
ui->lineEdit->setInputMask("00-00-0000");
}
if (labeltext == "Enter URL :") {
inputDialog::setWindowTitle("Add newssource");
//ui->lineEdit->setInputMask("00-00");
}
if (labeltext == "Search number :") {
inputDialog::setWindowTitle("Search whole year for cipher");
ui->lineEdit->setInputMask("0000");
}
if (labeltext == "New Phrase :") inputDialog::setWindowTitle("Phrase needed for Analyzer to run");
if (labeltext == "New phrase :") inputDialog::setWindowTitle("Enter new phrase");
if (labeltext == "Enter Year:") {
inputDialog::setWindowTitle("Change year");
ui->lineEdit->setInputMask("0000");
}
if (labeltext == "Enter Cipher nr. :") {
inputDialog::setWindowTitle("Search history.txt");
ui->lineEdit->setInputMask("0000");
}
if (labeltext == "Filter history :") {
inputDialog::setWindowTitle("List History");
tmpstring = "<none>";
}
ui->label->setText(labeltext);
}
inputDialog::~inputDialog()
{
delete ui;
}
void inputDialog::displaydialog()
{
if (labeltext == "New Phrase :") phrase = ui->lineEdit->text();
if (labeltext == "New phrase :") phrase = ui->lineEdit->text();
if (labeltext == "Search number :") ns = ui->lineEdit->text().mid(0,4).toInt();
if (labeltext == "Compare to history :") ns = ui->lineEdit->text().mid(0,4).toInt();
if (labeltext == "Enter Year:") year = ui->lineEdit->text().mid(0,4).toInt();
if (labeltext == "Enter Cipher nr. :") ns = ui->lineEdit->text().mid(0,4).toInt();
if (labeltext == "Filter history :") tmpstring = ui->lineEdit->text();
if (labeltext == "Enter URL :") tmpstring = ui->lineEdit->text();
if (eudate) {
if (labeltext == "New date :") {
dd = ui->lineEdit->text().mid(0,2).toInt();
mm = ui->lineEdit->text().mid(3,2).toInt();
if (valid_date(dd,mm,year) == 0) {
QDate cd = QDate::currentDate();
year = cd.year();
dd = cd.day();
mm = cd.month();
}
}
}else{
if (labeltext == "New date :") {
dd = ui->lineEdit->text().mid(3,2).toInt();
mm = ui->lineEdit->text().mid(0,2).toInt();
if (valid_date(dd,mm,year) == 0) {
QDate cd = QDate::currentDate();
year = cd.year();
dd = cd.day();
mm = cd.month();
}
}
}
if (eudate) {
if (labeltext == "Enter second date :") {
d2 = ui->lineEdit->text().mid(0,2).toInt();
m2 = ui->lineEdit->text().mid(3,2).toInt();
y2 = ui->lineEdit->text().mid(6,4).toInt();
if (valid_date(d2,m2,y2) == 0) {
d2 = 0;
m2 = 0;
y2 = 0;
}
}
}else {
if (labeltext == "Enter second date :") {
d2 = ui->lineEdit->text().mid(3,2).toInt();
m2 = ui->lineEdit->text().mid(0,2).toInt();
y2 = ui->lineEdit->text().mid(6,4).toInt();
if (valid_date(d2,m2,y2) == 0) {
d2 = 0;
m2 = 0;
y2 = 0;
}
}
}
}
void inputDialog::on_buttonBox_accepted()
{
emit displaydialog();
}
void inputDialog::on_lineEdit_returnPressed()
{
emit displaydialog();
}
void MainWindow::on_actionNew_Phrase_triggered() //Ctrl-P
{
labeltext = "New phrase :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
updatestatusbar();
}
void MainWindow::on_actionNew_Date_triggered()
{
labeltext = "New date :";
inputDialog datesearch;
datesearch.eudate = eudate;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
updatestatusbar();
}
void MainWindow::on_actionSearch_History_txt_triggered() //Ctrl-H
{
ns = 0;
labeltext = "Enter Cipher nr. :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
if (ns > 0){
writetmpfile("<br>Search history with number starts<br>");
QString html = searchwords(ns,true);
if (ns >0) writetmpfile("<html>"+html+"</html>");
}
}
void MainWindow::on_actionSet_Year_triggered()
{
labeltext = "Enter Year:";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
updatestatusbar();
}
void MainWindow::on_action_Analyze_triggered() //Ctrl-A
{
if (phrase == "<none>") {
labeltext = "New Phrase :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
updatestatusbar();
}
if (phrase != "<none>") {
writetmpfile("<br>Analyzing phrase starts");
readsolarfile(dd,mm,year);
bool sentences = ui->actionSentence_split->isChecked();
QString html;
if (sentences) html = analyze(dd,mm,year,phrase,false,0,eudate);
else html = runanalyze(dd,mm,year,phrase.toUtf8().constData(),false,0,eudate);
writetmpfile("<html>"+html+"</html>");
}
}
void MainWindow::on_action_Eu_date_toggled(bool arg1)
{
if (arg1) eudate = true;
else eudate = false;
char filename[13] = "settings.txt";
if (eudate) {
ui->action_Eu_date->setText("Date DMY");
writeSettings(filename,"DMY","true");
} else {
ui->action_Eu_date->setText("Date MDY");
writeSettings(filename,"DMY","false");
}
updatestatusbar();
}
void MainWindow::on_actionDate_Details_triggered() //Ctrl-D
{
QString html = gcalc(dd,mm,year,d2,m2,y2,eudate);
writetmpfile("<html>"+html+"</html>");
//#include <QDebug>//qDebug() << "\n" << html;
}
void MainWindow::calc(QString calcstr)
{
int result=0,ppos=0,mpos=0;
ppos = calcstr.indexOf("+");
mpos = calcstr.indexOf("-");
if (ppos == -1) ppos = calcstr.length();
if (mpos == -1) mpos = calcstr.length();
if (ppos==0) {
int ppos2 = calcstr.indexOf("+",ppos+1);
if (mpos < ppos2 || ppos2 == -1) result += calcstr.mid(0,mpos).toInt();
else result += calcstr.mid(0,ppos2).toInt();
ppos = calcstr.indexOf("+",ppos+1);
} else if (mpos==0) {
int mpos2 = calcstr.indexOf("-",mpos+1);
if (ppos < mpos2 || mpos2 == -1) result += calcstr.mid(0,ppos).toInt();
else result += calcstr.mid(0,mpos2).toInt();
mpos = calcstr.indexOf("-",mpos+1);
} else if ((ppos < mpos || mpos == -1) && ppos != -1) result += calcstr.mid(0,ppos).toInt();
else result += calcstr.mid(0,mpos).toInt();
if (ppos == calcstr.length()) ppos = calcstr.indexOf("+");
if (mpos == calcstr.length()) mpos = calcstr.indexOf("-");
do {
if ((ppos < mpos || mpos == -1) && ppos != -1) {
int ppos2 = calcstr.indexOf("+",ppos+1);
if (ppos2 < mpos && ppos2 != -1) result += calcstr.mid(ppos,ppos2-ppos).toInt();
else if (mpos == -1 && ppos2 == -1) result += calcstr.mid(ppos,calcstr.length()-ppos).toInt();
else if (mpos == -1 && ppos2 > ppos) result += calcstr.mid(ppos,ppos2-ppos).toInt();
else result += calcstr.mid(ppos,mpos-ppos).toInt();
ppos = calcstr.indexOf("+",ppos+1);
} else {
int mpos2 = calcstr.indexOf("-",mpos+1);
if (mpos2 < ppos && mpos2 != -1) result += calcstr.mid(mpos,mpos2-mpos).toInt();
else if (ppos == -1 && mpos2 == -1) result += calcstr.mid(mpos,calcstr.length()-mpos).toInt();
else if (ppos == -1 && mpos2 > mpos) result += calcstr.mid(mpos,mpos2-mpos).toInt();
else result += calcstr.mid(mpos,ppos-mpos).toInt();
mpos = calcstr.indexOf("-",mpos+1);
}
} while (ppos != -1 || mpos != -1);
writetmpfile(calcstr+"="+QString::number(result));
}
int indexOfLineStartingWith(const QStringList& list, const QString& textToFind)
{
return list.indexOf(QRegularExpression("^" + QRegularExpression::escape(textToFind) + ".+"));
}
void MainWindow::on_lineEdit_returnPressed()
{
QString tphrase = ui->lineEdit->text(), command;
std::string stdphrase = tphrase.toUtf8().constData();
QStringList commands={"compare"};
int n=stdphrase.find(" ");
command = QString::fromStdString(stdphrase.substr(0,n));
if (ui->checkBox->isChecked() && stdphrase[0] != '/') stdphrase = "/a" +stdphrase;
bool forcalc=true;
for(size_t i=0; i<stdphrase.size(); ++i){
if ((int(stdphrase[i]) > 57 || int(stdphrase[i]) < 48) && int(stdphrase[i]) != 43 && int(stdphrase[i]) != 45 && int(stdphrase[i]) != 32) forcalc=false;
// || int(stdphrase[i]) != 43 || int(stdphrase[i]) != 45
}
//if (tphrase.indexOf("+") != -1 || tphrase.indexOf("-") != -1) {
if (forcalc) {
eraseAllQSubStr(tphrase," ");
calc(tphrase);
}
else if (stdphrase == "dd" || stdphrase == "DD") {
QString html = printword(stdphrase,'D',true,false);
writetmpfile("<html>"+html+"</html>");
}
else if (stdphrase [0] == '/' || stdphrase [0] == '.') {
//qDebug() << QString::fromStdString(stdphrase) << "\n";
//eraseAllSubStr(stdphrase," ");
tphrase = QString::fromStdString(stdphrase);
replaceAll(stdphrase,"/ ","/");
replaceAll(stdphrase," /","/");
replaceAll(stdphrase,"/a ","/a");
replaceAll(stdphrase,"/c ","/c");
replaceAll(stdphrase,"/n ","/n");
replaceAll(stdphrase,"/s ","/s");
replaceAll(stdphrase,"/h ","/h");
replaceAll(stdphrase,"/w ","/w");
replaceAll(stdphrase,"/e ","/e");
replaceAll(stdphrase,"/o ","/o");
replaceAll(stdphrase,"/r ","/r");
//qDebug() << QString::fromStdString(stdphrase) << "\n";
if (stdphrase[1] != 'a') keymem(QString::fromStdString(stdphrase));
switch (stdphrase[1]) {
case 'a':
{
if (QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2)) == "" && phrase == "<none>") {
labeltext = "New Phrase :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
} else if (QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2)) != ""){
phrase = QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2));
keymem(phrase);
readsolarfile(dd,mm,year);
bool sentences = ui->actionSentence_split->isChecked();
QString html;
if (sentences) html = analyze(dd,mm,year,phrase,false,0,eudate);
else html = runanalyze(dd,mm,year,phrase.toUtf8().constData(),false,0,eudate);
writetmpfile("<html>"+html+"</html>");
updatestatusbar();
}
break;
}
case 'c':
{
ui->textBrowser->clear();
file->remove();
if ( !file->open(QIODevice::ReadWrite) )
{
qDebug() << "tmp.htm not open";
} else file->close();
break;
}
case 'n':
{
QStringList dags= tphrase.mid(2,tphrase.length()-2).split("/");
if (dags.count() < 2) dags= tphrase.mid(2,tphrase.length()-2).split(".");
if (eudate && dags.count() >= 2) {
dd = dags[0].toUInt();
mm = dags[1].toUInt();
//dd = ui->lineEdit->text().mid(2,2).toInt();
//mm = ui->lineEdit->text().mid(5,2).toInt();
} else if (dags.count() >= 2){
mm = dags[0].toUInt();
dd = dags[1].toUInt();
}
//if (ui->lineEdit->text().mid(8,4).toInt() > 0) year = ui->lineEdit->text().mid(8,4).toInt();
if (dags.count() > 2) {
year = dags[2].toInt();
if (year < 100) year += 2000;
}
if (valid_date(dd,mm,year) == 0 || dags.count() < 2) {
//qDebug() << ui->lineEdit->text().mid(2,2) << " " << ui->lineEdit->text().mid(5,2) << " " << year;
QDate cd = QDate::currentDate();
dd = cd.day();
mm = cd.month();
year = cd.year();
}
updatestatusbar();
break;
}
case 's':
{
QStringList dags= tphrase.mid(2,tphrase.length()-2).split("/");
if (dags.count() < 2) dags= tphrase.mid(2,tphrase.length()-2).split(".");
if (eudate && dags.count() >= 2) {
d2 = dags[0].toUInt();
m2 = dags[1].toUInt();
} else if (dags.count() >= 2){
m2 = dags[0].toUInt();
d2 = dags[1].toUInt();
}
if (dags.count() > 2) {
y2 = dags[2].toInt();
if (y2 < 100) y2 += 2000;
} else y2 = year;
if (valid_date(d2,m2,y2) == 0 || dags.count() < 2) {
//qDebug() << ui->lineEdit->text().mid(2,2) << " " << ui->lineEdit->text().mid(5,2) << " " << y2;
d2 = 0;
m2 = 0;
y2 = 0;
} else ui->actionSwap_dates->setDisabled(false);
updatestatusbar();
break;
}
case 'h':
emit shorthelp();
break;
case 'w':
{
if (QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2)) == "" && phrase == "<none>") {
labeltext = "New phrase :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
} else if (QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2)) != "") phrase = QString::fromStdString(stdphrase.substr(2,stdphrase.length()-2));
keymem(phrase);
updatestatusbar();
if (phrase != "<none>") {
std::string stdphrase = phrase.toUtf8().constData();
bool sentences = ui->actionSentence_split->isChecked();
if (sentences) writetmpfile("<html>"+printallwords(stdphrase,'N',true,false)+"</html>");
else writetmpfile("<html>"+printword(stdphrase,'N',true,false)+"</html>");
}
break;
case 'd':
{
QString html;
if (eudate) {if (valid_date(ui->lineEdit->text().mid(2,2).toInt(),ui->lineEdit->text().mid(5,2).toInt(),year) == 1) {
if (ui->lineEdit->text().mid(8,4).toInt() > 0) html = gcalc(ui->lineEdit->text().mid(2,2).toInt(),ui->lineEdit->text().mid(5,2).toInt(),ui->lineEdit->text().mid(8,4).toInt(),d2,m2,y2,eudate);
else html = gcalc(ui->lineEdit->text().mid(2,2).toInt(),ui->lineEdit->text().mid(5,2).toInt(),year,d2,m2,y2,eudate);
}
else html = gcalc(dd,mm,year,d2,m2,y2,eudate);
}else { if (valid_date(ui->lineEdit->text().mid(5,2).toInt(),ui->lineEdit->text().mid(2,2).toInt(),year) == 1) {
if (ui->lineEdit->text().mid(8,4).toInt() > 0) html = gcalc(ui->lineEdit->text().mid(5,2).toInt(),ui->lineEdit->text().mid(2,2).toInt(),ui->lineEdit->text().mid(8,4).toInt(),d2,m2,y2,eudate);
else gcalc(ui->lineEdit->text().mid(5,2).toInt(),ui->lineEdit->text().mid(2,2).toInt(),year,d2,m2,y2,eudate);
}
else html = gcalc(dd,mm,year,d2,m2,y2,eudate);
}
writetmpfile("<html>"+html+"</html>");
break;
}
case 'e':
{
QString html;
int type=5;
if (ui->lineEdit->text().mid(2,1).toUpper() == "T") type = 1;
if (ui->lineEdit->text().mid(2,1).toUpper() == "A") type = 2;
if (ui->lineEdit->text().mid(2,1).toUpper() == "P") type = 3;
if (ui->lineEdit->text().mid(2,1).toUpper() == "H") type = 4;
if (ui->lineEdit->text().mid(2,1).toUpper() == "X") type = 5;
//qDebug() << ui->lineEdit->text().mid(2,1) << " " << ui->lineEdit->text().mid(4,2) << " " << ui->lineEdit->text().mid(7,2) << " " << ui->lineEdit->text().mid(10,4);
if (eudate) {if (valid_date(ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(7,2).toInt(),year) == 1) {
if (ui->lineEdit->text().mid(10,4).toInt() > 0) html = solareclipe(ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(10,4).toInt(),1,type,eudate);
else if (ui->lineEdit->text().mid(2,1) != "") html = solareclipe(ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(7,2).toInt(),year,1,type,eudate);
}
else html = solareclipe(dd,mm,year, 1,type,eudate);
}else { if (valid_date(ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(4,2).toInt(),year) == 1) {
if (ui->lineEdit->text().mid(10,4).toInt() > 0) html = solareclipe(ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(10,4).toInt(),1,type,eudate);
else solareclipe(ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(4,2).toInt(),year,1,type,eudate);
}
else if (type > 0) html = solareclipe(dd,mm,year,1,type,eudate);
}
writetmpfile("<html>"+html+"</html>");
break;
}
case 'o':
{
QString html;
if (ui->lineEdit->text().mid(2,1).toInt() > 0 && ui->lineEdit->text().mid(2,1).toInt() < 5) {
if (eudate) {if (valid_date(ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(7,2).toInt(),year) == 1) html = date2history(ui->lineEdit->text().mid(4,2).toInt(),ui->lineEdit->text().mid(7,2).toInt(),year,true,eudate,ui->lineEdit->text().mid(2,1).toInt());
else html = date2history(dd,mm,year,true,eudate,ui->lineEdit->text().mid(2,1).toInt());
}else { if (valid_date(ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(4,2).toInt(),year) == 1) html = date2history(ui->lineEdit->text().mid(7,2).toInt(),ui->lineEdit->text().mid(4,2).toInt(),year,true,eudate,ui->lineEdit->text().mid(2,1).toInt());
else html = date2history(dd,mm,year,true,eudate,ui->lineEdit->text().mid(2,1).toInt());
}
writetmpfile("<html>"+html+"</html>");
}
break;
}
case 'r':
{
if (jewish_on && single_r_on && francis_on && satanic_on && sumerian_on && rev_sumerian_on) {
single_r_on=false;
francis_on=false;
satanic_on=false;
jewish_on=false;
sumerian_on=false;
rev_sumerian_on=false;
} else if (!jewish_on && !single_r_on && !francis_on && !satanic_on && !sumerian_on && !rev_sumerian_on) {
single_r_on=true;
francis_on=true;
satanic_on=true;
jewish_on=true;
sumerian_on=true;
rev_sumerian_on=true;
}
break;
}
case 'y':
{
QString html;
if (phrase == "<none>") phrase = tphrase.mid(2,tphrase.length()-2);
if (phrase != "") {
html = phraserank(phrase.toUtf8().constData(),eudate,3,true,true,true,true);
writetmpfile("<html>"+html+"</html>");
}
break;
}
case 'x':
{
if (stdphrase [2] == 'd') { //add/subtrackt to date
ns = ui->lineEdit->text().length();
ns = ui->lineEdit->text().mid(3,ns-3).toInt();
int d1,m1,y1;
QDate cd(year,mm,dd);
cd = cd.addDays(ns);
y1 = cd.year();
d1 = cd.day();
m1 = cd.month();
if (eudate) writetmpfile("<html>"+QString::number(d1)+"/"+QString::number(m1)+"/"+QString::number(y1)+"</html>");
else writetmpfile("<html>"+QString::number(m1)+"/"+QString::number(d1)+"/"+QString::number(y1)+"</html>");
} else if (stdphrase [2] == 's') { // add/subtrackt to second date
ns = ui->lineEdit->text().length();
ns = ui->lineEdit->text().mid(3,ns-3).toInt();
QDate cd(year,mm,dd);
cd = cd.addDays(ns);
y2 = cd.year();
d2 = cd.day();
m2 = cd.month();
updatestatusbar();
} else { // add/subtrackt to date and display only
ns = ui->lineEdit->text().length();
ns = ui->lineEdit->text().mid(2,ns-2).toInt();
QDate cd(year,mm,dd);
cd = cd.addDays(ns);
year = cd.year();
dd = cd.day();
mm = cd.month();
updatestatusbar();
}
break;
}
case 'f':
{
Httpdownload = new HttpDownload(this);
Httpdownload->setWindowTitle("News Download");
Httpdownload->show();
connect(Httpdownload, SIGNAL(dl_ready(QString)),
this, SLOT(show_news(QString)));
//HttpDownload Httpdownload;
//Httpdownload.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
//Httpdownload.exec();
//filesource = "index.html";
//tmpstring = "https://www.nytimes.com/";
//qDebug() << filesource;
break;
}
case 't': // test
{
qDebug() << "days d_s " << a_seconddate("day_d_s");
qDebug() << "days s_d " << a_seconddate("day_s_d");
qDebug() << "week d_s " << a_seconddate("week_d_s");
qDebug() << "week s_d " << a_seconddate("week_s_d");
qDebug() << "month d_s " << a_seconddate("month_d_s");
qDebug() << "month s_d " << a_seconddate("month_s_d");
qDebug() << "day_full " << a_seconddate("day_full");
qDebug() << "week_full " << a_seconddate("week_full");
qDebug() << "month_full " << a_seconddate("month_full");
//qDebug() << "months_d_s " << monthbeetween(mm,m2,a_seconddate("day_d_s"),'M') << " days " << monthbeetween(mm,m2,a_seconddate("day_d_s"),'D');
//qDebug() << "months_s_d " << monthbeetween(m2,mm,a_seconddate("day_s_d"),'M') << " days " << monthbeetween(m2,mm,a_seconddate("day_s_d"),'D');
//int test = a_seconddate("week_d_s");
//test = a_seconddate("week_s_d");
}
}
}
}
else if (stdphrase != "")
if (commands.indexOf(command) !=-1 && phrase != "<none>") {
qDebug() << "here!!";
int ns;
QString html;
//Compare the numbers in active phrase and one entered
for ( const auto& i : commands )
if (i =="compare") {
int n=stdphrase.find(" ");
stdphrase.erase(0,n);
ns=getns(phrase.toUtf8().constData(),1,0);
if (getns(stdphrase,1,0) == ns) {
if (ui->SaveHistory->isChecked()) html = printword(stdphrase,'Y',true,false);
else html = printword(stdphrase,'N',true,false);
writetmpfile("<html>"+html+"</html>");
}
}
}else {
QString html;
keymem(QString::fromStdString(stdphrase));
phrase = QString::fromStdString(stdphrase);
updatestatusbar();
if (ui->SaveHistory->isChecked()) html = printword(stdphrase,'Y',true,false);
else html = printword(stdphrase,'N',true,false);
writetmpfile("<html>"+html+"</html>");
}
ui->lineEdit->clear();
}
void MainWindow::shorthelp()
{
QString color="";
if (!nightmode)
color="blue";
else
color="lightblue";
writetmpfile("<br><h1>Short help</h1><br>");
writetmpfile("<b>All functions are available from the Menu</b>");
writetmpfile("<b>By shortcut following functions are available</b>");
writetmpfile("<font color=\""+color+"\">(Ctrl-S)</font> <b>Date search</b> connect number to dates spanning the active year.");
writetmpfile("<font color=\""+color+"\">(Ctrl-H)</font> <b>Search history.txt</b> searches all words connected to entered number in history.txt.");
writetmpfile("<font color=\""+color+"\">(Ctrl-A)</font> <b>Analyze</b> takes active phrase and compare it to current date displayed on the status bar.");
writetmpfile("<font color=\""+color+"\">(Ctrl-D)</font> <b>Date details</b> displays calculations for current date. Second date will extend the information.");
writetmpfile("<font color=\""+color+"\">(Ctrl-R)</font> <b>Phrase ranking</b> search through the year and displays number of hits pr. date.");
writetmpfile("<font color=\""+color+"\">(Ctrl-W)</font> <b>Word details</b> shows details about active phrase.");
writetmpfile("<font color=\""+color+"\">(Ctrl-E)</font> <b>Compare Solar Eclipses to History.txt</b> for current date");
writetmpfile("<font color=\""+color+"\">(Ctrl-O)</font> <b>Date compare to history</b> calculate current date and compares it to history.txt");
writetmpfile("<font color=\""+color+"\">(Ctrl-T)</font> <b>Compare phrase to history.txt</b> takes one of the base ciphers from active phrase and compares it to history.txt<br>");
writetmpfile("<b>Sentence split</b> When unchecked analyze and word print will not split sentences<br>");
writetmpfile("The input area takes phrases which are displayed and saved to history.txt if Save is checked<br>");
writetmpfile("Toggle Analyze will run entered phrases through analyzer instead of word details.<br>");
writetmpfile("<b>The input area also takes commands:</b>");
writetmpfile("<font color=\""+color+"\">/a(phrase)</font> runs analyzer, (<b>Phrase</b> is optional)");
writetmpfile("<font color=\""+color+"\">/w(phrase)</font> phrase details (<b>Phrase</b> is optional)");
writetmpfile("<font color=\""+color+"\">/y(phrase)</font> phrase rank (<b>Phrase</b> active or passed in command.)");
writetmpfile("<font color=\""+color+"\">/n##/##/####</font> New date, (Year is optional)");
writetmpfile("<font color=\""+color+"\">/s##/##/####</font> New second date");
writetmpfile("<font color=\""+color+"\">/d##/##/####</font> date details (date is optional, year is extra option)");
writetmpfile("<font color=\""+color+"\">/o#/##/##</font> Date compare to history (first number is filter 1-4, date is optional)");
writetmpfile("<font color=\""+color+"\">/e@/##/##/####</font> Last and next Solar eclipse relative to date. @ is type \"T A P H-X=for all\" (date is optional, year is extra option)");
writetmpfile("<font color=\""+color+"\">/r</font> Toggle all extra ciphers on or off");
writetmpfile("<font color=\""+color+"\">/x##</font> Add or subtract days from current date and set that date.");
writetmpfile("<font color=\""+color+"\">/xs##</font> Add or subtract days from current date and set that as second date.");
writetmpfile("<font color=\""+color+"\">/xd##</font> Add or subtract days from current date and display only in output.");
writetmpfile("<font color=\""+color+"\">dd</font> deletes last line from history.txt");
writetmpfile("<font color=\""+color+"\">/h</font> shows this help");
writetmpfile("<font color=\""+color+"\">/c</font> Clears output");
writetmpfile("Enter <b>Word Phrase</b> shows details about that phrase and saves it to history if Save is checked.");
writetmpfile("Change <b>Current Year</b> from The Edit menu");
writetmpfile("Change <b>Date Style</b> from The Edit menu");
writetmpfile("<br><b>© [email protected]</b><br>");
}
void MainWindow::welcome()
{
QString color="";
if (!nightmode)
color="blue";
else
color="lightblue";
writetmpfile("<h1>Welcome to Gematria Analyzer!</h1><br>");
writetmpfile("<h2>This program calculates Kabbalah ciphers from phrases and compares it to date numerology.</h2><br>");
writetmpfile("<b>For details about ciphers select <font color=\""+color+"\">Tables->List ciphers</font></b>");
writetmpfile("The program takes a phrase and date for comparison, also second date can be entered<br>");
writetmpfile("Select <b>Help</b> from menu or type <font color=\""+color+"\">/h</font> in input area<br>");
//writetmpfile("<div title=\"them's hoverin' words\">hover me</div>");
}
void MainWindow::on_action_Word_details_triggered() //Ctrl-W
{
if (phrase == "<none>") {
labeltext = "New phrase :";
inputDialog datesearch;
datesearch.setModal(true); // if nomodal is needed then create pointer inputdialog *datesearch; in mainwindow.h private section, then here use inputdialog = new datesearch(this); datesearch.show();
datesearch.exec();
updatestatusbar();
}
if (phrase != "<none>") {
std::string stdphrase = phrase.toUtf8().constData();
bool sentences = ui->actionSentence_split->isChecked();
if (sentences) writetmpfile("<html>"+printallwords(stdphrase,'N',true,false)+"</html>");
else writetmpfile("<html>"+printword(stdphrase,'N',true,false)+"</html>");
}