@@ -34,23 +34,13 @@ CalendarWindow::CalendarWindow(QWidget *parent) :
3434 }
3535 // Initialize current date to today's date
3636 QDate currentDate = QDate::currentDate ();
37-
38- // Month names for Gregorian and Bikram Sambat calendars
39- QStringList gregorianMonths = {" जनवरी" , " फेब्रुअरी" , " मार्च" , " अप्रिल" , " मे" , " जुन" ,
40- " जुलाई" , " अगस्ट" , " सेप्टेम्बर" , " अक्टोबर" , " नोभेम्बर" , " डिसेम्बर" };
41-
42- QStringList bikramMonths = {" बैशाख" , " जेठ" , " असार" , " श्रावण" , " भाद्र" ,
43- " आश्विन" , " कार्तिक" , " मंसिर" , " पौष" , " माघ" ,
44- " फाल्गुन" , " चैत" };
45-
46-
4737 // Populate AD combo boxes
4838 for (int year = 1900 ; year <= 2100 ; ++year) {
4939 ui->yearselectAD ->addItem (QString::number (year));
5040 ui->yearselectAD ->setEditable (true );
5141 }
52- for (const QString & month : gregorianMonths ) {
53- ui->monthselectAD ->addItem (month);
42+ for (int month = 1 ; month <= 12 ; ++month ) {
43+ ui->monthselectAD ->addItem (getEnglishMonthName ( month) );
5444 }
5545 for (int day = 1 ; day <= 31 ; ++day) {
5646 ui->dayselectAD ->addItem (QString::number (day));
@@ -61,9 +51,13 @@ CalendarWindow::CalendarWindow(QWidget *parent) :
6151 ui->yearselectBS ->addItem (QString::number (year));
6252 ui->yearselectBS ->setEditable (true );
6353 }
64- for (const QString & month : bikramMonths ) {
65- ui->monthselectBS ->addItem (month);
54+ for (int month = 1 ; month <= 12 ; ++month ) {
55+ ui->monthselectBS ->addItem (getBikramMonthName ( month) );
6656 }
57+ int year = ui->yearselectBS ->currentText ().toInt ();
58+ int month = ui->monthselectBS ->currentIndex () + 1 ;
59+ populateBsDays (year, month);
60+
6761
6862 // Set current date in AD combo boxes
6963 ui->yearselectAD ->setCurrentText (QString::number (currentDate.year ()));
@@ -103,6 +97,12 @@ CalendarWindow::CalendarWindow(QWidget *parent) :
10397 connect (ui->yearselectBS , QOverload<int >::of (&QComboBox::currentIndexChanged), this , &CalendarWindow::onBsYearChanged);
10498 connect (ui->monthselectBS , QOverload<int >::of (&QComboBox::currentIndexChanged), this , &CalendarWindow::onBsMonthChanged);
10599 connect (ui->dayselectBS , QOverload<int >::of (&QComboBox::currentIndexChanged), this , &CalendarWindow::onBsDayChanged);
100+ connect (ui->previousMonthButton_2 , &QPushButton::clicked, this , &CalendarWindow::onpreviousMonthButtonclicked);
101+ connect (ui->nextMonthButton , &QPushButton::clicked, this , &CalendarWindow::onnextMonthButtonclicked);
102+
103+
104+
105+
106106 connect (ui->todayButton , &QPushButton::clicked, this , &CalendarWindow::ontodayButtonclicked);
107107
108108 // Initialize the calendar
@@ -120,6 +120,42 @@ bool CalendarWindow::eventFilter(QObject *object, QEvent *event) {
120120 return QMainWindow::eventFilter (object, event);
121121}
122122
123+ const QStringList CalendarWindow::bikramMonths = {
124+ " वैशाख" , " जेठ" , " असार" , " श्रावण" , " भाद्र" ,
125+ " आश्विन" , " कार्तिक" , " मंसिर" , " पौष" , " माघ" ,
126+ " फाल्गुन" , " चैत्र"
127+ };
128+ const QStringList CalendarWindow::gregorianMonths = {" जनवरी" , " फेब्रुअरी" , " मार्च" , " अप्रिल" , " मे" , " जुन" ,
129+ " जुलाई" , " अगस्ट" , " सेप्टेम्बर" , " अक्टोबर" , " नोभेम्बर" , " डिसेम्बर" };
130+
131+ QString CalendarWindow::getBikramMonthName (int month) {
132+ if (month < 1 || month > 12 ) {
133+ return " " ; // Return an empty string for invalid month
134+ }
135+ return bikramMonths.at (month - 1 ); // Assuming 1-based month input
136+ }
137+ QString CalendarWindow::getEnglishMonthName (int month) {
138+ if (month < 1 || month > 12 ) {
139+ return " " ; // Return an empty string for invalid month
140+ }
141+ return gregorianMonths.at (month - 1 ); // Assuming 1-based month input
142+ }
143+
144+ QString CalendarWindow::convertToNepaliNumerals (int number) {
145+ QString nepaliNumerals = QString::number (number);
146+ nepaliNumerals.replace (" 0" , " ०" );
147+ nepaliNumerals.replace (" 1" , " १" );
148+ nepaliNumerals.replace (" 2" , " २" );
149+ nepaliNumerals.replace (" 3" , " ३" );
150+ nepaliNumerals.replace (" 4" , " ४" );
151+ nepaliNumerals.replace (" 5" , " ५" );
152+ nepaliNumerals.replace (" 6" , " ६" );
153+ nepaliNumerals.replace (" 7" , " ७" );
154+ nepaliNumerals.replace (" 8" , " ८" );
155+ nepaliNumerals.replace (" 9" , " ९" );
156+ return nepaliNumerals;
157+ }
158+
123159void CalendarWindow::ontodayButtonclicked () {
124160 // Get today's date
125161 QDate today = QDate::currentDate ();
@@ -155,7 +191,33 @@ void CalendarWindow::ontodayButtonclicked() {
155191 // Update the calendar
156192 updateCalendar (bsYear, bsMonth);
157193}
194+ // Slot for Previous Month button
195+ void CalendarWindow::onpreviousMonthButtonclicked () {
196+ int currentIndex = ui->monthselectBS ->currentIndex ();
197+
198+ if (currentIndex > 0 ) {
199+ ui->monthselectBS ->setCurrentIndex (currentIndex - 1 );
200+ } else {
201+ // Wrap around to December
202+ ui->monthselectBS ->setCurrentIndex (11 ); // December (0-based index)
203+ }
204+
205+ // The change will automatically trigger the connected slot for month selection
206+ }
158207
208+ // Slot for Next Month button
209+ void CalendarWindow::onnextMonthButtonclicked () {
210+ int currentIndex = ui->monthselectBS ->currentIndex ();
211+
212+ if (currentIndex < 11 ) { // 11 is December
213+ ui->monthselectBS ->setCurrentIndex (currentIndex + 1 );
214+ } else {
215+ // Wrap around to January
216+ ui->monthselectBS ->setCurrentIndex (0 ); // January (0-based index)
217+ }
218+
219+ // The change will automatically trigger the connected slot for month selection
220+ }
159221
160222void CalendarWindow::resizeEvent (QResizeEvent* event) {
161223 QMainWindow::resizeEvent (event);
@@ -314,11 +376,12 @@ void CalendarWindow::onBsYearChanged(int /*index*/) {
314376
315377 int year = ui->yearselectBS ->currentText ().toInt ();
316378 int month = ui->monthselectBS ->currentIndex () + 1 ;
317- int day = ui->dayselectBS ->currentText ().toInt ();
318379
319380 // Update BS day combo box based on current month and year
320381 populateBsDays (year, month);
321382
383+ // Now, use the current day selection to update AD date
384+ int day = ui->dayselectBS ->currentText ().toInt ();
322385 updateAdDateFromBs (year, month, day);
323386
324387 // Update the calendar
@@ -327,15 +390,14 @@ void CalendarWindow::onBsYearChanged(int /*index*/) {
327390 blockSignals = false ;
328391}
329392
393+
330394void CalendarWindow::onBsMonthChanged (int /* index*/ ) {
331395 if (blockSignals) return ;
332396 blockSignals = true ;
333397
334398 int year = ui->yearselectBS ->currentText ().toInt ();
335399 int month = ui->monthselectBS ->currentIndex () + 1 ;
336400 int day = ui->dayselectBS ->currentText ().toInt ();
337- populateBsDays (year, month);
338- // Update BS day combo box based on current month and year
339401 updateAdDateFromBs (year, month, day);
340402
341403 // Update the calendar
@@ -344,6 +406,7 @@ void CalendarWindow::onBsMonthChanged(int /*index*/) {
344406 blockSignals = false ;
345407}
346408
409+
347410void CalendarWindow::onBsDayChanged (int /* index*/ ) {
348411 if (blockSignals) return ;
349412 blockSignals = true ;
@@ -353,8 +416,6 @@ void CalendarWindow::onBsDayChanged(int /*index*/) {
353416 int day = ui->dayselectBS ->currentText ().toInt ();
354417
355418 updateAdDateFromBs (year, month, day);
356- populateBsDays (year, month);
357-
358419 blockSignals = false ;
359420}
360421
@@ -400,15 +461,24 @@ void CalendarWindow::updateAdDateFromBs(int year, int month, int day) {
400461 ui->monthselectAD ->setCurrentIndex (gMonth - 1 );
401462 ui->dayselectAD ->setCurrentText (QString::number (gDay ));
402463
464+
403465 int bsDaysInMonth = converter.daysInMonth (year, month);
404466 QString bsMonthName = getBikramMonthName (month);
405- QString adMonthName = getEnglishMonthName (gMonth );
406- ui->output ->setText (QString (" अङ्ग्रेजी मिति मा परिवर्तन गरियो: %1 %2 %3 \n %4 %5 मा जम्मा दिन सङ्ख्या: %6" )
407- .arg (convertToNepaliNumerals (gYear )).arg (adMonthName).arg (convertToNepaliNumerals (gDay )).arg (bsMonthName).arg (convertToNepaliNumerals (year)).arg (convertToNepaliNumerals (bsDaysInMonth)));
467+ double julianDate = gregorianToJulian (gYear , gMonth , gDay );
468+ Panchang panchang (julianDate);
469+ QString tithiName = QString::fromStdString (tithi[(int )panchang.tithi_index ]);
470+ QString paksha = QString::fromStdString (panchang.paksha );
471+ QString tithipaksha = QString (" %1 %2" ).arg (paksha).arg (tithiName);
472+ ui->output ->setText (QString (" ईसवी सन मा परिवर्तन गरियो: %1 %2 %3 गते %5 \n %2 %1 मा जम्मा दिन सङ्ख्या: %4" )
473+ .arg (convertToNepaliNumerals (gYear )).arg (bsMonthName).arg (convertToNepaliNumerals (gDay )).arg (convertToNepaliNumerals (bsDaysInMonth)).arg (tithipaksha));
408474
475+ // Update the calendar
476+ updateCalendar (year, month);
477+ // Populate BS day combo box based on current month and year
409478 populateBsDays (year, month);
410479}
411480
481+
412482void CalendarWindow::updateCalendar (int year, int month) {
413483 int daysInMonth = converter.daysInMonth (year, month);
414484
@@ -568,3 +638,4 @@ void CalendarWindow::populateBsDays(int year, int month) {
568638 // Set the current day
569639 ui->dayselectBS ->setCurrentText (QString::number (currentDay));
570640}
641+
0 commit comments