-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
1547 lines (1245 loc) · 62.8 KB
/
mainwindow.cpp
File metadata and controls
1547 lines (1245 loc) · 62.8 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
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"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
// Initialising important data
ui->setupUi(this);
this->wallet = new wlt::eWallet();
// Setup Language
if(qtLanguageTranslator.load(QString(":/lang/language_") + QString::fromStdString(this->wallet->getLocalLanguage()) + QString(".qm")) )
{
qApp->installTranslator(&qtLanguageTranslator);
ui->retranslateUi(this);
}
QObject::connect(ui->mainWindow, &QStackedWidget::currentChanged, this, &MainWindow::StackedWidgetIndexChanged);
// Init connects
this->sideBarConnects();
this->formsInit();
this->settingsFormInit();
this->contactFormInit();
this->fillRatesData();
// Fill dynamic data
this->fillAccountData();
this->fillNoteData();
this->fillRatesData();
}
MainWindow::~MainWindow()
{
delete this->wallet;
delete ui;
}
// Class slots
void MainWindow::StackedWidgetIndexChanged()
{
if(ui->mainWindow->currentIndex() == 0)
{
this->last_index = 0;
// main window
this->fillAccountData();
this->fillNoteData();
}
else if(ui->mainWindow->currentIndex() == 5)
{
this->last_index = 5;
// Full notes list page update
this->fillFullNotesPage();
}
else if(ui->mainWindow->currentIndex() == 6)
{
// Stat with chart page
this->updateStatPage();
}
else if(ui->mainWindow->currentIndex() == 7)
{
//this->fillRatesData();
}
else if(ui->mainWindow->currentIndex() == 8)
{
this->updateSettingsForm();
}
}
void MainWindow::CreateAccount()
{
// qDebug() << ui->accNameLineEdit->text();
// qDebug() << ui->CountLineEdit->text();
// qDebug() << ui->currencListCombobox->currentText();
if(ui->accNameLineEdit->text() == "" || ui->CountLineEdit->text() == "" || ui->currencListCombobox->currentText() == "")
return;
if(ui->CountLineEdit->text().length() >= 13)
return;
if( this->wallet->inRatesTable( ui->currencListCombobox->currentText().toUpper().toStdString() ) == -1 )
return;
double Value = ui->CountLineEdit->text().replace(",",".").toDouble();
wallet->Create_Account(ui->accNameLineEdit->text().toStdString(), Value, ui->currencListCombobox->currentText().toStdString() );
ui->mainWindow->setCurrentIndex(0);
}
void MainWindow::AccountNameChangedInEditor()
{
wlt::Account choosen_account = wallet->getAccountByName( ui->accountNameComboBox_edit->currentText().toStdString());
ui->currencListCombobox_edit->setCurrentText( QString::fromStdString( choosen_account.getCurrencyType() ) );
ui->CountLineEdit_edit->setText( QString::number( choosen_account.getCount(), 'f', 2 ) );
}
void MainWindow::OperationTypeChangedInForm()
{
if(ui->OperationComboBox->currentIndex() == 2)
{
ui->AccountLabelAddit->setVisible(true);
ui->accountAdditComboBox->setVisible(true);
}
else
{
ui->AccountLabelAddit->setVisible(false);
ui->accountAdditComboBox->setVisible(false);
if(ui->OperationComboBox->currentIndex() == 1)
ui->categoryComboBox->setCurrentIndex(9);
}
}
void MainWindow::AccountComboBoxChangedInAddNoteForm()
{
ui->accountAdditComboBox->clear();
std::list<wlt::Account> lst_acc = wallet->getAccountList();
wlt::Account selected_acc = wallet->getAccountByName( ui->accountMainComboBox->currentText().toStdString() );
for(auto acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
{
if(acc_iter->getName() != selected_acc.getName() && acc_iter->getCurrencyType() == selected_acc.getCurrencyType())
ui->accountAdditComboBox->addItem(QString::fromStdString(acc_iter->getName()));
}
}
void MainWindow::OperationTypeChangedInForm_edit()
{
if(ui->OperationComboBox_edit->currentIndex() == 2)
{
ui->AccountLabelAddit_edit->setVisible(true);
ui->accountAdditComboBox_edit->setVisible(true);
}
else
{
ui->AccountLabelAddit_edit->setVisible(false);
ui->accountAdditComboBox_edit->setVisible(false);
if(ui->OperationComboBox_edit->currentIndex() == 1)
ui->categoryComboBox_edit->setCurrentIndex(9);
}
}
void MainWindow::AccountComboBoxChangedInAddNoteForm_edit()
{
ui->accountAdditComboBox_edit->clear();
std::list<wlt::Account> lst_acc = wallet->getAccountList();
wlt::Account selected_acc = wallet->getAccountByName( ui->accountMainComboBox_edit->currentText().toStdString() );
for(auto acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
{
if(acc_iter->getName() != selected_acc.getName() && acc_iter->getCurrencyType() == selected_acc.getCurrencyType())
ui->accountAdditComboBox_edit->addItem(QString::fromStdString(acc_iter->getName()));
}
}
void MainWindow::DeleteAccount()
{
wallet->Remove_Account(ui->accountNameComboBox_edit->currentText().toStdString());
ui->mainWindow->setCurrentIndex(0);
}
void MainWindow::editAccountFormUpdate()
{
QObject::disconnect(ui->accountNameComboBox_edit, &QComboBox::currentTextChanged, this, &MainWindow::AccountNameChangedInEditor);
ui->accountNameComboBox_edit->clear();
std::list<wlt::Account> lst_acc = wallet->getAccountList();
for(auto acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
ui->accountNameComboBox_edit->addItem(QString::fromStdString(acc_iter->getName()));
if(ui->accountNameComboBox_edit->currentIndex() == 0)
this->AccountNameChangedInEditor();
QObject::connect(ui->accountNameComboBox_edit, &QComboBox::currentTextChanged, this, &MainWindow::AccountNameChangedInEditor);
}
void MainWindow::addNoteFormUpdate()
{
//QObject::connect(ui->OperationComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::OperationTypeChangedInForm);
QObject::disconnect(ui->accountMainComboBox, &QComboBox::currentTextChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm);
ui->accountMainComboBox->clear();
ui->accountAdditComboBox->clear();
ui->ValueLineEditNote->setText("");
ui->detailsTextEditNote->setText("");
std::list<wlt::Account> lst_acc = wallet->getAccountList();
for(auto acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
{
ui->accountMainComboBox->addItem(QString::fromStdString(acc_iter->getName()));
//ui->accountAdditComboBox->addItem(QString::fromStdString(acc_iter->getName()));
}
QObject::connect(ui->accountMainComboBox, &QComboBox::currentTextChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm);
}
void MainWindow::editNoteFormUpdate(unsigned long id)
{
QObject::disconnect(ui->accountMainComboBox_edit, &QComboBox::currentIndexChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm_edit);
ui->accountMainComboBox_edit->clear();
ui->accountAdditComboBox_edit->clear();
ui->ValueLineEditNote_edit->setText("");
ui->detailsTextEditNote_edit->setText("");
std::list<wlt::Account> lst_acc = wallet->getAccountList();
for(auto acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
{
ui->accountMainComboBox_edit->addItem(QString::fromStdString(acc_iter->getName()));
//ui->accountAdditComboBox_edit->addItem(QString::fromStdString(acc_iter->getName()));
}
QObject::connect(ui->accountMainComboBox_edit, &QComboBox::currentIndexChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm_edit);
std::list<wlt::Note>::iterator selected_iterator = wallet->getNoteByID(id);
ui->OperationComboBox_edit->setCurrentIndex((int)selected_iterator->getOperation() );
ui->categoryComboBox_edit->setCurrentIndex((int) selected_iterator->getCategory() );
ui->ValueLineEditNote_edit->setText( QString::number(selected_iterator->getValue() ,'f', 2) );
ui->detailsTextEditNote_edit->setText(QString::fromStdString( selected_iterator->getDetails() ));
ui->accountMainComboBox_edit->setCurrentText( QString::fromStdString( selected_iterator->getAccountName() ) );
ui->accountAdditComboBox_edit->setCurrentText( QString::fromStdString( selected_iterator->getAccountNameAddit() ) );
}
void MainWindow::SaveAccountEdit()
{
if( ui->CountLineEdit_edit->text().length() == 0 || ui->CountLineEdit_edit->text().length() >= 13)
return;
if( this->wallet->inRatesTable( ui->currencListCombobox_edit->currentText().toUpper().toStdString() ) == -1 )
return;
double Value = ui->CountLineEdit_edit->text().replace(",",".").toDouble();
wallet->Edit_Account(ui->accountNameComboBox_edit->currentText().toStdString(), Value, ui->currencListCombobox_edit->currentText().toStdString());
ui->mainWindow->setCurrentIndex(0);
}
void MainWindow::CreateNote()
{
if(ui->ValueLineEditNote->text().length() == 0)
return;
if(ui->OperationComboBox->currentIndex() == 2 && ui->accountAdditComboBox->currentText() == "")
return;
if(ui->ValueLineEditNote->text().length() >= 13)
return;
double Value = ui->ValueLineEditNote->text().replace(",",".").toDouble();
QString details_str = ui->detailsTextEditNote->toPlainText();
details_str.truncate(500);
int operation_type = ui->OperationComboBox->currentIndex();
wlt::Account main_acc = wallet->getAccountByName( ui->accountMainComboBox->currentText().toStdString() );
if(ui->accountAdditComboBox->currentText().toStdString() != "")
{
wlt::Account addit_acc = wallet->getAccountByName( ui->accountAdditComboBox->currentText().toStdString() );
if( addit_acc.getCount() >= 100000000000 && Value > 0 && operation_type == 2)
return;
}
if(Value <= 0 && operation_type == 2)
return;
if( main_acc.getCount() >= 100000000000 && Value > 0 && operation_type == 1)
return;
else if ( main_acc.getCount() <= -100000000000 && Value > 0 && operation_type == 0)
return;
if(operation_type == 2)
{
wlt::Account addit_acc = wallet->getAccountByName( ui->accountAdditComboBox->currentText().toStdString() );
wlt::Account main_acc = wallet->getAccountByName( ui->accountMainComboBox->currentText().toStdString() );
if(main_acc.getCount() <= -10000000000 || addit_acc.getCount() >= 100000000000)
return;
// Transfer operation
wallet->Create_Note( static_cast<wlt::Operation>( ui->OperationComboBox->currentIndex() ), static_cast<wlt::Category>( ui->categoryComboBox->currentIndex() ),
ui->accountMainComboBox->currentText().toStdString(), ui->accountAdditComboBox->currentText().toStdString() ,Value, details_str.toStdString());
ui->mainWindow->setCurrentIndex(0);
return;
}
if(operation_type == 0)
operation_type = 1;
else if(operation_type == 1)
operation_type = 0;
// Usual operation
this->wallet->Create_Note( static_cast<wlt::Operation>( operation_type ), static_cast<wlt::Category>( ui->categoryComboBox->currentIndex() ),
ui->accountMainComboBox->currentText().toStdString(), Value, details_str.toStdString());
ui->mainWindow->setCurrentIndex(this->last_index);
}
void MainWindow::EditNote()
{
if(ui->ValueLineEditNote_edit->text().length() == 0)
return;
if(ui->OperationComboBox_edit->currentIndex() == 2 && ui->accountAdditComboBox_edit->currentText() == "")
return;
if(ui->ValueLineEditNote_edit->text().length() >= 13)
return;
double Value = ui->ValueLineEditNote_edit->text().replace(",",".").toDouble();
QString details_str = ui->detailsTextEditNote_edit->toPlainText();
details_str.truncate(500);
int operation_type = ui->OperationComboBox_edit->currentIndex();
wlt::Account main_acc = wallet->getAccountByName( ui->accountMainComboBox_edit->currentText().toStdString() );
if(ui->accountAdditComboBox_edit->currentText().toStdString() != "")
{
wlt::Account addit_acc = wallet->getAccountByName( ui->accountAdditComboBox_edit->currentText().toStdString() );
if( addit_acc.getCount() >= 100000000000 && Value > 0 && operation_type == 2)
return;
}
if(Value <= 0 && operation_type == 2)
return;
if( main_acc.getCount() >= 100000000000 && Value > 0 && operation_type == 1)
return;
else if ( main_acc.getCount() <= -100000000000 && Value > 0 && operation_type == 0)
return;
if(operation_type == 2)
{
this->wallet->Edit_Note(this->ID, static_cast<wlt::Operation>( ui->OperationComboBox_edit->currentIndex() ), static_cast<wlt::Category>( ui->categoryComboBox_edit->currentIndex() ),
ui->accountMainComboBox_edit->currentText().toStdString(), ui->accountAdditComboBox_edit->currentText().toStdString() ,Value, details_str.toStdString());
ui->mainWindow->setCurrentIndex(0);
return;
}
if(operation_type == 0)
operation_type = 1;
else if(operation_type == 1)
operation_type = 0;
//std::cout << ui->categoryComboBox_edit->currentIndex() << std::endl;
this->wallet->Edit_Note(this->ID, static_cast<wlt::Operation>( operation_type ), static_cast<wlt::Category>( ui->categoryComboBox_edit->currentIndex() ),
ui->accountMainComboBox_edit->currentText().toStdString(), Value, details_str.toStdString() );
ui->mainWindow->setCurrentIndex(this->last_index);
}
void MainWindow::DeleteNote()
{
wallet->Remove_Note(this->ID);
ui->mainWindow->setCurrentIndex(this->last_index);
}
void MainWindow::CurrencyChanged()
{
if(!this->wallet->isRatesEmpty())
{
this->wallet->setCurrencyType(ui->MainCurrencyComboBox->currentText().toStdString());
this->fillRatesData();
}
else
{
QMessageBox::StandardButton reply;
reply = QMessageBox::critical(nullptr, tr("No connection"),
tr("No rates tables loaded. Connect to internet connection."),
QMessageBox::Ok);
QObject::disconnect(ui->MainCurrencyComboBox, &QComboBox::currentTextChanged, this, &MainWindow::CurrencyChanged);
ui->MainCurrencyComboBox->setCurrentText(QString::fromStdString(this->wallet->getCurrencyType()));
QObject::connect(ui->MainCurrencyComboBox, &QComboBox::currentTextChanged, this, &MainWindow::CurrencyChanged);
}
}
// -------------------------------------
void MainWindow::formsInit()
{
// Account Form
ui->CountLineEdit->setValidator( new QDoubleValidator(-10000000000, 10000000000, 2) );
std::list<std::string> RatesStrings = wallet->getRatesNames();
for(auto it = RatesStrings.begin(); it != RatesStrings.end(); it++)
{
ui->currencListCombobox->addItem( QString::fromStdString(*it) );
}
QObject::connect(ui->addAccCancelButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(0);} );
QObject::connect(ui->addAccCreateButton, &QPushButton::clicked, this , &MainWindow::CreateAccount);
// Edit Account Form
ui->CountLineEdit_edit->setValidator( new QDoubleValidator(-10000000000, 10000000000, 2) );
for(auto it = RatesStrings.begin(); it != RatesStrings.end(); it++)
{
ui->currencListCombobox_edit->addItem(QString::fromStdString(*it));
}
std::list<wlt::Account> lst_acc = wallet->getAccountList();
std::list<wlt::Account>::iterator acc_iter;
for(acc_iter = lst_acc.begin(); acc_iter != lst_acc.end(); acc_iter++)
{
ui->accountNameComboBox_edit->addItem(QString::fromStdString(acc_iter->getName()));
}
if(this->wallet->AccountsCount() > 0)
{
int choosen = 0;
acc_iter = lst_acc.begin();
std::advance(acc_iter, choosen);
ui->accountNameComboBox_edit->setCurrentIndex( choosen);
ui->currencListCombobox_edit->setCurrentText( QString::fromStdString( acc_iter->getCurrencyType() ) );
ui->CountLineEdit_edit->setText( QString::number( acc_iter->getCount(), 'f', 2 ) );
}
QObject::connect(ui->accountNameComboBox_edit, &QComboBox::currentTextChanged, this, &MainWindow::AccountNameChangedInEditor);
QObject::connect(ui->cancelButton_edit, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(0);});
QObject::connect(ui->deleteButton_edit, &QPushButton::clicked, this, &MainWindow::DeleteAccount);
QObject::connect(ui->saveButton_edit, &QPushButton::clicked, this, &MainWindow::SaveAccountEdit);
// Add note form
ui->OperationComboBox->addItem( tr("Outcome") );
ui->OperationComboBox->addItem( tr("Income") );
ui->OperationComboBox->addItem( tr("Transfer") );
//Category { FOOD, PRODUCT, HOUSE, TRANSPORT, CAR, ENTERTAINMENT, NETWORK, FINANCE_EXPENSIES, TRANSFER_OPERATION, EARNINGS};
ui->categoryComboBox->addItem(tr("Food and restaraunts") );
ui->categoryComboBox->addItem(tr("Products") );
ui->categoryComboBox->addItem(tr("Healthcare") );
ui->categoryComboBox->addItem(tr("Public Transport") );
ui->categoryComboBox->addItem(tr("Vehicle") );
ui->categoryComboBox->addItem(tr("Entertainment") );
ui->categoryComboBox->addItem(tr("Communication and internet") );
ui->categoryComboBox->addItem(tr("Financial expenses") );
ui->categoryComboBox->addItem(tr("Financial transfer") );
ui->categoryComboBox->addItem(tr("Income") );
// EDIT combobox items !!!
//std::list<wlt::Account> lst_acc = wallet->getAccountList();
for(auto it = lst_acc.begin(); it != lst_acc.end(); it++)
{
ui->accountMainComboBox->addItem(QString::fromStdString(it->getName() ) );
//ui->accountAdditComboBox->addItem(QString::fromStdString(it->getName() ) );
}
// if(ui->accountAdditComboBox->count() > 1)
// ui->accountAdditComboBox->setCurrentIndex(1);
ui->accountMainComboBox->setCurrentText("");
ui->AccountLabelAddit->setVisible(false);
ui->accountAdditComboBox->setVisible(false);
ui->ValueLineEditNote->setValidator( new QDoubleValidator(-10000000000, 10000000000, 2) );
QObject::connect(ui->cancelButtonNote, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(this->last_index);});
QObject::connect(ui->saveButtonNote, &QPushButton::clicked, this, &MainWindow::CreateNote );
QObject::connect(ui->OperationComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::OperationTypeChangedInForm);
QObject::connect(ui->accountMainComboBox, &QComboBox::currentTextChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm);
// Edit Note Form
ui->OperationComboBox_edit->addItem( tr("Outcome") );
ui->OperationComboBox_edit->addItem( tr("Income") );
ui->OperationComboBox_edit->addItem( tr("Transfer") );
ui->categoryComboBox_edit->addItem(tr("Food and restaraunts"));
ui->categoryComboBox_edit->addItem(tr("Products") );
ui->categoryComboBox_edit->addItem(tr("Healthcare"));
ui->categoryComboBox_edit->addItem(tr("Public transport") );
ui->categoryComboBox_edit->addItem(tr("Vehicle"));
ui->categoryComboBox_edit->addItem(tr("Entertainment"));
ui->categoryComboBox_edit->addItem(tr("Communication and internet") );
ui->categoryComboBox_edit->addItem(tr("Financial expenses") );
ui->categoryComboBox_edit->addItem(tr("Financial transfer") );
ui->categoryComboBox_edit->addItem(tr("Income"));
for(auto it = lst_acc.begin(); it != lst_acc.end(); it++)
{
ui->accountMainComboBox_edit->addItem(QString::fromStdString(it->getName() ) );
//ui->accountAdditComboBox_edit->addItem(QString::fromStdString(it->getName() ) );
}
ui->AccountLabelAddit_edit->setVisible(false);
ui->accountAdditComboBox_edit->setVisible(false);
ui->ValueLineEditNote_edit->setValidator( new QDoubleValidator(-10000000000, 10000000000, 2) );
QObject::connect(ui->OperationComboBox_edit, &QComboBox::currentIndexChanged, this, &MainWindow::OperationTypeChangedInForm_edit);
QObject::connect(ui->accountMainComboBox_edit, &QComboBox::currentIndexChanged, this, &MainWindow::AccountComboBoxChangedInAddNoteForm_edit);
QObject::connect(ui->cancelButtonNote_edit, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(this->last_index);} );
QObject::connect(ui->saveButtonNote_edit, &QPushButton::clicked, this, &MainWindow::EditNote );
QObject::connect( ui->deleteButtonNote_edit, &QPushButton::clicked, this, &MainWindow::DeleteNote );
}
void MainWindow::settingsFormInit()
{
// Currency combobox
std::list<std::string> RatesStrings = wallet->getRatesNames();
for(auto it = RatesStrings.begin(); it != RatesStrings.end(); it++)
{
ui->MainCurrencyComboBox->addItem( QString::fromStdString(*it) );
}
ui->MainCurrencyComboBox->setCurrentText(QString::fromStdString(this->wallet->getCurrencyType()));
QObject::connect(ui->MainCurrencyComboBox, &QComboBox::currentTextChanged, this, &MainWindow::CurrencyChanged);
ui->MainCurIcon->setPixmap(this->getWhiteIcon(":/icons/base-currenct.svg"));
// Main Language
ui->languageComboBox->addItem(QString("English"));
ui->languageComboBox->addItem(QString("Русский"));
ui->languageComboBox->addItem(QString("Українська"));
QString db_lang = QString::fromStdString( this->wallet->getLocalLanguage() );
if(db_lang == "en")
ui->languageComboBox->setCurrentText("English");
else if(db_lang == "ru")
ui->languageComboBox->setCurrentText("Русский");
else if(db_lang == "ua")
ui->languageComboBox->setCurrentText("Українська");
// QObject::connect(ui->languageComboBox, &QComboBox::currentIndexChanged, this, this->ChangeTranslation);
QObject::connect(ui->languageComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::ChangeTranslation);
ui->LangIcon->setPixmap(this->getWhiteIcon(":/setting-icons/icons/language-solid.svg"));
}
void MainWindow::contactFormInit()
{
ui->BugReportButton->setIcon(this->getWhiteIcon(":/setting-icons/icons/bug-solid.svg"));
ui->BugReportButton->setIconSize(QSize(23,22));
ui->BugReportButton->setCursor(Qt::PointingHandCursor);
ui->DonateButton->setIcon(this->getWhiteIcon(":/setting-icons/icons/circle-dollar-to-slot-solid.svg"));
ui->DonateButton->setIconSize(QSize(23,22));
ui->DonateButton->setCursor(Qt::PointingHandCursor);
// Disable donation button
ui->DonateButton->setDisabled(true);
ui->DonateButton->setVisible(false);
// Url connects
QObject::connect(ui->BugReportButton, &QPushButton::clicked, this,
[=]()
{
QUrl url("https://docs.google.com/forms/d/e/1FAIpQLSeh9zxZDbWYW5kBU1ZUV8ETvm2jGT8JhbwNsECWI3VSwfS5gA/viewform");
QDesktopServices::openUrl(url);
}
);
QObject::connect(ui->DonateButton, &QPushButton::clicked, this,
[=]()
{
QUrl url("https://ko-fi.com/softbitdeveloper");
QDesktopServices::openUrl(url);
}
);
}
void MainWindow::sideBarConnects()
{
QObject::connect(ui->mainButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(0);} );
QObject::connect(ui->mainButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Main") ) ;} );
QObject::connect(ui->notesButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(5);});
QObject::connect(ui->notesButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Operations") ) ;});
QObject::connect(ui->statisticButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(6);});
QObject::connect(ui->statisticButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Statistic") ) ;});
QObject::connect(ui->ratesButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(7);});
QObject::connect(ui->ratesButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Rates") ) ;});
QObject::connect(ui->settingsButton, &QPushButton::clicked, ui->mainWindow, [=](){ui->mainWindow->setCurrentIndex(8);});
QObject::connect(ui->settingsButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Settings") ) ;});
QObject::connect(ui->contactsButton, &QPushButton::clicked, ui->mainWindow,[=](){ui->mainWindow->setCurrentIndex(9);});
QObject::connect(ui->contactsButton, &QPushButton::clicked, ui->namebar_label, [=](){ui->namebar_label->setText(tr("Contacts") ) ;});
ui->mainButton->setIcon(this->getWhiteIcon(":/nav-bar/house.svg"));
ui->mainButton->setIconSize(QSize(23,22));
ui->mainButton->setCursor(Qt::PointingHandCursor);
ui->notesButton->setIcon(this->getWhiteIcon(":/nav-bar/note.svg"));
ui->notesButton->setIconSize(QSize(23,22));
ui->notesButton->setCursor(Qt::PointingHandCursor);
ui->statisticButton->setIcon(this->getWhiteIcon(":/nav-bar/chart.svg"));
ui->statisticButton->setIconSize(QSize(23,22));
ui->statisticButton->setCursor(Qt::PointingHandCursor);
ui->ratesButton->setIcon(this->getWhiteIcon(":/nav-bar/glass-dollar.svg"));
ui->ratesButton->setIconSize(QSize(23,22));
ui->ratesButton->setCursor(Qt::PointingHandCursor);
ui->settingsButton->setIcon(this->getWhiteIcon(":/nav-bar/gear.svg"));
ui->settingsButton->setIconSize(QSize(23,22));
ui->settingsButton->setCursor(Qt::PointingHandCursor);
ui->contactsButton->setIcon(this->getWhiteIcon(":/nav-bar/mail.svg"));
ui->contactsButton->setIconSize(QSize(23,22));
ui->contactsButton->setCursor(Qt::PointingHandCursor);
// ui->supportButton->setIcon(this->getWhiteIcon(":/nav-bar/house.svg"));
// ui->supportButton->setIconSize(QSize(23,22));
}
void MainWindow::fillAccountData()
{
// Clear data
this->removeLayoutWidgets(ui->AccList->layout());
// Total account label
double totalValue = wallet->getTotalCount();
ui->TotalCountLabel->setText( QString::number(totalValue, 'f', 2) + QString::fromStdString(" " + wallet->getCurrencyType() ) );
if(QString::number(totalValue, 'f', 2).length() >= 13)
ui->TotalCountLabel->setStyleSheet("font: 600 31pt \"Segoe UI\";color:#ECEBDF;");
else if(QString::number(totalValue, 'f', 2).length() >= 10)
ui->TotalCountLabel->setStyleSheet("font: 600 34pt \"Segoe UI\";color:#ECEBDF;");
else
ui->TotalCountLabel->setStyleSheet("font: 600 42pt \"Segoe UI\";color:#ECEBDF;");
// Create cards
std::list<wlt::Account> acc_lst = this->wallet->getAccountList();
for(auto it = acc_lst.begin(); it != acc_lst.end(); it++ )
{
this->addAccountCard(it->getName(), it->getCount(), it->getCurrencyType());
}
// Create add_acc_button
if(this->wallet->AccountsCount() < 10)
{
QPushButton *addAccountButton = new QPushButton(tr( "Create new Account" ) );
addAccountButton->setMaximumSize(500, 80);
addAccountButton->setMinimumSize(350, 80);
addAccountButton->setStyleSheet("QPushButton{background-color:#1F2021; font: 600 14pt \"Segoe UI\";color:#ECEBDF;border: 5px solid #112D9F; } QPushButton:hover{background-color:#112D9F; font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
addAccountButton->setCursor(Qt::PointingHandCursor);
QObject::connect(addAccountButton, &QPushButton::clicked, this, [=](){ ui->mainWindow->setCurrentIndex(2); });
ui->AccList->layout()->addWidget( addAccountButton );
}
QSpacerItem *vertical_spacer = new QSpacerItem(20, 40, QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
ui->AccList->layout()->addItem(vertical_spacer);
}
void MainWindow::addAccountCard(std::string AccName, double Count, std::string Currency)
{
// Create account card example
//QWidget *accountCard = new QWidget();
AccountCardWidget *accountCard = new AccountCardWidget();
accountCard->setAccountName(AccName);
QHBoxLayout *layout = new QHBoxLayout(accountCard);
accountCard->setMinimumSize(350, 80);
accountCard->setMaximumSize(500, 80);
//accountCard->setStyleSheet("QWidget#AccountCardWidget{background-color:rgb(86, 86, 86);}");
// Create leftside icon
QWidget *iconBG = new QWidget();
iconBG->setMaximumSize(60, 60);
iconBG->setStyleSheet("QWidget{border-radius: 15px; background-color: #530FC8;}");
QLabel *icon = new QLabel();
//QPixmap iconImage(":/icons/wallet-solid.svg");
QPixmap iconImage = this->getWhiteIcon(":/icons/wallet-solid.svg");
icon->setPixmap(iconImage);
icon->setScaledContents(true);
icon->setGeometry(10, 10, 40, 40);
icon->setParent(iconBG);
// Create data info labels
QVBoxLayout *dataLabelsLayout = new QVBoxLayout();
QLabel *CountLabel = new QLabel();
QLabel *AccLabel = new QLabel();
QString Count_str = QString::number(Count, 'f', 2);
CountLabel->setText(Count_str + QString::fromStdString(" " + Currency));
AccLabel->setText(QString::fromStdString(AccName));
if(Count_str.length() >= 10)
CountLabel->setStyleSheet("QLabel{font: 600 12pt \"Segoe UI\";color:#ECEBDF;}");
else
CountLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
AccLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
dataLabelsLayout->addWidget(AccLabel);
dataLabelsLayout->addWidget(CountLabel);
// Create right-side buttons
QPushButton *addButton = new QPushButton();
QPushButton *editButton = new QPushButton();
addButton->setMaximumSize(50, 50);
editButton->setMaximumSize(50, 50);
//addButton->setText(QString("+"));
//addButton->setIcon(QIcon(this->getWhiteIcon("")));
//editButton->setText(QString("E"));
addButton->setIcon(QIcon(this->getWhiteIcon(":/utility-icons/plus.svg") ) );
addButton->setIconSize(QSize(35,35));
editButton->setIcon(QIcon(this->getWhiteIcon(":/utility-icons/edit.svg") ) );
editButton->setIconSize(QSize(30,30));
addButton->setStyleSheet("QPushButton{border: 3px solid #112D9F;background-color:#1F2021;border-radius:15px;} QPushButton:hover{background-color:#112D9F;border-radius:15px;}");
editButton->setStyleSheet("QPushButton{border: 3px solid #112D9F;background-color:#1F2021;border-radius:15px;} QPushButton:hover{background-color:#112D9F;border-radius:15px;}");
addButton->setToolTip("<html><head/><body><p><span style=\" font-size:12pt; color:#ffffff;\">" + tr("Create a new note") + "</span></p></body></html>");
editButton->setToolTip("<html><head/><body><p><span style=\" font-size:12pt; color:#ffffff;\">" + tr("Edit this account") + "</span></p></body></html>");
QGraphicsOpacityEffect *effect_add = new QGraphicsOpacityEffect();
QGraphicsOpacityEffect *effect_edit = new QGraphicsOpacityEffect();
addButton->setGraphicsEffect(effect_add);
editButton->setGraphicsEffect(effect_edit);
effect_add->setOpacity(0);
effect_edit->setOpacity(0);
// add note button logic
QObject::connect(addButton, &QPushButton::clicked, addButton, [=](){
QString accountNamefromCard = QString::fromStdString( accountCard->getAccountName() );
this->addNoteFormUpdate();
ui->accountMainComboBox->setCurrentText(accountNamefromCard);
this->AccountComboBoxChangedInAddNoteForm();
ui->mainWindow->setCurrentIndex(1);
});
// edit account button logic
QObject::connect(editButton, &QPushButton::clicked, editButton, [=](){
QString accountNamefromCard = QString::fromStdString( accountCard->getAccountName() );
this->editAccountFormUpdate();
ui->accountNameComboBox_edit->setCurrentText(accountNamefromCard);
ui->mainWindow->setCurrentIndex(4);
});
// adding some animation effects
QObject::connect(accountCard, &AccountCardWidget::MouseInSignal, this, [=](){
effect_add->setOpacity(1);
effect_edit->setOpacity(1);
});
QObject::connect(accountCard, &AccountCardWidget::MouseOutSignal, this, [=](){
effect_add->setOpacity(0);
effect_edit->setOpacity(0);
});
addButton->setCursor(Qt::PointingHandCursor);
editButton->setCursor(Qt::PointingHandCursor);
// Adding all elements to main layout
layout->addWidget(iconBG);
layout->addLayout(dataLabelsLayout);
layout->addWidget(addButton);
layout->addWidget(editButton);
// Creating card to ui interface
ui->AccList->layout()->addWidget( accountCard );
}
void MainWindow::fillNoteData()
{
this->removeLayoutWidgets(ui->NoteList->layout());
std::list<wlt::Note> note_lst = this->wallet->getNoteListLast(7);
for(auto it = note_lst.begin(); it != note_lst.end(); it++)
{
ui->NoteList->layout()->addWidget( this->addNoteCard(it->getOperation(), it->getCategoryString(), it->getAccountName(), it->getAccountNameAddit(), it->getValue(),
it->getDetails(), it->getDay(), it->getMonth(), it->getYear(), it->getId()) );
}
if(note_lst.size() == 0)
{
QLabel *emptyNoteListLabel = new QLabel();
emptyNoteListLabel->setText(tr("No operations yet"));
emptyNoteListLabel->setAlignment(Qt::AlignHCenter);
emptyNoteListLabel->setMinimumSize(QSize(250, 50));
emptyNoteListLabel->setMaximumSize(QSize(1500, 50));
emptyNoteListLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
ui->NoteList->layout()->addWidget(emptyNoteListLabel);
return;
}
QSpacerItem *vertical_spacer = new QSpacerItem(30, 40, QSizePolicy::Maximum, QSizePolicy::Expanding);
ui->NoteList->layout()->addItem(vertical_spacer);
}
QWidget *MainWindow::addNoteCard(wlt::Operation operation, std::string category, std::string accName, std::string accNameAddit,
double value, std::string details, unsigned int day, unsigned int month, unsigned int year, unsigned long ID)
{
// Create Note Card example
// QWidget *noteCard = new QWidget();
NoteCardWidget *noteCard = new NoteCardWidget();
noteCard->setID(ID);
QHBoxLayout *layout = new QHBoxLayout(noteCard);
noteCard->setMinimumSize(450, 80);
noteCard->setMaximumSize(500, 80);
noteCard->setCursor(Qt::PointingHandCursor);
//noteCard->setStyleSheet("NoteCardWidget{ background-color:rgb(86, 86, 86); }");
// Creating left-side icon
QWidget *iconBG = new QWidget();
iconBG->setMaximumSize(60, 60);
//iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #0B3CFF;}");
QLabel *icon = new QLabel();
QPixmap iconImage;
//QPixmap iconImage(":/icons/money-bill-solid.svg");
//QPixmap iconImage = this->getWhiteIcon(":/icons/money-bill-solid.svg");
QString categoryString = QString::fromStdString(category);
// Dynamic icon changing
if(categoryString == "Food")
{
iconImage = this->getWhiteIcon(":/icons/food.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #4A5A73;}");
categoryString = tr("Food");
}
else if(categoryString == "Products")
{
iconImage = this->getWhiteIcon(":/icons/shopping-bag.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #009DFF;}");
categoryString = tr("Products");
}
else if(categoryString == "Healthcare")
{
iconImage = this->getWhiteIcon(":/icons/med.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #0FAE56;}");
categoryString = tr("Healthcare");
}
else if(categoryString == "Public Transport")
{
iconImage = this->getWhiteIcon(":/icons/bus.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #9B9489;}");
categoryString = tr("Public Transport");
}
else if(categoryString == "Vehicle")
{
iconImage = this->getWhiteIcon(":/icons/car.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #95005E;}");
categoryString = tr("Vehicle");
}
else if(categoryString == "Entertainment")
{
iconImage = this->getWhiteIcon(":/icons/smile.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #CC8B00;}");
categoryString = tr("Entertainment");
}
else if(categoryString == "Network")
{
iconImage = this->getWhiteIcon(":/icons/wifi.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #0B3CFF;}");
categoryString = tr("Communication and internet");
}
else if(categoryString == "Finance Expensies")
{
iconImage = this->getWhiteIcon(":/icons/money.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #AFBB02;}");
categoryString = tr("Finance Expensies");
}
else if(categoryString == "Transfer operation")
{
iconImage = this->getWhiteIcon(":/icons/money-trans.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #C95045;}");
categoryString = tr("Transfer operation");
}
else if(categoryString == "Earnings")
{
iconImage = this->getWhiteIcon(":/icons/coins.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #C1B318;}");
categoryString = tr("Earnings");
}
else
{
iconImage = this->getWhiteIcon(":/icons/money-bill-solid.svg");
iconBG->setStyleSheet("QWidget{border-radius: 30px; background-color: #0B3CFF;}");
}
icon->setPixmap(iconImage);
icon->setScaledContents(true);
icon->setGeometry(15, 15, 31, 31);
icon->setParent(iconBG);
// Creating center info labels
QVBoxLayout *centerDataLayout = new QVBoxLayout();
QLabel *categoryLabel = new QLabel();
QLabel *accountNameLabel = new QLabel();
QString acc_name_correct = QString::fromStdString( accName );
if(acc_name_correct.size() >= 18)
{
acc_name_correct.truncate(18);
acc_name_correct.insert(19, '.');
acc_name_correct.insert(20, '.');
acc_name_correct.insert(21, '.');
}
// categoryLabel->setText( QString::fromStdString(category) );
categoryLabel->setText( categoryString );
accountNameLabel->setText( acc_name_correct );
if(categoryLabel->text().size() >= 15)
categoryLabel->setStyleSheet("QLabel{font: 600 13pt \"Segoe UI\";color:#ECEBDF;}");
else
categoryLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
accountNameLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
centerDataLayout->addWidget(categoryLabel);
centerDataLayout->addWidget(accountNameLabel);
// Creating right-side Count info labels
QVBoxLayout *rightSideLayout = new QVBoxLayout();
QLabel *valueLabel = new QLabel();
QLabel *dateLabel = new QLabel();
QString CurrencyType = QString::fromStdString( " " + wallet->getCurrencyFromAccName(accName) );
QString MonthStr = this->fromIntToMonth(month);
QString Year = QString::number(year);
valueLabel->setText( QString::number(value, 'f', 1) + CurrencyType);
dateLabel->setText( QString::number(day) + " " + MonthStr + " " + Year);
valueLabel->setAlignment(Qt::AlignRight);
dateLabel->setAlignment(Qt::AlignRight);
switch(operation)
{
case wlt::Operation::EXPENSE: valueLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#CE4D4D;}");
break;
case wlt::Operation::INCOME: valueLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#54CE4D;}");
break;
case wlt::Operation::TRANSFER: valueLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#CEBB4D;}");
break;
default: valueLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
break;
}
dateLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");
rightSideLayout->addWidget(valueLabel);
rightSideLayout->addWidget(dateLabel);
// Adding all elements to main layout
layout->addWidget(iconBG);
layout->addLayout(centerDataLayout);
layout->addLayout(rightSideLayout);
QObject::connect(noteCard, &NoteCardWidget::clickedSignal, this, [=](){
this->editNoteFormUpdate(noteCard->getID());
this->ID = noteCard->getID();
ui->mainWindow->setCurrentIndex(3);
});
return noteCard;
// Creating card to ui interface
//ui->NoteList->layout()->addWidget(noteCard);
}
void MainWindow::fillRatesData()
{
this->removeLayoutWidgets(ui->RatesList->layout());
if(this->wallet->isRatesEmpty())
{
QLabel *emptyNoteListLabel = new QLabel();
emptyNoteListLabel->setText( tr("Connect to internet to get Rates data") );
emptyNoteListLabel->setAlignment(Qt::AlignHCenter);
emptyNoteListLabel->setMinimumSize(QSize(250, 50));
emptyNoteListLabel->setMaximumSize(QSize(1500, 50));
emptyNoteListLabel->setStyleSheet("QLabel{font: 600 14pt \"Segoe UI\";color:#ECEBDF;}");