keyboard left/right control when graphs focused

This commit is contained in:
Mark Watkins 2011-07-16 00:27:37 +10:00
parent 3aac219aad
commit e72980de11
2 changed files with 27 additions and 0 deletions

View File

@ -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<gGraphWindow *>::iterator g=link_zoom.begin();g!=link_zoom.end();g++) {
(*g)->SetXBounds(min,max);
}
}
event->accept();
} else {
event->ignore();
}
}
void gGraphWindow::OnMouseRightDown(QMouseEvent * event)
{

View File

@ -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);