Skip to content

Commit

Permalink
Merge pull request #10 from khumnath/devlopment
Browse files Browse the repository at this point in the history
created icon for purnima and amawasya
corrected autostart file name for linux
created JavaScript date converter
  • Loading branch information
khumnath authored Jul 16, 2024
2 parents b67b290 + e2cafb8 commit d63a470
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 13 deletions.
49 changes: 43 additions & 6 deletions DayTithiWidget.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QIcon>
#include <QPixmap>
#include <QPainter>

class DayTithiWidget : public QWidget {
Q_OBJECT

public:
explicit DayTithiWidget(const QString &day, const QString &tithi, QWidget *parent = nullptr)
: QWidget(parent) {
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0); // Remove margins
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0); // Remove margins

dayLabel = new QLabel(day, this);
dayLabel->setObjectName("dayLabel"); // Set object name for styling
Expand All @@ -23,10 +26,19 @@ class DayTithiWidget : public QWidget {
tithiLabel->setObjectName("tithiLabel"); // Set object name for styling
tithiLabel->setStyleSheet("font-size: 10px; color: blue; background-color: transparent; font-family: 'laila';");

layout->addWidget(dayLabel);
layout->addWidget(tithiLabel);
iconLabel = new QLabel(this);
iconLabel->setObjectName("iconLabel");
iconLabel->setAlignment(Qt::AlignJustify);
iconLabel->setStyleSheet("background-color: transparent;");
iconLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

mainLayout->addWidget(dayLabel);
mainLayout->addWidget(iconLabel);
mainLayout->addWidget(tithiLabel);
adjustIconSize();
}
void setTodayStyle() {

void setTodayStyle() {
setStyleSheet("background-color: transparent;");
dayLabel->setStyleSheet("font-size: 20px; font-weight: bold; text-decoration: underline; color: green; font-family: 'laila';");
}
Expand All @@ -36,11 +48,36 @@ class DayTithiWidget : public QWidget {
dayLabel->setStyleSheet("font-size: 19px; color: red; font-family: 'laila';");
}

void setIcon(const QIcon &icon, qreal opacity = 1.0) {
if (!icon.isNull()) {
QPixmap pixmap = icon.pixmap(iconSize);
QPixmap transparentPixmap(pixmap.size());
transparentPixmap.fill(Qt::transparent);

QPainter painter(&transparentPixmap);
painter.setOpacity(opacity);
painter.drawPixmap(0, 0, pixmap);
painter.end();

iconLabel->setPixmap(transparentPixmap); // Set the transparent pixmap
} else {
iconLabel->clear(); // Clear the icon if no icon is provided
}
}

private:
QLabel *dayLabel;
QLabel *tithiLabel;
QLabel *iconLabel;
QSize iconSize = QSize(15, 15);
void adjustIconSize() {
// Calculate available space and adjust icon size if necessary
int availableHeight = iconLabel->height()-3; // Adjust for borders
int availableWidth = iconLabel->width()-3; // Adjust for borders

int minSize = qMin(availableWidth, availableHeight);
iconSize = QSize(minSize, minSize);
}
};

#endif // DAYTITHIWIDGET_H
21 changes: 16 additions & 5 deletions calendarwindow.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QScreen>
#include <QDate>
#include <QDebug>
#include <QIcon>

CalendarWindow::CalendarWindow(QWidget *parent) :
QMainWindow(parent),
Expand Down Expand Up @@ -443,7 +444,6 @@ void CalendarWindow::updateAdDateFromBs(int year, int month, int day) {
populateBsDays(year, month);
}


void CalendarWindow::updateCalendar(int year, int month) {
int daysInMonth = converter.daysInMonth(year, month);

Expand Down Expand Up @@ -485,7 +485,7 @@ void CalendarWindow::updateCalendar(int year, int month) {
);

// Find the first day of the month

int gYear, gMonth, gDay;
converter.toGregorian(year, month, 1, gYear, gMonth, gDay);
QDate firstDay(gYear, gMonth, gDay);
int startDay = firstDay.dayOfWeek(); // 0 (Monday) to 6 (Sunday)
Expand All @@ -502,6 +502,10 @@ void CalendarWindow::updateCalendar(int year, int month) {
// Identify Saturday index (assuming "शनि" is at index 6)
int saturdayIndex = 6; // Modify this if "शनि" is at a different index

// Load moon icons
QIcon purnimaIcon(":/resources/purnima.png");
QIcon amavasyaIcon(":/resources/amawasya.png");

// Fill the calendar
int row = 0;
int col = (startDay - saturdayIndex + 6) % 7; // Calculate offset based on Saturday index
Expand All @@ -520,7 +524,6 @@ void CalendarWindow::updateCalendar(int year, int month) {

// Set tooltip
QString paksha = QString::fromStdString(panchang.paksha);
//customWidget->setToolTip(tithiName, paksha);
QString tooltipText = QString("%1 (%2)").arg(tithiName).arg(paksha);
customWidget->setToolTip(tooltipText);

Expand All @@ -533,17 +536,24 @@ void CalendarWindow::updateCalendar(int year, int month) {

if (isToday && isSaturday) {
// If today is both Saturday and the current date, apply the "today" style
item->setBackground(QColor(153,255,204)); // light green
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
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();
}

if (panchang.tithi_index == 14) {
customWidget->setIcon(purnimaIcon, 0.8); // Example opacity set to 0.8
} else if (panchang.tithi_index == 29) {
customWidget->setIcon(amavasyaIcon, 0.8); // Example opacity set to 0.8
} else {
customWidget->setIcon(QIcon(), 0.0); // Clear icon and set transparency
}

ui->calendarTable->setCellWidget(row, col, customWidget);
col++;
Expand All @@ -567,6 +577,7 @@ void CalendarWindow::updateCalendar(int year, int month) {




void CalendarWindow::adjustCellSizes() {
int tableWidth = ui->calendarTable->viewport()->width();
int tableHeight = ui->calendarTable->viewport()->height();
Expand Down
Loading

0 comments on commit d63a470

Please sign in to comment.