diff --git a/sleepyhead/Graphs/gFlagsLine.cpp b/sleepyhead/Graphs/gFlagsLine.cpp index 154a1290..73973aa2 100644 --- a/sleepyhead/Graphs/gFlagsLine.cpp +++ b/sleepyhead/Graphs/gFlagsLine.cpp @@ -366,7 +366,7 @@ void gFlagsLine::paint(QPainter &painter, gGraph &w, const QRegion ®ion) brush = QBrush(color); painter.fillRect(x2, bartop, x1-x2, bottom-bartop, brush); - if (!hover && QRect(x2, bartop, x1-x2, bottom-bartop).contains(w.graphView()->currentMousePos())) { + if (!w.selectingArea() && !hover && QRect(x2, bartop, x1-x2, bottom-bartop).contains(w.graphView()->currentMousePos())) { hover = true; painter.setPen(QPen(Qt::red,1)); @@ -394,7 +394,7 @@ void gFlagsLine::paint(QPainter &painter, gGraph &w, const QRegion ®ion) x1 = (X - minx) * xmult + left; - if (!hover && QRect(x1-3, bartop-2, 6, bottom-bartop+4).contains(w.graphView()->currentMousePos())) { + if (!w.selectingArea() && !hover && QRect(x1-3, bartop-2, 6, bottom-bartop+4).contains(w.graphView()->currentMousePos())) { hover = true; painter.setPen(QPen(Qt::red,1)); diff --git a/sleepyhead/Graphs/gGraph.cpp b/sleepyhead/Graphs/gGraph.cpp index a6081a55..1972784b 100644 --- a/sleepyhead/Graphs/gGraph.cpp +++ b/sleepyhead/Graphs/gGraph.cpp @@ -766,6 +766,10 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) m_selDurString.sprintf("%02i:%02i:%02i:%03i", h, m, s, ms); } + ToolTipAlignment align = x >= x2 ? TT_AlignLeft : TT_AlignRight; + int offset = (x >= x2) ? 20 : - 20; + ToolTip(m_selDurString, m_rect.left() + x + offset, m_rect.top() + y + 20, align); + if (qstatus2) { qstatus2->setText(m_selDurString); } @@ -836,6 +840,9 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) // //qDebug() << m_title << "Moved" << x << y << left << right << top << bottom << m_width << m_height; // } } + +bool gGraph::selectingArea() { return m_selecting_area || m_graphview->metaSelect(); } + void gGraph::mousePressEvent(QMouseEvent *event) { int y = event->pos().y(); diff --git a/sleepyhead/Graphs/gGraph.h b/sleepyhead/Graphs/gGraph.h index 4d93111b..bfff230c 100644 --- a/sleepyhead/Graphs/gGraph.h +++ b/sleepyhead/Graphs/gGraph.h @@ -106,9 +106,13 @@ class gGraph : public QObject //! \brief Returns true if none of the included layers have data attached bool isEmpty(); + //! \brief Returns true if the user is currently dragging the mouse to select an area + bool selectingArea(); + double currentTime() const; + //! \brief Add Layer l to graph object, allowing you to specify position, // margin sizes, order, movability status and offsets void AddLayer(Layer *l, LayerPosition position = LayerCenter, diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index 255c2774..23afeb88 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -936,16 +936,80 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) } } painter.setClipping(false); + + + // Calculate combined session times within selected area... + double first, last; + double time = 0; + + // Calculate the session time. + for (QList::iterator s = m_day->begin(); s != m_day->end(); s++) { + if (!(*s)->enabled()) { continue; } + + first = (*s)->first(); + last = (*s)->last(); + + if (last < w.min_x) { continue; } + if (first > w.max_x) { continue; } + + if (first < w.min_x) { + first = w.min_x; + } + + if (last > w.max_x) { + last = w.max_x; + } + + time += last - first; + } + + + time /= 1000; + + QList ahilist; + ahilist.push_back(CPAP_Hypopnea); + ahilist.push_back(CPAP_Obstructive); + ahilist.push_back(CPAP_Apnea); + ahilist.push_back(CPAP_ClearAirway); + + QList extras; + ahilist.push_back(CPAP_NRI); + ahilist.push_back(CPAP_UserFlag1); + ahilist.push_back(CPAP_UserFlag2); + + double sum = 0; + int cnt = 0; + + // Draw the linechart overlays if (m_day && (p_profile->appearance->lineCursorMode() || (m_codes[0]==CPAP_FlowRate))) { QHash::iterator fit; bool blockhover = false; for (fit = flags.begin(); fit != flags.end(); ++fit) { + ChannelID code = fit.key(); gLineOverlayBar * lob = fit.value(); lob->setBlockHover(blockhover); lob->paint(painter, w, region); if (lob->hover()) blockhover = true; // did it render a hover over? + + if (ahilist.contains(code)) { + sum += lob->sum(); + cnt += lob->count(); + } } } + if (m_codes[0] == CPAP_FlowRate) { + float hours = float(time) / 3600.0; + int h = time / 3600; + int m = int(time / 60) % 60; + int s = int(time) % 60; + + float f = float(cnt) / hours; // / (sum / 3600.0); + QString txt = QObject::tr("Duration %1:%2:%3").arg(h,2,10,QChar('0')).arg(m,2,10,QChar('0')).arg(s,2,10,QChar('0')) + " "+ + QObject::tr("AHI: %1").arg(f,0,'f',2); + painter.setPen(Qt::black); + painter.drawText(left,top-4,txt); + } + painter.setRenderHint(QPainter::Antialiasing, false); } diff --git a/sleepyhead/Graphs/gLineOverlay.cpp b/sleepyhead/Graphs/gLineOverlay.cpp index d3cd18b5..84f7ef8d 100644 --- a/sleepyhead/Graphs/gLineOverlay.cpp +++ b/sleepyhead/Graphs/gLineOverlay.cpp @@ -222,7 +222,7 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion) painter.setPen(QPen(col,4)); painter.drawPoint(x1, top); - if (!m_blockhover && rect.contains(mouse) && !m_hover) { + if (!w.selectingArea() && !m_blockhover && rect.contains(mouse) && !m_hover) { m_hover = true; @@ -270,7 +270,7 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion) // Top and bottom markers ////////////////////////////////////////////////////////////////////////////////////// bool b = false; - if (!m_blockhover && QRect(x1-2, topp, 6, height).contains(mouse) && !m_hover) { + if (!w.selectingArea() && !m_blockhover && QRect(x1-2, topp, 6, height).contains(mouse) && !m_hover) { // only want to draw the highlight/label once per frame m_hover = true; b = true; @@ -401,11 +401,12 @@ void gLineOverlaySummary::paint(QPainter &painter, gGraph &w, const QRegion ® QString a; - if ((w.graphView()->selectionInProgress() || w.graphView()->metaSelect()) && (!w.selDurString().isEmpty())) { + if (0) { //(w.graphView()->selectionInProgress())) { // || w.graphView()->metaSelect()) && (!w.selDurString().isEmpty())) { a = QObject::tr("Duration")+": "+w.selDurString(); } else { a = QObject::tr("Events") + ": " + QString::number(cnt) + ", " + - QObject::tr("Duration") + " " + QString().sprintf("%02i:%02i:%02i", h, m, s) + ", " + m_text + ": " + QString::number(val, 'f', 2); + QObject::tr("Duration") + " " + QString().sprintf("%02i:%02i:%02i", h, m, s) + ", " + + m_text + ": " + QString::number(val, 'f', 2); } if (isSpan) { float sph;