diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/DayTithiWidget.h b/DayTithiWidget.h index c5cb24d..c829b05 100644 --- a/DayTithiWidget.h +++ b/DayTithiWidget.h @@ -17,11 +17,11 @@ class DayTithiWidget : public QWidget { dayLabel = new QLabel(day, this); dayLabel->setObjectName("dayLabel"); // Set object name for styling - dayLabel->setStyleSheet("font-size: 19px; color: black; font-family: 'laila';"); + dayLabel->setStyleSheet("font-size: 19px; color: black; background-color: transparent; font-family: 'laila';"); tithiLabel = new QLabel(tithi, this); tithiLabel->setObjectName("tithiLabel"); // Set object name for styling - tithiLabel->setStyleSheet("font-size: 10px; color: blue; font-family: 'laila';"); + tithiLabel->setStyleSheet("font-size: 10px; color: blue; background-color: transparent; font-family: 'laila';"); layout->addWidget(dayLabel); layout->addWidget(tithiLabel); @@ -32,6 +32,7 @@ class DayTithiWidget : public QWidget { } void setSaturdayStyle() { + setStyleSheet("background-color: transparent;"); dayLabel->setStyleSheet("font-size: 19px; color: red; font-family: 'laila';"); } diff --git a/bikram.h b/bikram.h old mode 100755 new mode 100644 index c0d2d39..bcf539e --- a/bikram.h +++ b/bikram.h @@ -179,7 +179,7 @@ inline int bikram::getDay() { inline std::string bikram::getWeekdayName(int year, int month, int day) { - std::tm timeinfo = { 0, 0, 0, 0, day, month - 1, year - 1900, 0, 0, 0, 0 }; + std::tm timeinfo = { 0, 0, 0, day, month - 1, year - 1900, 0, 0, 0 }; std::mktime(&timeinfo); const char* weekday[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; return weekday[timeinfo.tm_wday]; diff --git a/calendarwindow.cpp b/calendarwindow.cpp index 162db50..ae7f0fc 100644 --- a/calendarwindow.cpp +++ b/calendarwindow.cpp @@ -20,6 +20,7 @@ CalendarWindow::CalendarWindow(QWidget *parent) : connect(ui->aboutbutton, &QPushButton::clicked, this, &CalendarWindow::showMenu); // Center the window on the screen centerOnScreen(); + installEventFilter(this); // Set the global stylesheet for all QComboBox widgets QString globalStyleSheet = R"( QComboBox { @@ -138,7 +139,7 @@ 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); // Add this line - connect(ui->todayButton, &QPushButton::clicked, this, &CalendarWindow::on_todayButton_clicked); + connect(ui->todayButton, &QPushButton::clicked, this, &CalendarWindow::ontodayButtonclicked); // Initialize the calendar updateCalendar(bsYear, bsMonth); @@ -146,9 +147,16 @@ CalendarWindow::CalendarWindow(QWidget *parent) : adjustCellSizes(); adjustCalendarTableSize(); } +bool CalendarWindow::eventFilter(QObject *object, QEvent *event) { + if (object == this && event->type() == QEvent::Show) { + // Perform action when the window is shown + ui->todayButton->click(); // or any other action + } + return QMainWindow::eventFilter(object, event); +} -void CalendarWindow::on_todayButton_clicked() { +void CalendarWindow::ontodayButtonclicked() { // Get today's date QDate today = QDate::currentDate(); @@ -257,25 +265,23 @@ void CalendarWindow::showAbout() {

nepali calendar

Author: khumnath

Version: 1.0.0

-

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

+

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

)"; - QMessageBox *msgBox = new QMessageBox(QMessageBox::Information, "About", aboutText, QMessageBox::Ok, this); - msgBox->setStyleSheet("QDialog { background-color: white; color: black; }" - "QLabel { color: black; }" - "QPushButton { background-color: white; color: black; }"); - - msgBox->setWindowModality(Qt::WindowModal); - QAbstractButton *okButton = msgBox->button(QMessageBox::Ok); - connect(okButton, &QAbstractButton::clicked, msgBox, &QMessageBox::close); - msgBox->exec(); - delete msgBox; + QMessageBox msgBox(QMessageBox::Information, "About", aboutText, QMessageBox::Ok, this); // Set parent as this (MainWindow) + msgBox.setStyleSheet("QDialog { background-color: white; color: black; }" + "QLabel { color: black; }" + "QPushButton { background-color: white; color: black; }"); + msgBox.exec(); } void CalendarWindow::openSourceCode() { + // Open the URL using QDesktopServices QDesktopServices::openUrl(QUrl("https://github.com/khumnath/nepdate")); -} + // Ensure MainWindow is active if needed + activateWindow(); +} void CalendarWindow::centerOnScreen() { // Get the screen geometry @@ -362,8 +368,8 @@ 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 + populateBsDays(year, month); + // Update BS day combo box based on current month and year updateAdDateFromBs(year, month, day); // Update the calendar @@ -522,16 +528,23 @@ void CalendarWindow::updateCalendar(int year, int month) { ui->calendarTable->setItem(row, col, item); // Check if the current cell represents today's Bikram Sambat date - if (year == todayBsYear && month == todayBsMonth && day == todayBsDay) { - item->setBackground(QColor(230, 255, 230)); // light green - customWidget->setTodayStyle(); // defined in DayTithiWidget.h - } + bool isToday = (year == todayBsYear && month == todayBsMonth && day == todayBsDay); + bool isSaturday = (col == saturdayIndex); - // Check if Saturday and apply color/CSS class (optional) - if (col == saturdayIndex) { + if (isToday && isSaturday) { + // If today is both Saturday and the current date, apply the "today" style + item->setBackground(QColor(153,255,204)); // light green + customWidget->setTodayStyle(); // defined in DayTithiWidget.h + } else if (isToday) { + // If it's just today, apply the "today" style + item->setBackground(QColor(153,255,204)); // light green + customWidget->setTodayStyle(); // defined in DayTithiWidget.h + } else if (isSaturday) { + // If it's just Saturday, apply the "Saturday" style customWidget->setSaturdayStyle(); } + ui->calendarTable->setCellWidget(row, col, customWidget); col++; if (col > 6) { @@ -593,4 +606,3 @@ 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 2ac4bb3..039831d 100644 --- a/calendarwindow.h +++ b/calendarwindow.h @@ -74,13 +74,14 @@ private slots: void onBsYearChanged(int index); void onBsMonthChanged(int index); void onBsDayChanged(int index); - void on_todayButton_clicked(); + void ontodayButtonclicked(); void showMenu(); void showAbout(); void openSourceCode(); protected: void resizeEvent(QResizeEvent* event) override; + bool eventFilter(QObject *object, QEvent *event) override; private: Ui::CalendarWindow *ui; diff --git a/calendarwindow.ui b/calendarwindow.ui old mode 100755 new mode 100644 index 5688885..37d087c --- a/calendarwindow.ui +++ b/calendarwindow.ui @@ -53,8 +53,8 @@ - - + + Noto Sans Devanagari @@ -63,52 +63,87 @@ Qt::ClickFocus + + true + false - - + + - Laila + Noto Sans Devanagari - 12 + 31 - - + + - Noto Sans Devanagari + Laila SemiBold + 12 + true - - 31 + + color: black; + + + QFrame::NoFrame + + + 2 + + + TextLabel + + + true + + + Qt::AlignCenter + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - + + Noto Sans Devanagari - Qt::ClickFocus + Qt::WheelFocus + + + true + + + true + + + QComboBox::AdjustToContentsOnFirstShow false - - + + Laila @@ -119,20 +154,8 @@ - - - - - Noto Sans Devanagari - - - - 31 - - - - - + + Laila SemiBold @@ -144,12 +167,12 @@ color: #00ac98; - अङ्ग्रेजी मिति + बिक्रम संवत् मिति - - + + Laila SemiBold @@ -161,7 +184,7 @@ color: #00ac98; - बिक्रम संवत् मिति + अङ्ग्रेजी मिति @@ -175,6 +198,7 @@ QPushButton#todayButton { + color: white; background: #3EACBA; /* Light blue background */ border: 1px solid #379AA4; /* Blue border */ background-image: linear-gradient(to top, #48C6D4, #3EACBA); /* Blue gradient */ @@ -200,78 +224,153 @@ QPushButton#todayButton:pressed { - - - - true - + + - Laila + Noto Sans Devanagari - - Qt::StrongFocus - - - Qt::NoContextMenu - - - true - - - true - - - QFrame::Box - - - QFrame::Raised - - - 1 - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - QAbstractItemView::NoEditTriggers - - - false - - - false + + 31 - - false + + + + + + + + + + + + + 0 + 229 + 255 + + + + + + + 255 + 0 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + + + 0 + 229 + 255 + + + + + + + 255 + 0 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 0 + 127 + + + + + + + 255 + 255 + 255 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Plain + + + 1 + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::CurrentChanged|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::ScrollPerItem + + + true + + + false + + + + + + + + + + Laila + - - false + + 12 - - true - - - true - - - true - - - true - - + + 0 + + @@ -279,16 +378,20 @@ QPushButton#todayButton:pressed { - <html><head/><body><p>about application</p></body></html> + <p>About the application</p> Qt::RightToLeft + + + - + - + + :/resources/info.png:/resources/info.png @@ -297,44 +400,12 @@ QPushButton#todayButton:pressed { - false + true - - - - - Laila SemiBold - 12 - true - - - - QFrame::NoFrame - - - 2 - - - TextLabel - - - true - - - Qt::AlignCenter - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - diff --git a/mainwindow.cpp b/mainwindow.cpp old mode 100755 new mode 100644 index 48eeb0c..c47df1d --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,22 +9,21 @@ #include "calendarwindow.h" #include #include - - #include +#include +#include +#include +#include +#include + std::string MainWindow::getWeekdayName(int year, int month, int day) { - std::tm timeinfo; - std::memset(&timeinfo, 0, sizeof(timeinfo)); - timeinfo.tm_year = year - 1900; // Year since 1900 - timeinfo.tm_mon = month - 1; // Month, 0 - jan - timeinfo.tm_mday = day; - std::mktime(&timeinfo); + std::tm timeinfo = { 0, 0, 0, day, month - 1, year - 1900, 0, 0, 0}; + std::mktime(&timeinfo); // Update timeinfo to fill in the week day field const std::string nepaliWeekdays[] = { "आइतबार", "सोमबार", "मंगलबार", "बुधबार", "बिहिबार", "शुक्रबार", "शनिबार" }; return nepaliWeekdays[timeinfo.tm_wday]; } - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), isDragging(false), calendarWindow(nullptr) { @@ -32,7 +31,6 @@ MainWindow::MainWindow(QWidget *parent) : // Initialize the timer updateTimer = new QTimer(this); - // Connect the timer's timeout signal to a slot connect(updateTimer, &QTimer::timeout, this, &MainWindow::updateDateButton); @@ -40,53 +38,55 @@ MainWindow::MainWindow(QWidget *parent) : updateTimer->start(1000); // Update every second // Set the window flags to make it borderless - setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool); + setWindowFlags(Qt::Tool | Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + + // Set the window attributes to make it transparent + setAttribute(Qt::WA_TranslucentBackground); + + // Set the window position + setWindowPosition(); + + // Set today's date as default when setting up the UI + setupDefaultDate(); +} +void MainWindow::setWindowPosition() { // Get the geometry of the primary screen QScreen *primaryScreen = QGuiApplication::primaryScreen(); QRect screenGeometry = primaryScreen->availableGeometry(); // Calculate the position of the bottom-right corner - int x = screenGeometry.right(); - int y = screenGeometry.bottom() + height(); // Adjusted to place the window at the bottom + int x = screenGeometry.right() - width(); + int y = screenGeometry.bottom() - height(); // Adjusting the position to avoid the dock panel (you need to determine the dock height) int dockHeight = 40; // Example height of the dock panel if (screenGeometry.bottom() - dockHeight < y) { - y = screenGeometry.bottom() - dockHeight; + y = screenGeometry.bottom() - dockHeight - height(); } // Set the position of the window move(x, y); - ; - setAttribute(Qt::WA_TranslucentBackground); - - // Set today's date as default when setting up the UI - setupDefaultDate(); - - } - - MainWindow::~MainWindow() { delete ui; } -int MainWindow::is_leap_year(int year) + +int MainWindow::isleapyear(int year) { int a = year; - if (a%100==0) + if (a % 100 == 0) { - if(a%400==0) + if(a % 400 == 0) { return true; } else { return false; } - } else { - if (a%4==0) + if (a % 4 == 0) { return true; } else { @@ -95,7 +95,6 @@ int MainWindow::is_leap_year(int year) } } - int MainWindow::cnvToNepali(int mm, int dd, int yy) { // Perform the conversion using the bikram class bikram bsdate; @@ -110,7 +109,7 @@ int MainWindow::cnvToNepali(int mm, int dd, int yy) { std::string weekdayName = getWeekdayName(yy, mm, dd); // Adjust the day of the week - QString nepaliMonthName = get_nepali_month(nepaliMonth); + QString nepaliMonthName = getnepalimonth(nepaliMonth); QString nepaliDayOfWeekName = QString::fromStdString(weekdayName); // Construct the Nepali date format string @@ -143,12 +142,12 @@ int MainWindow::cnvToNepali(int mm, int dd, int yy) { } QColor MainWindow::getAverageColor(const QImage &image) { - int red = 0, green = 0, blue = 0; + qint64 red = 0, green = 0, blue = 0; int pixelCount = image.width() * image.height(); for (int y = 0; y < image.height(); ++y) { for (int x = 0; x < image.width(); ++x) { - QColor color = image.pixelColor(x, y); + QColor color(image.pixel(x, y)); red += color.red(); green += color.green(); blue += color.blue(); @@ -158,151 +157,151 @@ QColor MainWindow::getAverageColor(const QImage &image) { return QColor(red / pixelCount, green / pixelCount, blue / pixelCount); } -// Function to adjust text color based on the average color of the background void MainWindow::adjustTextColorBasedOnBackground() { - // Define threshold range - static const int lowerThreshold = 75; - static const int upperThreshold = 85; - static QColor currentTextColor = Qt::black; // Initial text color - // Get the screen behind the window QScreen *screen = QGuiApplication::primaryScreen(); - QPoint globalPos = ui->dateButton->mapToGlobal(QPoint(0, 0)); - QPixmap pixmap = screen->grabWindow(0, globalPos.x(), globalPos.y(), ui->dateButton->width(), ui->dateButton->height()); + QPixmap pixmap = screen->grabWindow(0, x(), y(), width(), height()); QImage image = pixmap.toImage(); // Calculate the average color QColor averageColor = getAverageColor(image); - // Calculate the brightness of the average color + // Determine whether to use black or white text based on the brightness of the average color int brightness = (averageColor.red() + averageColor.green() + averageColor.blue()) / 3; - - // Determine the appropriate text color using threshold range - if (brightness > upperThreshold) { - currentTextColor = Qt::black; - } else if (brightness < lowerThreshold) { - currentTextColor = Qt::white; - } + QColor textColor = (brightness > 80) ? Qt::black : Qt::white; // Set the text color of the dateButton - QString currentStyleSheet = QString("QPushButton { color: %1; }").arg(currentTextColor.name()); - if (ui->dateButton->styleSheet() != currentStyleSheet) { - ui->dateButton->setStyleSheet(currentStyleSheet); - } + QString styleSheet = QString("QPushButton { color: %1; border: none; outline: none; }").arg(textColor.name()); + ui->dateButton->setStyleSheet(styleSheet); } - - void MainWindow::setupDefaultDate() { - QDate currentDate = QDate::currentDate(); - - // Convert the current system date to Nepali and update UI - int mm = currentDate.month(); - int dd = currentDate.day(); - int yy = currentDate.year(); + // Convert the default Gregorian date to Nepali and update UI + int mm = 1; + int yy = 1; + int dd = 1; cnvToNepali(mm, dd, yy); } +void MainWindow::exitAll() +{ + QList topLevelWidgets = QApplication::topLevelWidgets(); + for (QWidget* widget : topLevelWidgets) { + MainWindow* mainWindow = qobject_cast(widget); + if (mainWindow) { + mainWindow->close(); + } + } -QString MainWindow::get_nepali_month(int m) { - QString n_month = ""; - - switch (m) { - case 1: - n_month = "वैशाख"; // Vaisakh - break; + // After closing all windows, quit the application + qApp->quit(); +} - case 2: - n_month = "जेष्ठ"; // Jestha - break; +const QString kAppName = "nepdate-widget"; +const QString kAutostartKey = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"; +const QString kAutostartDirLinux = QDir::homePath() + "/.config/autostart/"; +const QString kDesktopFileLinux = kAutostartDirLinux + "nepalicalendar.desktop"; + +bool isAutostartEnabled() { +#ifdef Q_OS_WIN + QSettings registrySettings(kAutostartKey, QSettings::NativeFormat); + return registrySettings.contains(kAppName); +#else + QFile desktopFile(kDesktopFileLinux); + return desktopFile.exists(); +#endif +} - case 3: - n_month = "असार"; // Ashad - break; +void createDesktopFile(const QString& path, const QString& execPath) { + QFile desktopFile(path); + if (!desktopFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + qDebug() << "Failed to open file for writing:" << path; + return; + } - case 4: - n_month = "श्रावण"; // Shrawn - break; + QTextStream out(&desktopFile); + out << "[Desktop Entry]\n"; + out << "Type=Application\n"; + out << "Name=Nepali Calendar widget\n"; + out << "Exec=" << execPath << "\n"; // Correctly write the application path + out << "Icon=icon-name\n"; // Replace with your icon name if needed + desktopFile.close(); +} - case 5: - n_month = "भदौ"; // Bhadra - break; +void MainWindow::setAutostart(bool enabled) { +#ifdef Q_OS_WIN + QSettings registrySettings(kAutostartKey, QSettings::NativeFormat); - case 6: - n_month = "आश्विन"; // Ashwin - break; + if (enabled) { + registrySettings.setValue(kAppName, QDir::toNativeSeparators(QCoreApplication::applicationFilePath())); + } else { + registrySettings.remove(kAppName); + } +#else // Assuming Q_OS_LINUX or any other Unix-like OS + const QString execPath = QCoreApplication::applicationFilePath(); - case 7: - n_month = "कार्तिक"; // Kartik - break; + if (enabled) { + // Ensure the desktop file exists in the application directory + if (!QFile::exists(kDesktopFileLinux)) { + createDesktopFile(kDesktopFileLinux, execPath); + } + // Copy the desktop file to the autostart directory + QFile::copy(kDesktopFileLinux, kAutostartDirLinux + "nepdate-widget.desktop"); + } else { + QFile::remove(kAutostartDirLinux + "nepdate-widget.desktop"); + } +#endif +} - case 8: - n_month = "मंसिर"; // Mangshir - break; +void MainWindow::contextMenuEvent(QContextMenuEvent *event) { + QMenu menu(tr("Context menu"), this); + QString styleSheet = "QMenu { background-color: #C9F8FA; color: black; border: 1px solid black; border-radius: 2px; }"; - case 9: - n_month = "पौष"; // Poush - break; + QAction *copyAction = new QAction(tr("Copy Nepali Date"), this); + connect(copyAction, &QAction::triggered, this, &MainWindow::copyButtonText); + menu.addAction(copyAction); - case 10: - n_month = "माघ"; // Magh - break; + menu.addSeparator(); // Add a separator before the autostart action - case 11: - n_month = "फाल्गुण"; // Falgun - break; + QAction *autostartAction = new QAction( + isAutostartEnabled() ? tr("Disable Autostart") : tr("Enable Autostart"), + this); + connect(autostartAction, &QAction::triggered, this, [this, autostartAction]() { + bool currentState = isAutostartEnabled(); + setAutostart(!currentState); + autostartAction->setText(isAutostartEnabled() ? tr("Disable Autostart") : tr("Enable Autostart")); + }); + menu.addAction(autostartAction); - case 12: - n_month = "चैत्र"; // Chaitra - break; - } - return n_month; -} + menu.addSeparator(); // Add a separator before the exit action + QAction *exitAllAction = new QAction(tr("Exit"), this); + connect(exitAllAction, &QAction::triggered, this, &MainWindow::exitAll); + menu.addAction(exitAllAction); -void MainWindow::contextMenuEvent(QContextMenuEvent *event) -{ - QMenu menu(tr("Context menu"), this); - QString styleSheet = "QMenu { background-color: #C9F8FA; color: black; border: 1px solid black; border-radius: 5px; }" - "QMenu::item { background-color: transparent; }" - "QMenu::item:selected { background-color: #1AEFF7; color: #184805;}"; menu.setStyleSheet(styleSheet); - menu.setWindowFlags(menu.windowFlags() | Qt::FramelessWindowHint); - - - QAction *copyAction = menu.addAction("Copy Date"); - connect(copyAction, &QAction::triggered, this, &MainWindow::copyButtonText); - QAction *exitAction = menu.addAction("Exit"); - connect(exitAction, &QAction::triggered, qApp, &QApplication::quit); menu.exec(event->globalPos()); } + void MainWindow::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - isDragging = true; - dragStartPosition = event->globalPosition().toPoint() - frameGeometry().topLeft(); - event->accept(); - } else { - QMainWindow::mousePressEvent(event); - } + // Update the drag start position to the current global position minus the top-left of the window frame + dragStartPosition = event->globalPosition().toPoint() - frameGeometry().topLeft(); } void MainWindow::mouseMoveEvent(QMouseEvent *event) { - if (isDragging) { - move(event->globalPosition().toPoint() - dragStartPosition); - event->accept(); - } else { - QMainWindow::mouseMoveEvent(event); - } + // Move the window based on the current global position minus the drag start position + move(event->globalPosition().toPoint() - dragStartPosition); } -void MainWindow::mouseReleaseEvent(QMouseEvent *event) { + + + +void MainWindow::mouseReleaseEvent(QMouseEvent *event) +{ if (event->button() == Qt::LeftButton) { isDragging = false; event->accept(); - } else { - QMainWindow::mouseReleaseEvent(event); } } - void MainWindow::openCalendarWindow(const QString &link) { qDebug() << "Clicked on datebutton. Link: " << link; if (link == "#") { @@ -350,19 +349,29 @@ void MainWindow::on_dateButton_clicked() calendarWindow->activateWindow(); } } -void MainWindow::copyButtonText() -{ - // Copy the text of the dateButton to the clipboard - QApplication::clipboard()->setText(ui->dateButton->text()); + +void MainWindow::copyButtonText() { + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(ui->dateButton->text()); } -void MainWindow::updateDateButton() -{ - // Get the current system date - QDate currentDate = QDate::currentDate(); - // Convert the current system date to Nepali date format - int mm = currentDate.month(); - int dd = currentDate.day(); - int yy = currentDate.year(); - cnvToNepali(mm, dd, yy); +void MainWindow::updateDateButton() { + QDate today = QDate::currentDate(); + cnvToNepali(today.month(), today.day(), today.year()); +} + +QString MainWindow::getnepalimonth(int m) { + const QString nepaliMonths[] = { + "बैशाख", "जेष्ठ", "आषाढ", "श्रावण", "भाद्र", "आश्विन", + "कार्तिक", "मंसिर", "पुष", "माघ", "फाल्गुण", "चैत्र" + }; + + if (m >= 1 && m <= 12) { + return nepaliMonths[m - 1]; + } else { + return QString(); + } } + + + diff --git a/mainwindow.h b/mainwindow.h index c5f9fb5..3bf2dff 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -10,8 +10,12 @@ #include #include #include -#include "calendarwindow.h" #include +#include +#include +#include +#include +#include "calendarwindow.h" struct NepaliDateStruct { // Renamed the structure to avoid conflict int yy; @@ -38,12 +42,7 @@ class MainWindow : public QMainWindow { public: explicit MainWindow(QWidget *parent = nullptr); - int is_leap_year(int); - int cnvToNepali(int, int, int); - NepaliDateStruct cnvToEnglish(int, int, int); // Updated to use the renamed structure - int what(); - int err(int errno, char *desc); - static int calculateDayOfWeek(int year, int month, int day); + void setAutostart(bool enabled); ~MainWindow(); protected: @@ -51,28 +50,32 @@ class MainWindow : public QMainWindow { void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void contextMenuEvent(QContextMenuEvent *event) override; + void exitAll(); public slots: void openCalendarWindow(const QString &link); private slots: - QString get_nepali_month(int); + void copyButtonText(); - void on_dateButton_clicked(); void updateDateButton(); + void on_dateButton_clicked(); private: void setupDefaultDate(); - // Declaration of getWeekdayName function + int isleapyear(int year); + int cnvToNepali(int mm, int dd, int yy); std::string getWeekdayName(int year, int month, int day); - QTimer *updateTimer; + QString getnepalimonth(int m); + void setWindowPosition(); void adjustTextColorBasedOnBackground(); QColor getAverageColor(const QImage &image); + Ui::MainWindow *ui; + QTimer *updateTimer; bool isDragging; QPoint dragStartPosition; - CalendarWindow *calendarWindow = nullptr; - QTimer *timer; + CalendarWindow *calendarWindow; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index da2fe98..65cfeb7 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -16,6 +16,7 @@ Noto Sans Devanagari + 11 @@ -31,10 +32,13 @@ Qt::StrongFocus - false + true - MainWindow + calendar + + + false @@ -73,6 +77,160 @@ border-radius: 10px; 31 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + Noto Sans Devanagari @@ -86,15 +244,23 @@ border-radius: 10px; true - Qt::NoFocus + Qt::StrongFocus + + + true - border: none; -border-radius: 5px, + PushButton + + false + + + false + diff --git a/nepdate-widget.pro b/nepdate-widget.pro index 8e8b392..00247ef 100644 --- a/nepdate-widget.pro +++ b/nepdate-widget.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui widgets -TARGET = nepdate +TARGET = nepdate-widget TEMPLATE = app SOURCES += main.cpp \ diff --git a/resources.qrc b/resources.qrc index 7a013af..cb63b6d 100644 --- a/resources.qrc +++ b/resources.qrc @@ -3,5 +3,6 @@ resources/dropdown.png resources/logo.png resources/logo.svg + resources/info.png diff --git a/resources/info.png b/resources/info.png new file mode 100755 index 0000000..a74c1f2 Binary files /dev/null and b/resources/info.png differ