From cbeba3fe052a82535af3e6e3d27e47dbc082755d Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sun, 20 Jul 2014 00:09:04 +1000 Subject: [PATCH] Make all mouse events save history --- sleepyhead/Graphs/gGraph.cpp | 9 ++++++++- sleepyhead/Graphs/gGraphView.cpp | 18 ++++++++++-------- sleepyhead/Graphs/gGraphView.h | 11 ++++++++++- sleepyhead/Graphs/glcommon.h | 2 ++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/sleepyhead/Graphs/gGraph.cpp b/sleepyhead/Graphs/gGraph.cpp index 0198ea62..fe50345f 100644 --- a/sleepyhead/Graphs/gGraph.cpp +++ b/sleepyhead/Graphs/gGraph.cpp @@ -761,6 +761,7 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) min_x = rmax_x - xx; } + m_graphview->saveHistory(); m_graphview->SetXBounds(min_x, max_x, m_group, false); doredraw = true; } else { @@ -784,6 +785,7 @@ void gGraph::mouseMoveEvent(QMouseEvent *event) min_x = rmax_x - xx; } + m_graphview->saveHistory(); m_graphview->SetXBounds(min_x, max_x, m_group, false); doredraw = true; } @@ -889,6 +891,7 @@ void gGraph::mouseReleaseEvent(QMouseEvent *event) } else { if (a2 - a1 < zoom_hard_limit) { a2 = a1 + zoom_hard_limit; } + m_graphview->saveHistory(); m_graphview->SetXBounds(a1, a2, m_group); } } else { @@ -906,7 +909,7 @@ void gGraph::mouseReleaseEvent(QMouseEvent *event) qDebug() << "Foo2??"; } else { if (a2 - a1 < zoom_hard_limit) { a2 = a1 + zoom_hard_limit; } - + m_graphview->saveHistory(); m_graphview->SetXBounds(a1, a2, m_group); } } @@ -980,6 +983,7 @@ void gGraph::mouseReleaseEvent(QMouseEvent *event) min_x = rmax_x - xx; } + m_graphview->saveHistory(); m_graphview->SetXBounds(min_x, max_x, m_group); m_lastx23 = x; } @@ -1116,6 +1120,9 @@ void gGraph::ZoomX(double mult, int origin_px) min = max - q; } + extern const int max_history; + + m_graphview->saveHistory(); m_graphview->SetXBounds(min, max, m_group); //updateSelectionTime(max-min); } diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index a9de226b..e4f25fc6 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -39,6 +39,7 @@ extern MainWindow *mainwin; extern QLabel *qstatus2; + gToolTip::gToolTip(gGraphView *graphview) : m_graphview(graphview) { @@ -1573,13 +1574,7 @@ void gGraphView::mouseReleaseEvent(QMouseEvent *event) if (m_button_down) { m_button_down = false; m_metaselect = event->modifiers() & Qt::ShiftModifier; - - const int max_history = 20; - - history.push_front(SelectionHistoryItem(m_minx, m_maxx)); - if (history.size() > max_history) { - history.pop_back(); - } + saveHistory(); if (m_metaselect) { m_point_released = event->pos(); @@ -1603,7 +1598,10 @@ void gGraphView::keyReleaseEvent(QKeyEvent *event) if (history.size() > 0) { SelectionHistoryItem h = history.takeFirst(); SetXBounds(h.minx, h.maxx); + + // could Forward push this to another list? } else { + ResetBounds(); } return; @@ -1731,8 +1729,9 @@ void gGraphView::wheelEvent(QWheelEvent *event) // What to do when ctrl+wheel is used on the graph title ?? } else { // send event to graph.. - if (!m_button_down) + if (!m_button_down) { m_graphs[i]->wheelEvent(event); + } } } else if ((y >= py + h) && (y <= py + h + graphSpacer + 1)) { // What to do when the wheel is used on the resize handle? @@ -1812,6 +1811,7 @@ void gGraphView::wheelEvent(QWheelEvent *event) g->min_x = g->max_x - xx; } + saveHistory(); SetXBounds(g->min_x, g->max_x, group); } } @@ -1891,6 +1891,7 @@ void gGraphView::keyPressEvent(QKeyEvent *event) g->max_x = g->rmin_x + xx; } + saveHistory(); SetXBounds(g->min_x, g->max_x, group); } else if (event->key() == Qt::Key_Right) { double xx = g->max_x - g->min_x; @@ -1906,6 +1907,7 @@ void gGraphView::keyPressEvent(QKeyEvent *event) g->min_x = g->rmax_x - xx; } + saveHistory(); SetXBounds(g->min_x, g->max_x, group); } else if (event->key() == Qt::Key_Up) { float zoom = 0.75F; diff --git a/sleepyhead/Graphs/gGraphView.h b/sleepyhead/Graphs/gGraphView.h index 06c95a68..32df1b63 100644 --- a/sleepyhead/Graphs/gGraphView.h +++ b/sleepyhead/Graphs/gGraphView.h @@ -269,6 +269,13 @@ class gGraphView inline void setPrintScaleX(float x) { print_scaleX = x; } inline void setPrintScaleY(float y) { print_scaleY = y; } + void saveHistory() { + history.push_front(SelectionHistoryItem(m_minx, m_maxx)); + if (history.size() > max_history) { + history.pop_back(); + } + } + //! \brief Returns true if all Graph objects contain NO day data. ie, graph area is completely empty. bool isEmpty(); @@ -374,6 +381,8 @@ class gGraphView int strings_drawn_this_frame; int strings_cached_this_frame; + QList history; + protected: //! \brief The heart of the drawing code @@ -464,7 +473,7 @@ class gGraphView qint64 m_minx, m_maxx; - QList history; + QList fwd_history; float print_scaleX, print_scaleY; QPixmap previous_day_snapshot; diff --git a/sleepyhead/Graphs/glcommon.h b/sleepyhead/Graphs/glcommon.h index 49522075..476fbdb4 100644 --- a/sleepyhead/Graphs/glcommon.h +++ b/sleepyhead/Graphs/glcommon.h @@ -56,6 +56,8 @@ const QColor COLOR_ALT_BG2 = COLOR_White; // Alternating Background Color 2 (Event Flags) +const int max_history = 50; + #ifndef M_PI const double M_PI = 3.141592653589793; #endif