From f0097e38ae46f946108230f9a6ca93c28e1a84d8 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 29 Aug 2014 01:45:46 +1000 Subject: [PATCH] Disable linecursor during printing, move date indicators down bottom in overview --- sleepyhead/Graphs/gGraph.cpp | 4 +++- sleepyhead/Graphs/gGraphView.cpp | 12 ++++++++++ sleepyhead/Graphs/gSummaryChart.cpp | 10 ++++----- sleepyhead/overview.cpp | 34 +++++++++++++++++++++++++++++ sleepyhead/overview.h | 4 ++++ sleepyhead/overview.ui | 8 ++++++- sleepyhead/reports.cpp | 3 +++ 7 files changed, 68 insertions(+), 7 deletions(-) diff --git a/sleepyhead/Graphs/gGraph.cpp b/sleepyhead/Graphs/gGraph.cpp index 92b111ba..6024f744 100644 --- a/sleepyhead/Graphs/gGraph.cpp +++ b/sleepyhead/Graphs/gGraph.cpp @@ -329,7 +329,9 @@ void gGraph::paint(QPainter &painter, const QRegion ®ion) QString t = name().section(";", -1); - painter.drawText(m_rect, Qt::AlignHCenter | Qt::AlignTop, QObject::tr("Snapshot %1").arg(t)); + QRect rec = m_rect; + rec.moveTop(rec.top() + 4); + painter.drawText(rec, Qt::AlignHCenter | Qt::AlignTop, QObject::tr("Snapshot %1").arg(t)); } diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index 679232fc..20eb6e04 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -1371,6 +1371,18 @@ QString gGraphView::getRangeString() qint64 diff = m_maxx - m_minx; if (diff > 86400000) { + int days = ceil(double(m_maxx-m_minx) / 86400000.0); + + qint64 minx = floor(double(m_minx)/86400000.0); + minx *= 86400000L; + + qint64 maxx = minx + 86400000L * qint64(days)-1; + + QDateTime st = QDateTime::fromMSecsSinceEpoch(minx); + QDateTime et = QDateTime::fromMSecsSinceEpoch(maxx); + + QString txt = st.toString("d MMM") + " - " + et.addDays(-1).toString("d MMM yyyy"); + return txt; } else if (diff > 60000) { fmt = "HH:mm:ss"; } else { diff --git a/sleepyhead/Graphs/gSummaryChart.cpp b/sleepyhead/Graphs/gSummaryChart.cpp index 380c8d1e..1039903c 100644 --- a/sleepyhead/Graphs/gSummaryChart.cpp +++ b/sleepyhead/Graphs/gSummaryChart.cpp @@ -527,13 +527,13 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) - QDateTime dt=QDateTime::fromMSecsSinceEpoch(time,Qt::UTC); +// QDateTime dt=QDateTime::fromMSecsSinceEpoch(time,Qt::UTC); - QString text = dt.date().toString(Qt::SystemLocaleLongDate); +// QString text = dt.date().toString(Qt::SystemLocaleLongDate); - int wid, h; - GetTextExtent(text, wid, h); - w.renderText(text, left + width/2 - wid/2, top-h+5); +// int wid, h; + // GetTextExtent(text, wid, h); + // w.renderText(text, left + width/2 - wid/2, top-h+5); } diff --git a/sleepyhead/overview.cpp b/sleepyhead/overview.cpp index 9b21289e..fbf45fec 100644 --- a/sleepyhead/overview.cpp +++ b/sleepyhead/overview.cpp @@ -102,6 +102,18 @@ Overview::Overview(QWidget *parent, gGraphView *shared) : layout->addWidget(scrollbar, 0); layout->layout(); + dateLabel = new MyLabel(this); + dateLabel->setAlignment(Qt::AlignVCenter); + dateLabel->setText("[Date Widget]"); + QFont font = dateLabel->font(); + font.setPointSizeF(font.pointSizeF()*1.3F); + dateLabel->setFont(font); + QPalette palette = dateLabel->palette(); + palette.setColor(QPalette::Base, Qt::blue); + dateLabel->setPalette(palette); + + ui->dateLayout->addWidget(dateLabel,1); + // TODO: Automate graph creation process ChannelID ahicode = p_profile->general->calculateRDI() ? CPAP_RDI : CPAP_AHI; @@ -316,6 +328,10 @@ Overview::Overview(QWidget *parent, gGraphView *shared) : GraphView->setEmptyImage(QPixmap(":/docs/sheep.png")); + connect(GraphView, SIGNAL(updateCurrentTime(double)), this, SLOT(on_LineCursorUpdate(double))); + connect(GraphView, SIGNAL(updateRange(double,double)), this, SLOT(on_RangeUpdate(double,double))); + + } Overview::~Overview() { @@ -362,6 +378,24 @@ gGraph *Overview::createGraph(QString code, QString name, QString units, YTicker return g; } +void Overview::on_LineCursorUpdate(double time) +{ + if (time > 1) { + QDateTime dt = QDateTime::fromMSecsSinceEpoch(time); + QString txt = dt.toString("dd MMM yyyy"); + dateLabel->setText(txt); + } else dateLabel->setText(QString(GraphView->emptyText())); +} + +void Overview::on_RangeUpdate(double minx, double maxx) +{ + if (minx > 1) { + dateLabel->setText(GraphView->getRangeString()); + } else { + dateLabel->setText(QString(GraphView->emptyText())); + } +} + void Overview::ReloadGraphs() { GraphView->setDay(nullptr); diff --git a/sleepyhead/overview.h b/sleepyhead/overview.h index 2655b9af..eec0dc20 100644 --- a/sleepyhead/overview.h +++ b/sleepyhead/overview.h @@ -109,6 +109,9 @@ class Overview : public QWidget void on_toggleVisibility_clicked(bool checked); + void on_LineCursorUpdate(double time); + void on_RangeUpdate(double minx, double maxx); + private: Ui::Overview *ui; gGraphView *GraphView; @@ -117,6 +120,7 @@ class Overview : public QWidget gGraphView *m_shared; QIcon *icon_on; QIcon *icon_off; + MyLabel *dateLabel; //! \brief Updates the calendar highlighting for the calendar object for this date. void UpdateCalendarDay(QDateEdit *calendar, QDate date); diff --git a/sleepyhead/overview.ui b/sleepyhead/overview.ui index da4a967f..a1db8294 100644 --- a/sleepyhead/overview.ui +++ b/sleepyhead/overview.ui @@ -205,14 +205,20 @@ QToolButton:pressed { Qt::Horizontal + + QSizePolicy::Fixed + - 260 + 4 20 + + + diff --git a/sleepyhead/reports.cpp b/sleepyhead/reports.cpp index 71c3178d..5ee2a559 100644 --- a/sleepyhead/reports.cpp +++ b/sleepyhead/reports.cpp @@ -423,6 +423,8 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) } qint64 st = savest, et = saveet; + bool lineCursorMode = p_profile->appearance->lineCursorMode(); + p_profile->appearance->setLineCursorMode(false); if (name == STR_TR_Daily) { if (!print_bookmarks) { @@ -655,5 +657,6 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) painter.end(); delete printer; mainwin->Notify(QObject::tr("SleepyHead has finished sending the job to the printer.")); + p_profile->appearance->setLineCursorMode(lineCursorMode); }