diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml new file mode 100644 index 0000000..396bdc0 --- /dev/null +++ b/.github/workflows/c-cpp.yml @@ -0,0 +1,34 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Install Qt + uses: jurplel/install-qt-action@v3 + with: + aqtversion: '==3.1.*' + version: '6.2.0' + host: 'linux' + target: 'desktop' + arch: 'gcc_64' + tools: 'tools_cmake' + archives: 'qttools qtsvg qtdeclarative qtbase icu' + + - name: Build Project + run: | + mkdir build + cd build + qmake ../nepdate.pro + make diff --git a/README.md b/README.md index 43f24a1..c74b593 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Nepdate and calendar relies on the following Qt libraries: 6. The floating Nepali date widget will appear on your desktop, with automatic text color adjustment based on the background color. ## Screenshots -nepdate in action ![nepdate](https://github.com/khumnath/nepdate/assets/50103558/8f17f73b-3dfd-4679-a2f9-2461d9b34cf9) +nepdate (v2.0.0) in action ![Screenshot_select-area_20240930185731](https://github.com/user-attachments/assets/93a88b55-4a24-47ce-beee-1c8334ccba3c) ## License diff --git a/calendarwindow.cpp b/calendarwindow.cpp index 2719e09..0b43d44 100755 --- a/calendarwindow.cpp +++ b/calendarwindow.cpp @@ -34,23 +34,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)); @@ -61,9 +51,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())); @@ -103,6 +97,12 @@ 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); // Initialize the calendar @@ -120,6 +120,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(); @@ -155,7 +191,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); @@ -314,11 +376,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 @@ -327,6 +390,7 @@ void CalendarWindow::onBsYearChanged(int /*index*/) { blockSignals = false; } + void CalendarWindow::onBsMonthChanged(int /*index*/) { if (blockSignals) return; blockSignals = true; @@ -334,8 +398,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 @@ -344,6 +406,7 @@ void CalendarWindow::onBsMonthChanged(int /*index*/) { blockSignals = false; } + void CalendarWindow::onBsDayChanged(int /*index*/) { if (blockSignals) return; blockSignals = true; @@ -353,8 +416,6 @@ void CalendarWindow::onBsDayChanged(int /*index*/) { int day = ui->dayselectBS->currentText().toInt(); updateAdDateFromBs(year, month, day); - populateBsDays(year, month); - blockSignals = false; } @@ -400,15 +461,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); @@ -568,3 +638,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 41dc272..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 */ +} + + + + अर्को महिना + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 61e4b27..28d63c9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -169,7 +169,7 @@ int MainWindow::cnvToNepali(int mm, int dd, int yy) { ui->dateButton->setToolTipDuration(3000); QFont tooltipFont("Noto Sans Devanagari", 12); // Replace "Noto Sans Devnagari" with the name of your desired font QToolTip::setFont(tooltipFont); - ui->dateButton->setToolTip(nepalitooltip); + ui->dateButton->setToolTip(nepalitooltip); adjustTextColorBasedOnBackground(); @@ -227,12 +227,20 @@ double contrastRatio(double lum1, double lum2) { // Main function to adjust the text color based on the background color void MainWindow::adjustTextColorBasedOnBackground() { // Capture the screen behind the window. + QPoint globalPos = ui->dateButton->mapToGlobal(QPoint(0, 0)); + + // Capture the screen behind the button. QScreen *screen = QGuiApplication::primaryScreen(); - QPixmap pixmap = screen->grabWindow(0, x(), y(), width(), height()); + + // Grab only area behind the button with button's dimensions + QPixmap pixmap = screen->grabWindow(0, globalPos.x(), globalPos.y(), ui->dateButton->width(), ui->dateButton->height()); QImage image = pixmap.toImage(); - // Calculate the average color of the background image. - QColor averageColor = getAverageColor(image); + // Scale down the image to reduce processing time.(this is optional). + QImage scaledImage = image.scaled(10, 10, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + + // Calculate the average color of the background behind the date button. + QColor averageColor = getAverageColor(scaledImage); // Calculate the luminance of the background color. double bgLuminance = luminance(averageColor);