Skip to content

Commit

Permalink
Merge pull request #9 from khumnath/devlopment
Browse files Browse the repository at this point in the history
build widget and calendar for windows and ui improve
  • Loading branch information
khumnath authored Jun 22, 2024
2 parents 419a3b2 + 88ad79d commit eac6c19
Show file tree
Hide file tree
Showing 12 changed files with 587 additions and 323 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions DayTithiWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,6 +32,7 @@ class DayTithiWidget : public QWidget {
}

void setSaturdayStyle() {
setStyleSheet("background-color: transparent;");
dayLabel->setStyleSheet("font-size: 19px; color: red; font-family: 'laila';");
}

Expand Down
2 changes: 1 addition & 1 deletion bikram.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
58 changes: 35 additions & 23 deletions calendarwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -138,17 +139,24 @@ CalendarWindow::CalendarWindow(QWidget *parent) :
connect(ui->yearselectBS, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CalendarWindow::onBsYearChanged);
connect(ui->monthselectBS, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &CalendarWindow::onBsMonthChanged);
connect(ui->dayselectBS, QOverload<int>::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);
// Adjust cell sizes initially
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();

Expand Down Expand Up @@ -257,25 +265,23 @@ void CalendarWindow::showAbout() {
<p>nepali calendar</p>
<p><b>Author:</b> <span style="font-weight: bold;">khumnath</span></p>
<p><b>Version:</b> 1.0.0</p>
<p>This application is written in C++ and Qt framework. For more information, visit my <a href="https://khumnath.com.np/posts/2024-06-20-post3" style="color: blue; text-decoration: underline;">Website</a>.</p>
<p>This application is written in C++ and Qt framework. For more information, visit my <a href="https://github.com/khumnath/nepdate" style="color: blue; text-decoration: underline;">GitHub page</a>.</p>
</center>)";

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -593,4 +606,3 @@ void CalendarWindow::populateBsDays(int year, int month) {
// Set the current day
ui->dayselectBS->setCurrentText(QString::number(currentDay));
}

3 changes: 2 additions & 1 deletion calendarwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit eac6c19

Please sign in to comment.