From d17523c91b3be731d41046cd15fb87b2306d0126 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 28 Aug 2014 23:01:16 +1000 Subject: [PATCH] Graph clone cleanups, make horizontal mouse panning graph context aware --- sleepyhead/Graphs/gGraphView.cpp | 218 ++++++++++++++++++++----------- sleepyhead/Graphs/gLineChart.cpp | 2 +- sleepyhead/reports.cpp | 12 +- 3 files changed, 151 insertions(+), 81 deletions(-) diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index 7d706290..42d4c1d7 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -2143,6 +2143,7 @@ void gGraphView::onSnapshotGraphToggle() if (graph->blockSelect()) { newgraph->setBlockSelect(true); } + newgraph->setZoomY(graph->zoomY()); newgraph->setSnapshot(true); @@ -2711,7 +2712,148 @@ void gGraphView::wheelEvent(QWheelEvent *event) if (m_button_down) return; - if ((event->modifiers() & Qt::ControlModifier)) { + if (event->modifiers() == Qt::NoModifier) { + int scrollDampening = p_profile->general->scrollDampening(); + + if (event->orientation() == Qt::Vertical) { // Vertical Scrolling + if (horizScrollTime.elapsed() < scrollDampening) { + return; + } + + if (m_scrollbar) + m_scrollbar->SendWheelEvent(event); // Just forwarding the event to scrollbar for now.. + m_tooltip->cancel(); + vertScrollTime.start(); + return; + } + // (This is a total pain in the butt on MacBook touchpads..) + + if (vertScrollTime.elapsed() < scrollDampening) { + return; + } + horizScrollTime.start(); + + gGraph *graph = nullptr; + int group = 0; + int x = event->x(); + int y = event->y(); + + float h, py = 0, pinned_height = 0; + + + // Find graph hovered over + for (int i = 0; i < m_graphs.size(); i++) { + gGraph *g = m_graphs[i]; + if (!g || g->isEmpty() || !g->visible() || !g->isPinned()) { + continue; + } + + h = g->height() * m_scaleY; + pinned_height += h + graphSpacer; + + if (py > height()) { + break; // we are done.. can't draw anymore + } + + if ((py + h + graphSpacer) >= 0) { + if ((y >= py) && (y <= py + h)) { + graph = g; + break; + } else if ((y >= py + h) && (y <= py + h + graphSpacer + 1)) { + // What to do when double clicked on the resize handle? + graph = g; + break; + } + } + + py += h; + py += graphSpacer; // do we want the extra spacer down the bottom? + } + if (!graph) { + py = -m_offsetY; + py += pinned_height; + + for (int i = 0; i < m_graphs.size(); i++) { + gGraph *g = m_graphs[i]; + if (!g || g->isEmpty() || !g->visible() || g->isPinned()) { + continue; + } + + h = g->height() * m_scaleY; + + if (py > height()) { + break; + } + + if ((py + h + graphSpacer) >= 0) { + if ((y >= py) && (y <= py + h)) { + graph = g; + break; + } else if ((y >= py + h) && (y <= py + h + graphSpacer + 1)) { + // What to do when double clicked on the resize handle? + graph = g; + break; + } + + } + + py += h; + py += graphSpacer; // do we want the extra spacer down the bottom? + } + } + +// // Pick the first valid graph in the primary group +// for (int i = 0; i < m_graphs.size(); i++) { +// if (!m_graphs[i]) continue; +// if (m_graphs[i]->group() == group) { +// if (!m_graphs[i]->isEmpty() && m_graphs[i]->visible()) { +// g = m_graphs[i]; +// break; +// } +// } +// } + + if (!graph) { + // just pick any graph then + for (int i = 0; i < m_graphs.size(); i++) { + if (!m_graphs[i]) continue; + if (!m_graphs[i]->isEmpty()) { + graph = m_graphs[i]; + group = graph->group(); + break; + } + } + } else group=graph->group(); + + if (!graph) { return; } + + double xx = (graph->max_x - graph->min_x); + double zoom = 240.0; + + int delta = event->delta(); + + if (delta > 0) { + graph->min_x -= (xx / zoom) * (float)abs(delta); + } else { + graph->min_x += (xx / zoom) * (float)abs(delta); + } + + graph->max_x = graph->min_x + xx; + + if (graph->min_x < graph->rmin_x) { + graph->min_x = graph->rmin_x; + graph->max_x = graph->rmin_x + xx; + } + + if (graph->max_x > graph->rmax_x) { + graph->max_x = graph->rmax_x; + graph->min_x = graph->max_x - xx; + } + + saveHistory(); + SetXBounds(graph->min_x, graph->max_x, group); + + } else if ((event->modifiers() & Qt::ControlModifier)) { int x = event->x(); int y = event->y(); @@ -2745,80 +2887,6 @@ void gGraphView::wheelEvent(QWheelEvent *event) py += h; py += graphSpacer; // do we want the extra spacer down the bottom? } - } else { - int scrollDampening = p_profile->general->scrollDampening(); - - if (event->orientation() == Qt::Vertical) { // Vertical Scrolling - if (horizScrollTime.elapsed() < scrollDampening) { - return; - } - - if (m_scrollbar) - m_scrollbar->SendWheelEvent(event); // Just forwarding the event to scrollbar for now.. - m_tooltip->cancel(); - vertScrollTime.start(); - } else { //Horizontal Panning - // (This is a total pain in the butt on MacBook touchpads..) - - if (vertScrollTime.elapsed() < scrollDampening) { - return; - } - - horizScrollTime.start(); - gGraph *g = nullptr; - int group = 0; - - // Pick the first valid graph in the primary group - for (int i = 0; i < m_graphs.size(); i++) { - if (!m_graphs[i]) continue; - if (m_graphs[i]->group() == group) { - if (!m_graphs[i]->isEmpty() && m_graphs[i]->visible()) { - g = m_graphs[i]; - break; - } - } - } - - if (!g) { - // just pick any graph then - for (int i = 0; i < m_graphs.size(); i++) { - if (!m_graphs[i]) continue; - if (!m_graphs[i]->isEmpty()) { - g = m_graphs[i]; - group = g->group(); - break; - } - } - } - - if (!g) { return; } - - double xx = (g->max_x - g->min_x); - double zoom = 240.0; - - int delta = event->delta(); - - if (delta > 0) { - g->min_x -= (xx / zoom) * (float)abs(delta); - } else { - g->min_x += (xx / zoom) * (float)abs(delta); - } - - g->max_x = g->min_x + xx; - - if (g->min_x < g->rmin_x) { - g->min_x = g->rmin_x; - g->max_x = g->rmin_x + xx; - } - - if (g->max_x > g->rmax_x) { - g->max_x = g->rmax_x; - g->min_x = g->max_x - xx; - } - - saveHistory(); - SetXBounds(g->min_x, g->max_x, group); - } } } diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index b0eafcbe..3fb55f64 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -490,7 +490,7 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion ®ion) int wid, h; GetTextExtent(text, wid, h); - w.renderText(text, left , top-h+5); //+ width/2 - wid/2 + w.renderText(text, left , top-h+7*w.printScaleY()); //+ width/2 - wid/2 } } diff --git a/sleepyhead/reports.cpp b/sleepyhead/reports.cpp index 1409f383..756c9db0 100644 --- a/sleepyhead/reports.cpp +++ b/sleepyhead/reports.cpp @@ -388,14 +388,14 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) painter.drawText(bounds, ovinfo, QTextOption(Qt::AlignHCenter)); if (bounds.height() > maxy) { maxy = bounds.height(); } - } else if (name == STR_TR_Oximetry) { + } /*else if (name == STR_TR_Oximetry) { QString ovinfo = QObject::tr("Reporting data goes here"); QRectF bounds = painter.boundingRect(QRectF(0, top, virt_width, 0), ovinfo, QTextOption(Qt::AlignHCenter)); painter.drawText(bounds, ovinfo, QTextOption(Qt::AlignHCenter)); if (bounds.height() > maxy) { maxy = bounds.height(); } - } + }*/ top += maxy; @@ -406,6 +406,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) QVector graphs; QVector start, end; qint64 savest, saveet; + gv->GetXBounds(savest, saveet); qint64 st = savest, et = saveet; @@ -568,8 +569,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) } if (first) { - QString footer = QObject::tr("SleepyHead v%1 - http://sleepyhead.sourceforge.net").arg( - VersionString); + QString footer = QObject::tr("SleepyHead v%1 - http://sleepyhead.sourceforge.net").arg(VersionString); QRectF bounds = painter.boundingRect(QRectF(0, virt_height, virt_width, normal_height), footer, QTextOption(Qt::AlignHCenter)); @@ -584,7 +584,9 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date) } gGraph *g = graphs[i]; - g->SetXBounds(start[i], end[i]); + if (!g->isSnapshot()) { + g->SetXBounds(start[i], end[i]); + } g->deselect(); QString label = labels[i];