From ffd42b072840d5b271ef4d198f36ef948b436e12 Mon Sep 17 00:00:00 2001 From: khumnath Date: Fri, 21 Jun 2024 08:08:11 +0900 Subject: [PATCH 1/3] corrected widget day name for today --- mainwindow.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e8aca32..30b5042 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,13 +13,18 @@ #include std::string MainWindow::getWeekdayName(int year, int month, int day) { - std::tm timeinfo = { 0, 0, 0, 0, day, month - 1, year - 1900, 0, 0, 0, 0}; - std::mktime(&timeinfo); // Update timeinfo to fill in the week day field + 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); const std::string nepaliWeekdays[] = { "आइतबार", "सोमबार", "मंगलबार", "बुधबार", "बिहिबार", "शुक्रबार", "शनिबार" }; return nepaliWeekdays[timeinfo.tm_wday]; } + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), isDragging(false), calendarWindow(nullptr) { @@ -174,13 +179,15 @@ void MainWindow::adjustTextColorBasedOnBackground() { void MainWindow::setupDefaultDate() { + QDate currentDate = QDate::currentDate(); - // Convert the default Gregorian date to Nepali and update UI - int mm = 10; - int yy = 1984; - int dd = 4; + // Convert the current system date to Nepali and update UI + int mm = currentDate.month(); + int dd = currentDate.day(); + int yy = currentDate.year(); cnvToNepali(mm, dd, yy); } + QString MainWindow::get_nepali_month(int m) { QString n_month = ""; From e62ae6de97dc853d6f5a2fe5f9194042fe443e85 Mon Sep 17 00:00:00 2001 From: khumnath Date: Fri, 21 Jun 2024 08:25:38 +0900 Subject: [PATCH 2/3] color of date display correction --- mainwindow.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 30b5042..48eeb0c 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -141,13 +141,14 @@ int MainWindow::cnvToNepali(int mm, int dd, int yy) { return 0; } + QColor MainWindow::getAverageColor(const QImage &image) { - qint64 red = 0, green = 0, blue = 0; + int 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.pixel(x, y)); + QColor color = image.pixelColor(x, y); red += color.red(); green += color.green(); blue += color.blue(); @@ -157,22 +158,37 @@ 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(); - QPixmap pixmap = screen->grabWindow(0, x(), y(), width(), height()); + QPoint globalPos = ui->dateButton->mapToGlobal(QPoint(0, 0)); + QPixmap pixmap = screen->grabWindow(0, globalPos.x(), globalPos.y(), ui->dateButton->width(), ui->dateButton->height()); QImage image = pixmap.toImage(); // Calculate the average color QColor averageColor = getAverageColor(image); - // Determine whether to use black or white text based on the brightness of the average color + // Calculate the brightness of the average color int brightness = (averageColor.red() + averageColor.green() + averageColor.blue()) / 3; - QColor textColor = (brightness > 80) ? Qt::black : Qt::white; + + // Determine the appropriate text color using threshold range + if (brightness > upperThreshold) { + currentTextColor = Qt::black; + } else if (brightness < lowerThreshold) { + currentTextColor = Qt::white; + } // Set the text color of the dateButton - QString styleSheet = QString("QPushButton { color: %1; }").arg(textColor.name()); - ui->dateButton->setStyleSheet(styleSheet); + QString currentStyleSheet = QString("QPushButton { color: %1; }").arg(currentTextColor.name()); + if (ui->dateButton->styleSheet() != currentStyleSheet) { + ui->dateButton->setStyleSheet(currentStyleSheet); + } } From fa68893dd87696e5f77ab70f04ac8bb38636a9c5 Mon Sep 17 00:00:00 2001 From: khumnath Date: Fri, 21 Jun 2024 10:47:33 +0900 Subject: [PATCH 3/3] revamped ui to make responsive --- calendarwindow.cpp | 17 +- calendarwindow.ui | 676 ++++++++++++++++++--------------------------- 2 files changed, 280 insertions(+), 413 deletions(-) diff --git a/calendarwindow.cpp b/calendarwindow.cpp index dfd9353..162db50 100644 --- a/calendarwindow.cpp +++ b/calendarwindow.cpp @@ -257,14 +257,19 @@ 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 GitHub page.

+

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

)"; - QMessageBox msgBox(QMessageBox::Information, "About", aboutText, QMessageBox::Ok); - msgBox.setStyleSheet("QDialog { background-color: white; color: black; }" - "QLabel { color: black; }" - "QPushButton { background-color: white; color: black; }"); - msgBox.exec(); + 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; } void CalendarWindow::openSourceCode() { diff --git a/calendarwindow.ui b/calendarwindow.ui index d3162fe..5688885 100755 --- a/calendarwindow.ui +++ b/calendarwindow.ui @@ -9,8 +9,8 @@ 0 0 - 595 - 570 + 750 + 600 @@ -52,384 +52,139 @@ QMainWindow::AllowTabbedDocks - - - 90 - 90 - - - - - 900 - 700 - - - - - Noto Sans Devanagari - - - - - background-color: light gray; - - - - - - 0 - 50 - 91 - 40 - - - - - Noto Sans Devanagari - - - - - - - false - - - - - - 90 - 50 - 111 - 41 - - - - - Laila - - - - - - - 12 - - - - - - 200 - 50 - 71 - 40 - - - - - Noto Sans Devanagari - - - - - - - - - - 300 - 50 - 91 - 40 - - - - - Noto Sans Devanagari - - - - - - - - - - 390 - 50 - 101 - 41 - - - - - Laila - - - - - - - 12 - - - 0 - - - - - - 490 - 50 - 71 - 40 - - - - - Noto Sans Devanagari - - - - - - - - - - 90 - 100 - 421 - 61 - - - - - Laila Medium - 12 - false - - - - Qt::StrongFocus - - - Qt::LeftToRight - - - 2 - - - TextLabel - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - 90 - 20 - 101 - 21 - - - - - Laila SemiBold - 13 - true - false - false - true - - - - color: #00ac98; - - - अङ्ग्रेजी मिति - - - - - - 410 - 20 - 81 - 21 - - - - - Laila SemiBold - 13 - true - - - - color: #00ac98; - - - विक्रम सम्वत - - - - - true - - - - 10 - 180 - 571 - 371 - - - - - 3 - 3 - - - - - 300 - 300 - - - - - 16777215 - 371 - - - - - 1000 - 900 - - - - - 500 - 300 - - - - - Laila - - - - Qt::StrongFocus - - - Qt::NoContextMenu - - - true - - - Qt::LeftToRight - - - true - - - - - - QFrame::Box - - - QFrame::Raised - - - 1 - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - QAbstractItemView::NoEditTriggers - - - false - - - false - - - false - - - QAbstractItemView::NoSelection - - - true - - - true - - - true - - - 94 - - - true - - - true - - - true - - - true - - - - - - 520 - 150 - 51 - 21 - - - - - Laila Medium - 13 - false - - - - QPushButton#todayButton { + + + + + + Noto Sans Devanagari + + + + Qt::ClickFocus + + + false + + + + + + + + Laila + + + + 12 + + + + + + + + Noto Sans Devanagari + + + + 31 + + + + + + + + Noto Sans Devanagari + + + + Qt::ClickFocus + + + false + + + + + + + + Laila + + + + 12 + + + + + + + + Noto Sans Devanagari + + + + 31 + + + + + + + + Laila SemiBold + 13 + true + + + + color: #00ac98; + + + अङ्ग्रेजी मिति + + + + + + + + Laila SemiBold + 13 + true + + + + color: #00ac98; + + + बिक्रम संवत् मिति + + + + + + + + Laila Medium + 13 + + + + QPushButton#todayButton { 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#todayButton:hover { - background: #48C6D4; - background-image: linear-gradient(to top, #3EACBA, #48C6D4); + background: #48C6D4; + background-image: linear-gradient(to top, #3EACBA, #48C6D4); } QPushButton#todayButton:pressed { @@ -439,41 +194,148 @@ QPushButton#todayButton:pressed { /* Background color on press */ } - - - आज - - - - - - 560 - 0 - 31 - 31 - - - - - Laila - - - - - - - - - - - 35 - 35 - - - - false - - + + + आज + + + + + + + true + + + + Laila + + + + Qt::StrongFocus + + + Qt::NoContextMenu + + + true + + + true + + + QFrame::Box + + + QFrame::Raised + + + 1 + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustToContents + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + false + + + false + + + true + + + true + + + true + + + true + + + + + + + + + + Laila + + + + <html><head/><body><p>about application</p></body></html> + + + Qt::RightToLeft + + + + + + + + + + 25 + 25 + + + + false + + + + + + + + + + Laila SemiBold + 12 + true + + + + QFrame::NoFrame + + + 2 + + + TextLabel + + + true + + + Qt::AlignCenter + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + +