From 640cf996af60c2b3c4020ff7640a3617996dee7d Mon Sep 17 00:00:00 2001 From: khumnath Date: Mon, 30 Sep 2024 07:15:45 +0900 Subject: [PATCH] applicatoion update code refactor/ added month navigation button/ bumped app version to 2.0.0/ --- CMakeLists.txt | 2 +- calendarwindow.cpp | 116 ++++++++++++++++++++++++------- calendarwindow.h | 63 +++++------------ calendarwindow.ui | 168 +++++++++++++++++++++++++++++++-------------- 4 files changed, 226 insertions(+), 123 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eae479..6dfd0a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(nepdate VERSION 1.0.0 LANGUAGES CXX) +project(nepdate VERSION 2.0.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/calendarwindow.cpp b/calendarwindow.cpp index ffbd885..99d733b 100755 --- a/calendarwindow.cpp +++ b/calendarwindow.cpp @@ -102,23 +102,13 @@ CalendarWindow::CalendarWindow(QWidget *parent) : // Initialize current date to today's date QDate currentDate = QDate::currentDate(); - - // Month names for Gregorian and Bikram Sambat calendars - QStringList gregorianMonths = {"जनवरी", "फेब्रुअरी", "मार्च", "अप्रिल", "मे", "जुन", - "जुलाई", "अगस्ट", "सेप्टेम्बर", "अक्टोबर", "नोभेम्बर", "डिसेम्बर"}; - - QStringList bikramMonths = {"बैशाख", "जेठ", "असार", "श्रावण", "भाद्र", - "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", - "फाल्गुन", "चैत"}; - - // Populate AD combo boxes for (int year = 1900; year <= 2100; ++year) { ui->yearselectAD->addItem(QString::number(year)); ui->yearselectAD->setEditable(true); } - for (const QString &month : gregorianMonths) { - ui->monthselectAD->addItem(month); + for (int month = 1; month <= 12; ++month) { + ui->monthselectAD->addItem(getEnglishMonthName(month)); } for (int day = 1; day <= 31; ++day) { ui->dayselectAD->addItem(QString::number(day)); @@ -129,9 +119,13 @@ CalendarWindow::CalendarWindow(QWidget *parent) : ui->yearselectBS->addItem(QString::number(year)); ui->yearselectBS->setEditable(true); } - for (const QString &month : bikramMonths) { - ui->monthselectBS->addItem(month); + for (int month = 1; month <= 12; ++month) { + ui->monthselectBS->addItem(getBikramMonthName(month)); } + int year = ui->yearselectBS->currentText().toInt(); + int month = ui->monthselectBS->currentIndex() + 1; + populateBsDays(year, month); + // Set current date in AD combo boxes ui->yearselectAD->setCurrentText(QString::number(currentDate.year())); @@ -171,6 +165,11 @@ CalendarWindow::CalendarWindow(QWidget *parent) : connect(ui->yearselectBS, QOverload::of(&QComboBox::currentIndexChanged), this, &CalendarWindow::onBsYearChanged); connect(ui->monthselectBS, QOverload::of(&QComboBox::currentIndexChanged), this, &CalendarWindow::onBsMonthChanged); connect(ui->dayselectBS, QOverload::of(&QComboBox::currentIndexChanged), this, &CalendarWindow::onBsDayChanged); + connect(ui->previousMonthButton_2, &QPushButton::clicked, this, &CalendarWindow::onpreviousMonthButtonclicked); + connect(ui->nextMonthButton, &QPushButton::clicked, this, &CalendarWindow::onnextMonthButtonclicked); + + + connect(ui->todayButton, &QPushButton::clicked, this, &CalendarWindow::ontodayButtonclicked); @@ -189,6 +188,42 @@ bool CalendarWindow::eventFilter(QObject *object, QEvent *event) { return QMainWindow::eventFilter(object, event); } +const QStringList CalendarWindow::bikramMonths = { + "वैशाख", "जेठ", "असार", "श्रावण", "भाद्र", + "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", + "फाल्गुन", "चैत्र" +}; +const QStringList CalendarWindow::gregorianMonths = {"जनवरी", "फेब्रुअरी", "मार्च", "अप्रिल", "मे", "जुन", + "जुलाई", "अगस्ट", "सेप्टेम्बर", "अक्टोबर", "नोभेम्बर", "डिसेम्बर"}; + +QString CalendarWindow::getBikramMonthName(int month) { + if (month < 1 || month > 12) { + return ""; // Return an empty string for invalid month + } + return bikramMonths.at(month - 1); // Assuming 1-based month input +} +QString CalendarWindow::getEnglishMonthName(int month) { + if (month < 1 || month > 12) { + return ""; // Return an empty string for invalid month + } + return gregorianMonths.at(month - 1); // Assuming 1-based month input +} + +QString CalendarWindow::convertToNepaliNumerals(int number) { + QString nepaliNumerals = QString::number(number); + nepaliNumerals.replace("0", "०"); + nepaliNumerals.replace("1", "१"); + nepaliNumerals.replace("2", "२"); + nepaliNumerals.replace("3", "३"); + nepaliNumerals.replace("4", "४"); + nepaliNumerals.replace("5", "५"); + nepaliNumerals.replace("6", "६"); + nepaliNumerals.replace("7", "७"); + nepaliNumerals.replace("8", "८"); + nepaliNumerals.replace("9", "९"); + return nepaliNumerals; +} + void CalendarWindow::ontodayButtonclicked() { // Get today's date QDate today = QDate::currentDate(); @@ -224,7 +259,33 @@ void CalendarWindow::ontodayButtonclicked() { // Update the calendar updateCalendar(bsYear, bsMonth); } +// Slot for Previous Month button +void CalendarWindow::onpreviousMonthButtonclicked() { + int currentIndex = ui->monthselectBS->currentIndex(); + + if (currentIndex > 0) { + ui->monthselectBS->setCurrentIndex(currentIndex - 1); + } else { + // Wrap around to December + ui->monthselectBS->setCurrentIndex(11); // December (0-based index) + } + + // The change will automatically trigger the connected slot for month selection +} + +// Slot for Next Month button +void CalendarWindow::onnextMonthButtonclicked() { + int currentIndex = ui->monthselectBS->currentIndex(); + if (currentIndex < 11) { // 11 is December + ui->monthselectBS->setCurrentIndex(currentIndex + 1); + } else { + // Wrap around to January + ui->monthselectBS->setCurrentIndex(0); // January (0-based index) + } + + // The change will automatically trigger the connected slot for month selection +} void CalendarWindow::resizeEvent(QResizeEvent* event) { QMainWindow::resizeEvent(event); @@ -293,7 +354,7 @@ void CalendarWindow::showAbout() {

About

nepali calendar

Author: khumnath

-

Version: 1.0.0

+

Version: 2.0.0

This application is written in C++ and Qt framework. For more information, visit my GitHub page.

)"; @@ -375,11 +436,12 @@ void CalendarWindow::onBsYearChanged(int /*index*/) { int year = ui->yearselectBS->currentText().toInt(); int month = ui->monthselectBS->currentIndex() + 1; - int day = ui->dayselectBS->currentText().toInt(); // Update BS day combo box based on current month and year populateBsDays(year, month); + // Now, use the current day selection to update AD date + int day = ui->dayselectBS->currentText().toInt(); updateAdDateFromBs(year, month, day); // Update the calendar @@ -388,6 +450,7 @@ void CalendarWindow::onBsYearChanged(int /*index*/) { blockSignals = false; } + void CalendarWindow::onBsMonthChanged(int /*index*/) { if (blockSignals) return; blockSignals = true; @@ -395,8 +458,6 @@ void CalendarWindow::onBsMonthChanged(int /*index*/) { int year = ui->yearselectBS->currentText().toInt(); int month = ui->monthselectBS->currentIndex() + 1; int day = ui->dayselectBS->currentText().toInt(); - populateBsDays(year, month); - // Update BS day combo box based on current month and year updateAdDateFromBs(year, month, day); // Update the calendar @@ -405,6 +466,7 @@ void CalendarWindow::onBsMonthChanged(int /*index*/) { blockSignals = false; } + void CalendarWindow::onBsDayChanged(int /*index*/) { if (blockSignals) return; blockSignals = true; @@ -414,8 +476,6 @@ void CalendarWindow::onBsDayChanged(int /*index*/) { int day = ui->dayselectBS->currentText().toInt(); updateAdDateFromBs(year, month, day); - populateBsDays(year, month); - blockSignals = false; } @@ -461,15 +521,24 @@ void CalendarWindow::updateAdDateFromBs(int year, int month, int day) { ui->monthselectAD->setCurrentIndex(gMonth - 1); ui->dayselectAD->setCurrentText(QString::number(gDay)); + int bsDaysInMonth = converter.daysInMonth(year, month); QString bsMonthName = getBikramMonthName(month); - QString adMonthName = getEnglishMonthName(gMonth); - ui->output->setText(QString("अङ्ग्रेजी मिति मा परिवर्तन गरियो: %1 %2 %3 \n %4 %5 मा जम्मा दिन सङ्ख्या: %6") - .arg(convertToNepaliNumerals(gYear)).arg(adMonthName).arg(convertToNepaliNumerals(gDay)).arg(bsMonthName).arg(convertToNepaliNumerals(year)).arg(convertToNepaliNumerals(bsDaysInMonth))); + double julianDate = gregorianToJulian(gYear, gMonth, gDay); + Panchang panchang(julianDate); + QString tithiName = QString::fromStdString(tithi[(int)panchang.tithi_index]); + QString paksha = QString::fromStdString(panchang.paksha); + QString tithipaksha = QString("%1 %2").arg(paksha).arg(tithiName); + ui->output->setText(QString("ईसवी सन मा परिवर्तन गरियो: %1 %2 %3 गते %5 \n%2 %1 मा जम्मा दिन सङ्ख्या: %4") + .arg(convertToNepaliNumerals(gYear)).arg(bsMonthName).arg(convertToNepaliNumerals(gDay)).arg(convertToNepaliNumerals(bsDaysInMonth)).arg(tithipaksha)); + // Update the calendar + updateCalendar(year, month); + // Populate BS day combo box based on current month and year populateBsDays(year, month); } + void CalendarWindow::updateCalendar(int year, int month) { int daysInMonth = converter.daysInMonth(year, month); @@ -632,3 +701,4 @@ void CalendarWindow::populateBsDays(int year, int month) { // Set the current day ui->dayselectBS->setCurrentText(QString::number(currentDay)); } + diff --git a/calendarwindow.h b/calendarwindow.h index 55407db..2ca5648 100644 --- a/calendarwindow.h +++ b/calendarwindow.h @@ -1,14 +1,14 @@ #ifndef CALENDARWINDOW_H #define CALENDARWINDOW_H -#include +#include #include "bikram.h" +#include "qdatetime.h" #include #include #include #include - namespace Ui { class CalendarWindow; } @@ -18,54 +18,19 @@ class CalendarWindow : public QMainWindow Q_OBJECT public: - - int gYear, gMonth, gDay; explicit CalendarWindow(QWidget *parent = nullptr); - ~CalendarWindow(); - QString getBikramMonthName(int month) { - QStringList bikramMonths = {"बैशाख", "जेठ", "असार", "श्रावण", "भाद्र", - "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", - "फाल्गुन", "चैत"}; - if (month >= 1 && month <= 12) { - return bikramMonths[month - 1]; - } else { - return QString("Invalid Month"); - } - } - QString getEnglishMonthName(int month) { - QStringList englishMonths = {"जनवरी", "फेब्रुअरी", "मार्च", "अप्रिल", "मे", "जुन", - "जुलाई", "अगस्ट", "सेप्टेम्बर", "अक्टोबर", "नोभेम्बर", "डिसेम्बर"}; + ~CalendarWindow(); - // Adjust month to use as an index (0-based in QStringList) - int index = month - 1; + // Static constant month names for Gregorian and Bikram Sambat calendars + static const QStringList gregorianMonths; + static const QStringList bikramMonths; - if (index >= 0 && index < englishMonths.size()) { - return englishMonths.at(index); - } - - return ""; // Return empty string if index is out of range - } + // Methods to get month names + QString getBikramMonthName(int month); + QString getEnglishMonthName(int month); // Function to convert number to Nepali numeral string - QString convertToNepaliNumerals(int number) { - QString nepaliNumbers[] = {"०", "१", "२", "३", "४", "५", "६", "७", "८", "९"}; - QString result; - QString numStr = QString::number(number); - - for (QChar ch : numStr) { - if (ch.isDigit()) { - int digit = ch.digitValue(); - result += nepaliNumbers[digit]; - } else { - result += ch; - } - } - - return result; - } - - - + QString convertToNepaliNumerals(int number); private slots: void onAdYearChanged(int index); @@ -75,6 +40,8 @@ private slots: void onBsMonthChanged(int index); void onBsDayChanged(int index); void ontodayButtonclicked(); + void onnextMonthButtonclicked(); + void onpreviousMonthButtonclicked(); void showMenu(); void showAbout(); void openSourceCode(); @@ -87,6 +54,10 @@ private slots: Ui::CalendarWindow *ui; bikram converter; bool blockSignals; + int gYear, gMonth, gDay; // Moved to private section for encapsulation + QDate currentBikramDate; + + // Private helper methods void centerOnScreen(); void updateBsDateFromAd(int year, int month, int day); void updateAdDateFromBs(int year, int month, int day); @@ -97,6 +68,4 @@ private slots: void populateBsDays(int year, int month); }; - - #endif // CALENDARWINDOW_H diff --git a/calendarwindow.ui b/calendarwindow.ui index 3bff540..3f85a63 100644 --- a/calendarwindow.ui +++ b/calendarwindow.ui @@ -47,6 +47,16 @@ + + + + color: #00ac98; + + + अङ्ग्रेजी मिति + + + @@ -75,14 +85,17 @@ - - - - 12 + + + + color: #00ac98; + + + बिक्रम संवत् मिति - + Qt::ClickFocus @@ -95,7 +108,7 @@ - + Qt::WheelFocus @@ -114,13 +127,31 @@ - - - - color: #00ac98; + + + + 12 - - अङ्ग्रेजी मिति + + + + + + 31 + + + + + + + 32 + + + + + + + 12 @@ -166,13 +197,6 @@ - - - - 31 - - - @@ -371,20 +395,42 @@ - - - - color: #00ac98; - - - बिक्रम संवत् मिति - - - - - - - QPushButton#todayButton { + + + + + + QPushButton#previousMonthButton_2 { + color: white; + background: #3EACBA; /* Light blue background */ + border: 1px solid #379AA4; /* Blue border */ + background-image: linear-gradient(to top, #48C6D4, #3EACBA); /* Blue gradient */ + + border-radius: 5px; /* Rounded corners */ +} + +QPushButton#previousMonthButton_2:hover { + background: #48C6D4; + background-image: linear-gradient(to top, #3EACBA, #48C6D4); +} + +QPushButton#previousMonthButton_2:pressed { + background: qradialgradient(cx: 0.4, cy: -0.1, + fx: 0.4, fy: -0.1, + radius: 1.35, stop: 0 #fff, stop: 1 #ddd); + /* Background color on press */ +} + + + + अघिल्लो महिना + + + + + + + QPushButton#todayButton { color: white; background: #3EACBA; /* Light blue background */ border: 1px solid #379AA4; /* Blue border */ @@ -405,25 +451,43 @@ QPushButton#todayButton:pressed { /* Background color on press */ } - - - आज - - - - - - - 31 - - - - - - - 12 - - + + + आज + + + + + + + QPushButton#nextMonthButton { + color: white; + background: #3EACBA; /* Light blue background */ + border: 1px solid #379AA4; /* Blue border */ + background-image: linear-gradient(to top, #48C6D4, #3EACBA); /* Blue gradient */ + + border-radius: 5px; /* Rounded corners */ +} + +QPushButton#nextMonthButton:hover { + background: #48C6D4; + background-image: linear-gradient(to top, #3EACBA, #48C6D4); +} + +QPushButton#nextMonthButton:pressed { + background: qradialgradient(cx: 0.4, cy: -0.1, + fx: 0.4, fy: -0.1, + radius: 1.35, stop: 0 #fff, stop: 1 #ddd); + /* Background color on press */ +} + + + + अर्को महिना + + + +