Skip to content

Commit

Permalink
Make it possible to pause the animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Johan Sørvig committed Feb 13, 2018
1 parent 8f027d1 commit b9b5048
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gui_opengl/hellowindow.cpp
Expand Up @@ -47,6 +47,7 @@
HelloWindow::HelloWindow()
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate)
, m_colorIndex(0)
, m_animating(true)
{

QSurfaceFormat format;
Expand All @@ -63,6 +64,15 @@ void HelloWindow::mousePressEvent(QMouseEvent *)
updateColor();
}

void HelloWindow::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Space) {
m_animating = !m_animating;
if (m_animating)
requestUpdate();
}
}

void HelloWindow::updateColor()
{
QColor colors[] =
Expand Down Expand Up @@ -152,7 +162,8 @@ void HelloWindow::paintGL()

// qDebug() << "HelloWindow::render 3 start timer";

requestUpdate();
if (m_animating)
requestUpdate();
}

void HelloWindow::paintQtLogo()
Expand Down
2 changes: 2 additions & 0 deletions gui_opengl/hellowindow.h
Expand Up @@ -55,9 +55,11 @@ class HelloWindow : public QOpenGLWindow
void paintGL() override;

void mousePressEvent(QMouseEvent *) override;
void keyPressEvent(QKeyEvent* event) override;

int m_colorIndex;
QColor m_color;
bool m_animating;

void paintQtLogo();
void createGeometry();
Expand Down

0 comments on commit b9b5048

Please sign in to comment.