From e72980de11f6c65dfa80d6222308a3a8e4f38244 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sat, 16 Jul 2011 00:27:37 +1000 Subject: [PATCH] keyboard left/right control when graphs focused --- Graphs/graphwindow.cpp | 26 ++++++++++++++++++++++++++ Graphs/graphwindow.h | 1 + 2 files changed, 27 insertions(+) diff --git a/Graphs/graphwindow.cpp b/Graphs/graphwindow.cpp index c0d00577..0f77778a 100644 --- a/Graphs/graphwindow.cpp +++ b/Graphs/graphwindow.cpp @@ -32,6 +32,7 @@ gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLWidget * s } //setAcceptDrops(true); setMouseTracking(true); + setFocusPolicy(Qt::StrongFocus); } gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLContext * context,Qt::WindowFlags f) @@ -57,6 +58,7 @@ gGraphWindow::gGraphWindow(QWidget *parent, const QString & title, QGLContext * } //setAcceptDrops(true); setMouseTracking(true); + setFocusPolicy(Qt::StrongFocus); } gGraphWindow::~gGraphWindow() @@ -360,6 +362,30 @@ void gGraphWindow::mouseReleaseEvent(QMouseEvent * event) OnMouseRightRelease(event); } +void gGraphWindow::keyPressEvent(QKeyEvent * event) +{ + bool moved=false; + if (event->key()==Qt::Key_Left) { + MoveX(40); + moved=true; + } else if (event->key()==Qt::Key_Right) { + MoveX(-40); + moved=true; + } + + if (moved) { + double min=MinX(); + double max=MaxX(); + if (pref["LinkGraphMovement"].toBool()) { + for (list::iterator g=link_zoom.begin();g!=link_zoom.end();g++) { + (*g)->SetXBounds(min,max); + } + } + event->accept(); + } else { + event->ignore(); + } +} void gGraphWindow::OnMouseRightDown(QMouseEvent * event) { diff --git a/Graphs/graphwindow.h b/Graphs/graphwindow.h index f6288c8b..7b429b5b 100644 --- a/Graphs/graphwindow.h +++ b/Graphs/graphwindow.h @@ -44,6 +44,7 @@ public: virtual void mousePressEvent(QMouseEvent * event); virtual void mouseReleaseEvent(QMouseEvent * event); virtual void mouseDoubleClickEvent(QMouseEvent * event); + virtual void keyPressEvent(QKeyEvent * event); //virtual void OnMouseRightDClick(wxMouseEvent * event); virtual void OnMouseLeftDown(QMouseEvent * event); virtual void OnMouseLeftRelease (QMouseEvent * event);