From 8f103ab5257729e8f01d6f9eff1476b08d87bdee Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Mon, 12 Sep 2011 13:07:57 +1000 Subject: [PATCH] Overview Popup Calendar Improvements --- overview.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ overview.h | 6 +++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/overview.cpp b/overview.cpp index b42135a2..fd53c74d 100644 --- a/overview.cpp +++ b/overview.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "overview.h" #include "ui_overview.h" #include "Graphs/gXAxis.h" @@ -123,10 +125,20 @@ Overview::Overview(QWidget *parent,Profile * _profile,gGraphView * shared) : ui->dateStart->setDisplayFormat(shortformat); ui->dateEnd->setDisplayFormat(shortformat); + QTextCharFormat format = ui->dateStart->calendarWidget()->weekdayTextFormat(Qt::Saturday); + format.setForeground(QBrush(Qt::black, Qt::SolidPattern)); + ui->dateStart->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format); + ui->dateStart->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format); + ui->dateEnd->calendarWidget()->setWeekdayTextFormat(Qt::Saturday, format); + ui->dateEnd->calendarWidget()->setWeekdayTextFormat(Qt::Sunday, format); + connect(ui->dateStart->calendarWidget(),SIGNAL(currentPageChanged(int,int)),this,SLOT(on_dateStart_currentPageChanged(int,int))); + connect(ui->dateEnd->calendarWidget(),SIGNAL(currentPageChanged(int,int)),this,SLOT(on_dateEnd_currentPageChanged(int,int))); report=NULL; } Overview::~Overview() { + disconnect(this,SLOT(on_dateStart_currentPageChanged(int,int))); + disconnect(this,SLOT(on_dateEnd_currentPageChanged(int,int))); if (report) { report->close(); delete report; @@ -141,6 +153,55 @@ void Overview::ReloadGraphs() GraphView->setDay(NULL); } +void Overview::UpdateCalendarDay(QDateEdit * dateedit,QDate date) +{ + QCalendarWidget *calendar=dateedit->calendarWidget(); + QTextCharFormat bold; + QTextCharFormat cpapcol; + QTextCharFormat normal; + QTextCharFormat oxiday; + bold.setFontWeight(QFont::Bold); + cpapcol.setForeground(QBrush(Qt::blue, Qt::SolidPattern)); + cpapcol.setFontWeight(QFont::Bold); + oxiday.setForeground(QBrush(Qt::red, Qt::SolidPattern)); + oxiday.setFontWeight(QFont::Bold); + bool hascpap=profile->GetDay(date,MT_CPAP)!=NULL; + bool hasoxi=profile->GetDay(date,MT_OXIMETER)!=NULL; + + if (hascpap) { + if (hasoxi) { + calendar->setDateTextFormat(date,oxiday); + } else { + calendar->setDateTextFormat(date,cpapcol); + } + } else if (profile->GetDay(date)) { + calendar->setDateTextFormat(date,bold); + } else { + calendar->setDateTextFormat(date,normal); + } + calendar->setHorizontalHeaderFormat(QCalendarWidget::ShortDayNames); +} +void Overview::on_dateStart_currentPageChanged(int year, int month) +{ + QDate d(year,month,1); + int dom=d.daysInMonth(); + + for (int i=1;i<=dom;i++) { + d=QDate(year,month,i); + UpdateCalendarDay(ui->dateStart,d); + } +} +void Overview::on_dateEnd_currentPageChanged(int year, int month) +{ + QDate d(year,month,1); + int dom=d.daysInMonth(); + + for (int i=1;i<=dom;i++) { + d=QDate(year,month,i); + UpdateCalendarDay(ui->dateEnd,d); + } +} + void Overview::on_dateEnd_dateChanged(const QDate &date) { diff --git a/overview.h b/overview.h index 34fde0d6..ba5eac01 100644 --- a/overview.h +++ b/overview.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "SleepLib/profiles.h" #include "Graphs/gGraphView.h" #include "Graphs/gBarChart.h" @@ -45,9 +46,11 @@ private slots: void on_rbEverything_clicked(); void on_rbDateRange_clicked(); */ + void on_dateStart_dateChanged(const QDate &date); void on_dateEnd_dateChanged(const QDate &date); - void on_dateStart_dateChanged(const QDate &date); + void on_dateStart_currentPageChanged(int year, int month); + void on_dateEnd_currentPageChanged(int year, int month); void on_toolButton_clicked(); @@ -62,6 +65,7 @@ private: Report * report; void UpdateHTML(); + void UpdateCalendarDay(QDateEdit * calendar,QDate date); //SessionTimes *session_times; //,*PRESSURE,*LEAK,*SESSTIMES;