Skip to content

Commit b255b9a

Browse files
committed
Merge branch 'main' of https://github.com/khumnath/nepdate
2 parents 284d9a0 + c49a741 commit b255b9a

File tree

6 files changed

+272
-126
lines changed

6 files changed

+272
-126
lines changed

.github/workflows/c-cpp.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v2
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: '3.11'
17+
18+
- name: Install Qt
19+
uses: jurplel/install-qt-action@v3
20+
with:
21+
aqtversion: '==3.1.*'
22+
version: '6.2.0'
23+
host: 'linux'
24+
target: 'desktop'
25+
arch: 'gcc_64'
26+
tools: 'tools_cmake'
27+
archives: 'qttools qtsvg qtdeclarative qtbase icu'
28+
29+
- name: Build Project
30+
run: |
31+
mkdir build
32+
cd build
33+
qmake ../nepdate.pro
34+
make

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Nepdate and calendar relies on the following Qt libraries:
4040
6. The floating Nepali date widget will appear on your desktop, with automatic text color adjustment based on the background color.
4141

4242
## Screenshots
43-
nepdate in action ![nepdate](https://github.com/khumnath/nepdate/assets/50103558/8f17f73b-3dfd-4679-a2f9-2461d9b34cf9)
43+
nepdate (v2.0.0) in action ![Screenshot_select-area_20240930185731](https://github.com/user-attachments/assets/93a88b55-4a24-47ce-beee-1c8334ccba3c)
4444

4545

4646
## License

calendarwindow.cpp

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
123159
void 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

160222
void 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+
330394
void 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+
347410
void 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+
412482
void 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+

calendarwindow.h

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef CALENDARWINDOW_H
22
#define CALENDARWINDOW_H
3-
#include <QMainWindow>
43

4+
#include <QMainWindow>
55
#include "bikram.h"
6+
#include "qdatetime.h"
67
#include <QMessageBox>
78
#include <QMenu>
89
#include <QDesktopServices>
910
#include <QUrl>
1011

11-
1212
namespace Ui {
1313
class CalendarWindow;
1414
}
@@ -18,54 +18,19 @@ class CalendarWindow : public QMainWindow
1818
Q_OBJECT
1919

2020
public:
21-
22-
int gYear, gMonth, gDay;
2321
explicit CalendarWindow(QWidget *parent = nullptr);
24-
~CalendarWindow();
25-
QString getBikramMonthName(int month) {
26-
QStringList bikramMonths = {"बैशाख", "जेठ", "असार", "श्रावण", "भाद्र",
27-
"अश्विन", "कार्तिक", "मंसिर", "पौष", "माघ",
28-
"फाल्गुन", "चैत"};
29-
if (month >= 1 && month <= 12) {
30-
return bikramMonths[month - 1];
31-
} else {
32-
return QString("Invalid Month");
33-
}
34-
}
35-
QString getEnglishMonthName(int month) {
36-
QStringList englishMonths = {"जनवरी", "फेब्रुअरी", "मार्च", "अप्रिल", "मे", "जुन",
37-
"जुलाई", "अगस्ट", "सेप्टेम्बर", "अक्टोबर", "नोभेम्बर", "डिसेम्बर"};
22+
~CalendarWindow();
3823

39-
// Adjust month to use as an index (0-based in QStringList)
40-
int index = month - 1;
24+
// Static constant month names for Gregorian and Bikram Sambat calendars
25+
static const QStringList gregorianMonths;
26+
static const QStringList bikramMonths;
4127

42-
if (index >= 0 && index < englishMonths.size()) {
43-
return englishMonths.at(index);
44-
}
45-
46-
return ""; // Return empty string if index is out of range
47-
}
28+
// Methods to get month names
29+
QString getBikramMonthName(int month);
30+
QString getEnglishMonthName(int month);
4831

4932
// Function to convert number to Nepali numeral string
50-
QString convertToNepaliNumerals(int number) {
51-
QString nepaliNumbers[] = {"", "", "", "", "", "", "", "", "", ""};
52-
QString result;
53-
QString numStr = QString::number(number);
54-
55-
for (QChar ch : numStr) {
56-
if (ch.isDigit()) {
57-
int digit = ch.digitValue();
58-
result += nepaliNumbers[digit];
59-
} else {
60-
result += ch;
61-
}
62-
}
63-
64-
return result;
65-
}
66-
67-
68-
33+
QString convertToNepaliNumerals(int number);
6934

7035
private slots:
7136
void onAdYearChanged(int index);
@@ -75,6 +40,8 @@ private slots:
7540
void onBsMonthChanged(int index);
7641
void onBsDayChanged(int index);
7742
void ontodayButtonclicked();
43+
void onnextMonthButtonclicked();
44+
void onpreviousMonthButtonclicked();
7845
void showMenu();
7946
void showAbout();
8047
void openSourceCode();
@@ -87,6 +54,10 @@ private slots:
8754
Ui::CalendarWindow *ui;
8855
bikram converter;
8956
bool blockSignals;
57+
int gYear, gMonth, gDay; // Moved to private section for encapsulation
58+
QDate currentBikramDate;
59+
60+
// Private helper methods
9061
void centerOnScreen();
9162
void updateBsDateFromAd(int year, int month, int day);
9263
void updateAdDateFromBs(int year, int month, int day);
@@ -97,6 +68,4 @@ private slots:
9768
void populateBsDays(int year, int month);
9869
};
9970

100-
101-
10271
#endif // CALENDARWINDOW_H

0 commit comments

Comments
 (0)