-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
879 lines (654 loc) · 23.6 KB
/
mainwindow.cpp
File metadata and controls
879 lines (654 loc) · 23.6 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
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Moshe Wagner. <moshe.wagner@gmail.com>
*
* Special thanks given to ארתיום בייליס, for the great help with gettext on windows. Thanks.
*
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
/*
Cross-Platform Kaluach clone:
Provides:
- Basic calandar interface:
- Hebrew / English date
- Hebrew / English interface
- Change date, location, timezone
- Zmanim obainted from ZmanimCLI
- Daf yomi ,(eventually should have other "yomi" stuff too)
- Print snapshots
Stuff to add:
- Events
- Haftarot
- Dalvening calculation
- Other cool features ;-)
*/
//TODO: Add zmanim shitot choosing
//TODO: Add translation option?
// Update hebrew translation
//TODO: Test on windows
//TODO: Check zmanimcli location before using it
//TODO: Purim katan
//TODO: Add a list of pre-defined places
//TODO: Add windows resource file
//TODO: System tray icon
//TODO: Special shabatot
//TODO: ברכת החמה
//TODO: Comments!!!
//List of all day button shown
QList <dayButton *> dayList;
//Points to the selected button
dayButton * lastselected;
QStringList weekdays;
vector <QLabel *> weekdaylbls;
QStringList engmonths;
QProcess *zmanimproc;
//Default is Jerusalem
QString locationName;
double latitude; //קו רוחב
double longitude; //קו אורך
QString TimeZone;
double elevation;
double candleLightingOffset;
bool hool;
bool ShowGDate;
bool ShowZmanim;
QString LANG;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Restores the window's state from the last run
restoreWindowState();
//Set all QString to work with unicode
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
setWindowIcon(QIcon(":/Icons/calendar.png"));
setWindowTitle(tr("Luach"));
connect( ¤t, SIGNAL(month_changed()), this, SLOT(redraw()));
removeDockWidget(ui->dockWidget);
addDockWidget(Qt::LeftDockWidgetArea, ui->dockWidget);
ui->dockWidget->show();
loadConfs();
weekdays << tr("Sunday") << tr("Monday") << tr("Tuesday") << tr("Wednesday") << tr("Thursday") << tr("Friday") << tr("Saturday");
engmonths << tr("January") << tr("February") << tr("March") << tr("April") << tr("May") << tr("June") << tr("July") << tr("August") << tr("September") << tr("October") << tr("November") << tr("December");
//Adjust for hebrew if needed
if (LANG == "Hebrew") toRTL();
lastselected = NULL;
connect(ui->exitaction, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->settingsaction, SIGNAL(triggered()), this, SLOT(settingsForm()));
connect(ui->gdateaction, SIGNAL(toggled(bool)), this, SLOT(toggleGDate(bool)));
connect(ui->zmanimpanelaction, SIGNAL(triggered(bool)), this, SLOT(toggleZmanimPanel(bool)));
connect(ui->aboutaction, SIGNAL(triggered()), this, SLOT(aboutForm()));
connect(ui->actionZmanim_accuracy, SIGNAL(triggered()), this, SLOT(ZmanimAccuracyForm()));
connect(ui->actionZmanim_used, SIGNAL(triggered()), this, SLOT(ZmanimInfoForm()));
connect(ui->printaction, SIGNAL(triggered()), this, SLOT(printSnap()));
connect(ui->todayAction, SIGNAL(triggered()), this, SLOT(todayAction()));
//Add weekday labels
for (int i=0; i<7; i++)
{
QLabel *lbl = new QLabel(weekdays[i]);
lbl->setLayoutDirection(Qt::RightToLeft);
lbl->setAlignment(Qt::AlignCenter);
ui->gridLayout->addWidget(lbl, 0, i);
QFont q;
q.setPixelSize(19);
lbl->setFont(q);
weekdaylbls.push_back(lbl);
//lbl->setStyleSheet("QLabel { background-color: blue }");
}
//Create the day buttons: (Invisible for now)
for (int i = 0; i<30; i++)
{
dayButton *d = new dayButton(this, 0, ShowGDate, hool);
dayList << d;
d->hide();
connect(d, SIGNAL(clicked(dayButton*)), this, SLOT(dayClicked(dayButton*)));
}
for (int i=0; i<ui->gridLayout->count(); i++) ui->gridLayout->setRowStretch(i,1);
initZmanim();
//A Hdate starts with todays date, so "current" is set to today
showMonth(¤t);
//Current time (do something with this):
//QTime t;
//print (t.currentTime().toString());
//Hide candel lighting labels
ui->clllbllbl->hide();
ui->candellightinglbl->hide();
ui->tslbl->hide();
ui->tslbllbl->hide();
ui->grpbox->hide();
}
MainWindow::~MainWindow()
{
saveDispConfs();
delete zmanimproc;
clearMonth();
delete ui;
}
//Restores the window's state from the last run
void MainWindow::restoreWindowState()
{
QSettings settings("Luach", "user");
settings.beginGroup("MainWindow");
QDesktopWidget *widget = QApplication::desktop();
int desktop_width = widget->width();
int desktop_height = widget->height();
restoreState(settings.value("state", "").toByteArray());
resize(settings.value("size", QSize(desktop_width, desktop_height-50)).toSize());
move(settings.value("pos", QPoint(0, 0)).toPoint());
settings.endGroup();
}
//Overrides the normal "closeEvent", so it can save tha window's state before quiting
void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings("Luach", "user");
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.setValue("state", saveState());
settings.endGroup();
}
void MainWindow::toRTL()
{
setLayoutDirection(Qt::RightToLeft);
ui->centralWidget->setLayoutDirection(Qt::RightToLeft);
ui->horizontalLayout->setDirection(QBoxLayout::RightToLeft);
ui->horizontalLayout_2->setDirection(QBoxLayout::RightToLeft);
ui->horizontalLayout_3->setDirection(QBoxLayout::RightToLeft);
ui->horizontalLayout_4->setDirection(QBoxLayout::RightToLeft);
ui->horizontalLayout_5->setDirection(QBoxLayout::RightToLeft);
ui->horizontalLayout_6->setDirection(QBoxLayout::RightToLeft);
ui->dockWidget->setLayoutDirection(Qt::RightToLeft);
removeDockWidget(ui->dockWidget);
addDockWidget(Qt::RightDockWidgetArea, ui->dockWidget);
if (ShowZmanim) ui->dockWidget->show();
ui->menu->setLayoutDirection(Qt::RightToLeft);
ui->menu_2->setLayoutDirection(Qt::RightToLeft);
ui->menu_3->setLayoutDirection(Qt::RightToLeft);
ui->menuBar->setLayoutDirection(Qt::RightToLeft);
}
//Rebuild the calendar from the given first day of the month
void MainWindow::showMonth(hdate::Hdate *dayinmonth)
{
//Clear last month
for (int i = 0; i<30; i++)
{
ui->gridLayout->removeWidget(dayList[i]);
dayList[i]->hide();
}
//Go to first day of the month
hdate::Hdate firstday;
firstday.set_hdate(1, dayinmonth->get_hmonth(), dayinmonth->get_hyear());
hdate::Hdate tmpday;
tmpday.set_hdate(firstday.get_hday(), firstday.get_hmonth(), firstday.get_hyear());
int jd = tmpday.get_julian();
int firstweekday = firstday.get_day_of_the_week()-1;
QSize widest(0,0);
//Set and add all dayButtons to where they should be:
for (int i = firstweekday; tmpday.get_hmonth() == firstday.get_hmonth(); i++)
{
//
//print (tmpday.get_format_date(0));
dayButton *d = dayList[i-firstweekday];
d->resetDate(jd, hool, ShowGDate);
d->show();
ui->gridLayout->addWidget(d, 1+(i/7), (i%7));
jd++;
tmpday.set_jd(jd);
//Find the biggest button's minimum size
if (d->sizeHint().width() > widest.width()) widest = d->sizeHint();
}
if (lastselected != NULL) lastselected->Unselect();
/*
//Force all buttons to the size of the biggest one
for (int i = 0; i<dayList.size(); i++)
{
dayList[i]->setMinimumSize(widest);
}
*/
if (current.get_julian() - firstday.get_julian() >= 0 && current.get_julian() - firstday.get_julian() < dayList.size())
{
dayList[current.get_julian() - firstday.get_julian()]->Select();
lastselected = dayList[current.get_julian() - firstday.get_julian()];
}
//A defualt Hdate class has today's date
hdate::Hdate today;
//Mark today
if (firstday.get_hmonth() == today.get_hmonth() && firstday.get_hyear() == today.get_hyear()) dayList[today.get_julian() - firstday.get_julian()]->setToday();
updateLabels(¤t);
}
void MainWindow::clearMonth()
{
for (int i = 0; i<dayList.size(); i++) delete dayList[i];
dayList.clear();
lastselected = NULL;
}
void MainWindow::redraw()
{
showMonth(¤t);
}
void MainWindow::dayClicked(dayButton * day)
{
if (lastselected != NULL) lastselected->Unselect();
day->Select();
lastselected = day;
current.set_jd(day->getHDate()->get_julian());
updateLabels(¤t);
}
void MainWindow::todayAction()
{
hdate::Hdate today;
current.set_jd(today.get_julian());
showMonth(¤t);
}
//Change the current day by the given offset
void MainWindow::changeDay(int i)
{
if (i < 0) for (int j=0; j > i; j--) current.removeDay();
else for (int j=0; j < i; j++) current.addDay();
if (lastselected != NULL) lastselected->Unselect();
dayList[current.get_julian() - dayList[0]->getHDate()->get_julian()]->Select();
lastselected = dayList[current.get_julian() - dayList[0]->getHDate()->get_julian()];
updateLabels(¤t);
}
void MainWindow::updateLabels(mHdate *date)
{
ui->monthlabel->setText(date->get_hebrew_month_string(0));
ui->yearlabel->setText(date->get_hebrew_year_string());
ui->engyearlbl->setText(stringify(date->get_gyear()));
ui->hmonthlbl->setText(date->get_hebrew_month_string(0));
ui->daylabel->setText(current.hebday());
ui->engdaylbl->setText(stringify(current.get_gday()));
ui->engmonthlbl->setText(engmonths[current.get_gmonth() - 1]);
hdate::Hdate e;
e.set_hdate(1, date->get_hmonth(), date->get_hyear());
QString gmonths = engmonths[e.get_gmonth() - 1];
e.set_hdate(date->getMonthLength(), date->get_hmonth(), date->get_hyear());
if (engmonths[e.get_gmonth()-1] != gmonths) gmonths += " - " + engmonths[e.get_gmonth()-1];
ui->gmonthlbl->setText(gmonths);
if (dafYomi(current.get_julian()) != "")
{
ui->dafyomilbl->show();
ui->dafyomilbl->setText(tr("Day Yomi - ") + dafYomi(current.get_julian()));
}
else ui->dafyomilbl->hide();
getZmanim(date);
}
void MainWindow::initZmanim()
{
zmanimproc = new QProcess(this);
times << "Alos90";
timeNames << tr("Alos (90 min)");
times << "Alos72";
timeNames << tr("Alos (72 min)");
times << "Misheyakir11Degrees";
timeNames << tr("Misheyakir");
times << "Sunrise";
timeNames << tr("Sunrise");
times << "SofZmanShmaMGA72Minutes";
timeNames << tr("Shma MGA");
times << "SofZmanShmaGRA";
timeNames << tr("Shma GRA");
times << "SofZmanTfilaMGA72Minutes";
timeNames << tr("Tfila MGA");
times << "SofZmanTfilaGRA";
timeNames << tr("Tfila GRA");
times << "Chatzos";
timeNames << tr("Chatzos");
times << ("MinchaGedola");
timeNames << tr("Mincha Gedola");
times << ("MinchaKetana");
timeNames << tr("Mincha Ketana");
times << "Sunset";
timeNames << tr("Sunset");
times << "Sunset";
timeNames << tr("Tzais (24 min)");
times << "Tzais72";
timeNames << tr("Tzais 72");
}
void MainWindow::getZmanim(mHdate *date)
{
// Invokes an istance of ZmanimCLI, telling it to give a list of times for our location and date;
// The output is sent to "gotTimes()" which updates the time labels by that.
QStringList args;
QString dstr = stringify(date->get_gyear()) + "/" + stringify(date->get_gmonth()) + "/" + stringify(date->get_gday());
args << "-d" << dstr << "-lat" << stringify(latitude) << "-lon" << stringify(longitude) << "-tz" << TimeZone << times;
//Invoke externall zmanim process
zmanimproc->start("./zmanimcli", args);
connect(zmanimproc, SIGNAL(readyReadStandardOutput()), this, SLOT(gotTimes()));
ui->TimeNameLBL->clear();
ui->TimesLBL->clear();
ui->errframe->show();
}
#include <QDebug>
void MainWindow::gotTimes()
{
QString str = zmanimproc->readAllStandardOutput();
if (str.startsWith("ERROR:") || str.isEmpty())
{
//No Zmanim detected. An error message will be shown.
return;
}
ui->grpbox->show();
ui->errframe->hide();
QStringList times = str.split('\n');
for (int i=0; i<times.size() && i<timeNames.size(); i++)
{
times[i].replace('\r',"");
QString t = times[i].mid(times[i].lastIndexOf(" ") + 1);
//Add a leading 0 to 1 digit times
if (t.indexOf(":") == 1) t = "0" + t;
//Tzais 24 minutes after skiah
if(timeNames[i].indexOf("Tzais (24 min)") != -1)
{
ui->TimeNameLBL->setText(ui->TimeNameLBL->text() + timeNames[i] + ":" + "<br><small><br></small>");
t = QTime::fromString(t, "hh:mm").addSecs(60 * 24).toString("hh:mm");
ui->TimesLBL->setText(ui->TimesLBL->text() + t + "<br><small><br></small>");
}
else if (times[i][0] == '*')
{
ui->TimeNameLBL->setText(ui->TimeNameLBL->text() + timeNames[i] + ":" + "<br><small><br></small>");
ui->TimesLBL->setText(ui->TimesLBL->text() + t + "<br><small><br></small>");
if (times[i].startsWith("* Sunset:") == true)
{
//Candel lighting:
if (current.get_day_of_the_week() == 6 || current.isErevYomTov(hool))
{
ui->clllbllbl->show();
ui->candellightinglbl->show();
QTime sunset = QTime::fromString(t, "hh:mm");
QTime cl = sunset.addSecs(-1 * (candleLightingOffset * 60));
ui->candellightinglbl->setText(cl.toString("hh:mm"));
}
else
{
ui->clllbllbl->hide();
ui->candellightinglbl->hide();
}
}
}
}
//מוצאי שבת או חג
if (current.get_day_of_the_week() == 7 || current.isYomTov(hool))
{
ui->tslbllbl->show();
if ( current.isYomTov(hool)) ui->tslbllbl->setText(tr("Chag ends"));
if (current.get_day_of_the_week() == 7) ui->tslbllbl->setText(tr("Shabbos ends"));
ui->tslbl->show();
QProcess tzais;
QString dstr = stringify(current.get_gyear()) + "/" + stringify(current.get_gmonth()) + "/" + stringify(current.get_gday());
QStringList args;
args << "-d" << dstr << "-lat" << stringify(latitude) << "-lon" << stringify(longitude) << "-tz" << TimeZone << "TzaisGeonim8Point5Degrees";
tzais.start("zmanimcli", args);
tzais.waitForFinished();
QByteArray result = tzais.readAllStandardOutput().replace('\r',"");
ui->tslbl->setText(QString(result.mid(result.indexOf(":") + 1)));
//If there is any candle lighting today, it should be at tzais shabat,
// and not at the normal time. (unless it's a Yom tov on friday)
if (current.get_day_of_the_week() != 6)
{
ui->candellightinglbl->setText(result);
}
}
else
{
ui->tslbllbl->hide();
ui->tslbl->hide();
}
}
void MainWindow::saveConfs()
{
QSettings settings("Luach", "user");
settings.setValue("LocationName", locationName);
settings.setValue("Latitude", latitude);
settings.setValue("Longitude", longitude);
settings.setValue("TimeZone", TimeZone);
settings.setValue("Elevation", elevation);
settings.setValue("CandleLightingOffset", candleLightingOffset);
settings.setValue("isHool", hool);
}
void MainWindow::saveDispConfs()
{
QSettings settings("Luach", "user");
settings.setValue("ShowGDate", ShowGDate);
settings.setValue("ShowZmanim", ShowZmanim);
}
void MainWindow::loadConfs()
{
QSettings settings("Luach", "user");
//Default is Jerusalem
locationName = settings.value("LocationName", tr("Jerusalem, Israel")).toString();
latitude = settings.value("Latitude", 31.77805).toDouble();
longitude = settings.value("Longitude", 35.235149).toDouble();
TimeZone = settings.value("TimeZone", "Israel").toString();
elevation = settings.value("Elevation", 800).toDouble();
candleLightingOffset = settings.value("CandleLightingOffset", 18.0).toDouble();
hool = settings.value("isHool",false).toBool();
ShowGDate = settings.value("ShowGDate", true).toBool();
ui->gdateaction->setChecked(ShowGDate);
ShowZmanim = settings.value("ShowZmanim", true).toBool();
ui->zmanimpanelaction->setChecked(ShowZmanim);
}
void MainWindow::toggleGDate(bool show)
{
ShowGDate = show;
//In case this was triggred from somewhere else
ui->gdateaction->setChecked(show);
if (!dayList.isEmpty()) redraw();
ui->engdaylbl->setVisible(show);
ui->engmonthlbl->setVisible(show);
ui->engyearlbl->setVisible(show);
ui->gmonthlbl->setVisible(show);
ui->hmonthlbl->setVisible(show);
ui->nextgdayBTN->setVisible(show);
ui->backgdayBTN->setVisible(show);
ui->nextgmonthBTN->setVisible(show);
ui->backgmonthBTN->setVisible(show);
ui->nextgYearBTN->setVisible(show);
ui->doublenextgYearBTN->setVisible(show);
ui->backgYearBTN->setVisible(show);
ui->doublebackgYearBTN->setVisible(show);
if (show == false) for (int i=3; i<7; i++) ui->gridLayout_2->setColumnStretch(i,0);
else for (int i=0; i<7; i++) ui->gridLayout_2->setColumnStretch(i,100);
}
void MainWindow::toggleZmanimPanel(bool show)
{
ShowZmanim = show;
ui->dockWidget->setVisible(show);
}
void MainWindow::on_dockWidget_visibilityChanged(bool visible)
{
ui->zmanimpanelaction->setChecked(visible);
}
settings *cl;
void MainWindow::settingsForm()
{
cl = new settings (this, &locationName, &latitude, &longitude, &candleLightingOffset, &TimeZone, &elevation, &hool);
connect(cl, SIGNAL(changed()), this, SLOT(redraw()));
connect(cl, SIGNAL(save()), this, SLOT(saveConfs()));
cl->show();
}
void MainWindow::aboutForm()
{
about = new About("About");
about->show();
}
void MainWindow::ZmanimInfoForm()
{
about = new About("Shitot");
about->show();
}
void MainWindow::ZmanimAccuracyForm()
{
about = new About("Accuracy");
about->show();
}
void MainWindow::keyPressEvent( QKeyEvent *keyEvent )
{
if ( keyEvent->key() == Qt::Key_Left)
{
if (LANG=="Hebrew") changeDay(1);
else changeDay(-1);
}
else if ( keyEvent->key() == Qt::Key_Right)
{
if (LANG=="Hebrew") changeDay(-1);
else changeDay(1);
}
else if ( keyEvent->key() == Qt::Key_Up)
{
//Move week back:
changeDay(-7);
}
else if ( keyEvent->key() == Qt::Key_Down)
{
//Move week ahead:
changeDay(7);
}
else if ( keyEvent->key() == Qt::Key_PageUp)
{
//Move month back:
current.removeMonth();
}
else if ( keyEvent->key() == Qt::Key_PageDown)
{
//Move month ahead:
current.addMonth();
}
}
void MainWindow::on_backMonthBTN_clicked()
{
if (LANG=="Hebrew") current.removeMonth();
else current.addMonth();
}
void MainWindow::on_nextMonthBTN_clicked()
{
if (LANG=="Hebrew") current.addMonth();
else current.removeMonth();
}
void MainWindow::on_backYearBTN_clicked()
{
if (LANG=="Hebrew") current.removeYear();
else current.addYear();
}
void MainWindow::on_nextYearBTN_clicked()
{
if (LANG=="Hebrew") current.addYear();
else current.removeYear();
}
void MainWindow::on_backDayBTN_clicked()
{
if (LANG=="Hebrew") changeDay(-1);
else changeDay(1);
}
void MainWindow::on_nextDayBTN_clicked()
{
if (LANG=="Hebrew") changeDay(1);
else changeDay(-1);
}
void MainWindow::on_doublenextYearBTN_clicked()
{
if (LANG=="Hebrew") current.addYear(10);
else current.removeYear(10);
}
void MainWindow::on_doublebackYearBTN_clicked()
{
if (LANG=="Hebrew") current.removeYear(10);
else current.addYear(10);
}
void MainWindow::on_backgdayBTN_clicked()
{
if (LANG=="Hebrew") changeDay(-1);
else changeDay(1);
}
void MainWindow::on_nextgdayBTN_clicked()
{
if (LANG=="Hebrew") changeDay(1);
else changeDay(-1);
}
void MainWindow::on_backgmonthBTN_clicked()
{
if (LANG=="Hebrew")
{
if (current.get_gmonth() > 1) current.set_gdate(current.get_gday(), current.get_gmonth()-1, current.get_gyear());
else current.set_gdate(current.get_gday(), 12, current.get_gyear()-1);
}
else
{
if (current.get_gmonth() < 12) current.set_gdate(current.get_gday(), current.get_gmonth()+1, current.get_gyear());
else current.set_gdate(current.get_gday(), 1, current.get_gyear()+1);
}
showMonth(¤t);
}
void MainWindow::on_nextgmonthBTN_clicked()
{
if (LANG=="Hebrew")
{
if (current.get_gmonth() < 12) current.set_gdate(current.get_gday(), current.get_gmonth()+1, current.get_gyear());
else current.set_gdate(current.get_gday(), 1, current.get_gyear()+1);
}
else
{
if (current.get_gmonth() > 1) current.set_gdate(current.get_gday(), current.get_gmonth()-1, current.get_gyear());
else current.set_gdate(current.get_gday(), 12, current.get_gyear()-1);
}
showMonth(¤t);
}
void MainWindow::on_backgYearBTN_clicked()
{
if (LANG=="Hebrew") current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()-1);
else current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()+1);
showMonth(¤t);
}
void MainWindow::on_nextgYearBTN_clicked()
{
if (LANG=="Hebrew") current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()+1);
else current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()-1);
showMonth(¤t);
}
void MainWindow::on_doublebackgYearBTN_clicked()
{
if (LANG=="Hebrew") current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()-10);
else current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()+10);
showMonth(¤t);
}
void MainWindow::on_doublenextgYearBTN_clicked()
{
if (LANG=="Hebrew") current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()+10);
else current.set_gdate(current.get_gday(), current.get_gmonth(), current.get_gyear()-10);
showMonth(¤t);
}
void MainWindow::printSnap()
{
ui->dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
QPixmap pix = QPixmap::grabWidget(this, 10, ui->menuBar->height(), this->width(), this->height());
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle("הדפס ספר");
if (dialog->exec() != QDialog::Accepted)
return;
else
{
printer.setOrientation(QPrinter::Landscape);
if (pix.width() > printer.width())
{
pix = pix.scaledToWidth(printer.width(), Qt::SmoothTransformation);
}
QPainter painter;
painter.begin(&printer);
painter.drawPixmap (0, 0, pix);
painter.end();
}
ui->dockWidget->setFeatures(QDockWidget::DockWidgetClosable);
}