Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 2394

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>glwidget.cpp Example File | Qt OpenGL</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtopengl-index.html">Qt OpenGL</a></td><td ><a href="qtopengl-hellogl2-example.html">Hello GL2 Example</a></td><td >glwidget.cpp Example File</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtopengl-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">glwidget.cpp Example File</h1>
<span class="subtitle">hellogl2/glwidget.cpp</span>
<!-- $$$hellogl2/glwidget.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;glwidget.h&quot;</span>
  <span class="preprocessor">#include &lt;QMouseEvent&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLShaderProgram&gt;</span>
  <span class="preprocessor">#include &lt;QCoreApplication&gt;</span>
  <span class="preprocessor">#include &lt;math.h&gt;</span>

  bool GLWidget<span class="operator">::</span>m_transparent <span class="operator">=</span> <span class="keyword">false</span>;

  GLWidget<span class="operator">::</span>GLWidget(<span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="../qtwidgets/qopenglwidget.html">QOpenGLWidget</a></span>(parent)<span class="operator">,</span>
        m_xRot(<span class="number">0</span>)<span class="operator">,</span>
        m_yRot(<span class="number">0</span>)<span class="operator">,</span>
        m_zRot(<span class="number">0</span>)<span class="operator">,</span>
        m_program(<span class="number">0</span>)
  {
      m_core <span class="operator">=</span> <span class="type"><a href="../qtgui/qsurfaceformat.html">QSurfaceFormat</a></span><span class="operator">::</span>defaultFormat()<span class="operator">.</span>profile() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtgui/qsurfaceformat.html">QSurfaceFormat</a></span><span class="operator">::</span>CoreProfile;
      <span class="comment">// --transparent causes the clear color to be transparent. Therefore, on systems that</span>
      <span class="comment">// support it, the widget will become transparent apart from the logo.</span>
      <span class="keyword">if</span> (m_transparent) {
          <span class="type"><a href="../qtgui/qsurfaceformat.html">QSurfaceFormat</a></span> fmt <span class="operator">=</span> format();
          fmt<span class="operator">.</span>setAlphaBufferSize(<span class="number">8</span>);
          setFormat(fmt);
      }
  }

  GLWidget<span class="operator">::</span><span class="operator">~</span>GLWidget()
  {
      cleanup();
  }

  <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> GLWidget<span class="operator">::</span>minimumSizeHint() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(<span class="number">50</span><span class="operator">,</span> <span class="number">50</span>);
  }

  <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> GLWidget<span class="operator">::</span>sizeHint() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(<span class="number">400</span><span class="operator">,</span> <span class="number">400</span>);
  }

  <span class="keyword">static</span> <span class="type">void</span> qNormalizeAngle(<span class="type">int</span> <span class="operator">&amp;</span>angle)
  {
      <span class="keyword">while</span> (angle <span class="operator">&lt;</span> <span class="number">0</span>)
          angle <span class="operator">+</span><span class="operator">=</span> <span class="number">360</span> <span class="operator">*</span> <span class="number">16</span>;
      <span class="keyword">while</span> (angle <span class="operator">&gt;</span> <span class="number">360</span> <span class="operator">*</span> <span class="number">16</span>)
          angle <span class="operator">-</span><span class="operator">=</span> <span class="number">360</span> <span class="operator">*</span> <span class="number">16</span>;
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>setXRotation(<span class="type">int</span> angle)
  {
      qNormalizeAngle(angle);
      <span class="keyword">if</span> (angle <span class="operator">!</span><span class="operator">=</span> m_xRot) {
          m_xRot <span class="operator">=</span> angle;
          <span class="keyword">emit</span> xRotationChanged(angle);
          update();
      }
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>setYRotation(<span class="type">int</span> angle)
  {
      qNormalizeAngle(angle);
      <span class="keyword">if</span> (angle <span class="operator">!</span><span class="operator">=</span> m_yRot) {
          m_yRot <span class="operator">=</span> angle;
          <span class="keyword">emit</span> yRotationChanged(angle);
          update();
      }
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>setZRotation(<span class="type">int</span> angle)
  {
      qNormalizeAngle(angle);
      <span class="keyword">if</span> (angle <span class="operator">!</span><span class="operator">=</span> m_zRot) {
          m_zRot <span class="operator">=</span> angle;
          <span class="keyword">emit</span> zRotationChanged(angle);
          update();
      }
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>cleanup()
  {
      <span class="keyword">if</span> (m_program <span class="operator">=</span><span class="operator">=</span> nullptr)
          <span class="keyword">return</span>;
      makeCurrent();
      m_logoVbo<span class="operator">.</span>destroy();
      <span class="keyword">delete</span> m_program;
      m_program <span class="operator">=</span> <span class="number">0</span>;
      doneCurrent();
  }

  <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>vertexShaderSourceCore <span class="operator">=</span>
      <span class="string">&quot;#version 150\n&quot;</span>
      <span class="string">&quot;in vec4 vertex;\n&quot;</span>
      <span class="string">&quot;in vec3 normal;\n&quot;</span>
      <span class="string">&quot;out vec3 vert;\n&quot;</span>
      <span class="string">&quot;out vec3 vertNormal;\n&quot;</span>
      <span class="string">&quot;uniform mat4 projMatrix;\n&quot;</span>
      <span class="string">&quot;uniform mat4 mvMatrix;\n&quot;</span>
      <span class="string">&quot;uniform mat3 normalMatrix;\n&quot;</span>
      <span class="string">&quot;void main() {\n&quot;</span>
      <span class="string">&quot;   vert = vertex.xyz;\n&quot;</span>
      <span class="string">&quot;   vertNormal = normalMatrix * normal;\n&quot;</span>
      <span class="string">&quot;   gl_Position = projMatrix * mvMatrix * vertex;\n&quot;</span>
      <span class="string">&quot;}\n&quot;</span>;

  <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>fragmentShaderSourceCore <span class="operator">=</span>
      <span class="string">&quot;#version 150\n&quot;</span>
      <span class="string">&quot;in highp vec3 vert;\n&quot;</span>
      <span class="string">&quot;in highp vec3 vertNormal;\n&quot;</span>
      <span class="string">&quot;out highp vec4 fragColor;\n&quot;</span>
      <span class="string">&quot;uniform highp vec3 lightPos;\n&quot;</span>
      <span class="string">&quot;void main() {\n&quot;</span>
      <span class="string">&quot;   highp vec3 L = normalize(lightPos - vert);\n&quot;</span>
      <span class="string">&quot;   highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n&quot;</span>
      <span class="string">&quot;   highp vec3 color = vec3(0.39, 1.0, 0.0);\n&quot;</span>
      <span class="string">&quot;   highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n&quot;</span>
      <span class="string">&quot;   fragColor = vec4(col, 1.0);\n&quot;</span>
      <span class="string">&quot;}\n&quot;</span>;

  <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>vertexShaderSource <span class="operator">=</span>
      <span class="string">&quot;attribute vec4 vertex;\n&quot;</span>
      <span class="string">&quot;attribute vec3 normal;\n&quot;</span>
      <span class="string">&quot;varying vec3 vert;\n&quot;</span>
      <span class="string">&quot;varying vec3 vertNormal;\n&quot;</span>
      <span class="string">&quot;uniform mat4 projMatrix;\n&quot;</span>
      <span class="string">&quot;uniform mat4 mvMatrix;\n&quot;</span>
      <span class="string">&quot;uniform mat3 normalMatrix;\n&quot;</span>
      <span class="string">&quot;void main() {\n&quot;</span>
      <span class="string">&quot;   vert = vertex.xyz;\n&quot;</span>
      <span class="string">&quot;   vertNormal = normalMatrix * normal;\n&quot;</span>
      <span class="string">&quot;   gl_Position = projMatrix * mvMatrix * vertex;\n&quot;</span>
      <span class="string">&quot;}\n&quot;</span>;

  <span class="keyword">static</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>fragmentShaderSource <span class="operator">=</span>
      <span class="string">&quot;varying highp vec3 vert;\n&quot;</span>
      <span class="string">&quot;varying highp vec3 vertNormal;\n&quot;</span>
      <span class="string">&quot;uniform highp vec3 lightPos;\n&quot;</span>
      <span class="string">&quot;void main() {\n&quot;</span>
      <span class="string">&quot;   highp vec3 L = normalize(lightPos - vert);\n&quot;</span>
      <span class="string">&quot;   highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n&quot;</span>
      <span class="string">&quot;   highp vec3 color = vec3(0.39, 1.0, 0.0);\n&quot;</span>
      <span class="string">&quot;   highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n&quot;</span>
      <span class="string">&quot;   gl_FragColor = vec4(col, 1.0);\n&quot;</span>
      <span class="string">&quot;}\n&quot;</span>;

  <span class="type">void</span> GLWidget<span class="operator">::</span>initializeGL()
  {
      <span class="comment">// In this example the widget's corresponding top-level window can change</span>
      <span class="comment">// several times during the widget's lifetime. Whenever this happens, the</span>
      <span class="comment">// QOpenGLWidget's associated context is destroyed and a new one is created.</span>
      <span class="comment">// Therefore we have to be prepared to clean up the resources on the</span>
      <span class="comment">// aboutToBeDestroyed() signal, instead of the destructor. The emission of</span>
      <span class="comment">// the signal will be followed by an invocation of initializeGL() where we</span>
      <span class="comment">// can recreate all resources.</span>
      connect(context()<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="../qtgui/qopenglcontext.html">QOpenGLContext</a></span><span class="operator">::</span>aboutToBeDestroyed<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>GLWidget<span class="operator">::</span>cleanup);

      initializeOpenGLFunctions();
      glClearColor(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> m_transparent <span class="operator">?</span> <span class="number">0</span> : <span class="number">1</span>);

      m_program <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtgui/qopenglshaderprogram.html">QOpenGLShaderProgram</a></span>;
      m_program<span class="operator">-</span><span class="operator">&gt;</span>addShaderFromSourceCode(<span class="type"><a href="../qtgui/qopenglshader.html">QOpenGLShader</a></span><span class="operator">::</span>Vertex<span class="operator">,</span> m_core <span class="operator">?</span> vertexShaderSourceCore : vertexShaderSource);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>addShaderFromSourceCode(<span class="type"><a href="../qtgui/qopenglshader.html">QOpenGLShader</a></span><span class="operator">::</span>Fragment<span class="operator">,</span> m_core <span class="operator">?</span> fragmentShaderSourceCore : fragmentShaderSource);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>bindAttributeLocation(<span class="string">&quot;vertex&quot;</span><span class="operator">,</span> <span class="number">0</span>);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>bindAttributeLocation(<span class="string">&quot;normal&quot;</span><span class="operator">,</span> <span class="number">1</span>);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>link();

      m_program<span class="operator">-</span><span class="operator">&gt;</span>bind();
      m_projMatrixLoc <span class="operator">=</span> m_program<span class="operator">-</span><span class="operator">&gt;</span>uniformLocation(<span class="string">&quot;projMatrix&quot;</span>);
      m_mvMatrixLoc <span class="operator">=</span> m_program<span class="operator">-</span><span class="operator">&gt;</span>uniformLocation(<span class="string">&quot;mvMatrix&quot;</span>);
      m_normalMatrixLoc <span class="operator">=</span> m_program<span class="operator">-</span><span class="operator">&gt;</span>uniformLocation(<span class="string">&quot;normalMatrix&quot;</span>);
      m_lightPosLoc <span class="operator">=</span> m_program<span class="operator">-</span><span class="operator">&gt;</span>uniformLocation(<span class="string">&quot;lightPos&quot;</span>);

      <span class="comment">// Create a vertex array object. In OpenGL ES 2.0 and OpenGL 2.x</span>
      <span class="comment">// implementations this is optional and support may not be present</span>
      <span class="comment">// at all. Nonetheless the below code works in all cases and makes</span>
      <span class="comment">// sure there is a VAO when one is needed.</span>
      m_vao<span class="operator">.</span>create();
      <span class="type"><a href="../qtgui/qopenglvertexarrayobject.html">QOpenGLVertexArrayObject</a></span><span class="operator">::</span>Binder vaoBinder(<span class="operator">&amp;</span>m_vao);

      <span class="comment">// Setup our vertex buffer object.</span>
      m_logoVbo<span class="operator">.</span>create();
      m_logoVbo<span class="operator">.</span>bind();
      m_logoVbo<span class="operator">.</span>allocate(m_logo<span class="operator">.</span>constData()<span class="operator">,</span> m_logo<span class="operator">.</span>count() <span class="operator">*</span> <span class="keyword">sizeof</span>(GLfloat));

      <span class="comment">// Store the vertex attribute bindings for the program.</span>
      setupVertexAttribs();

      <span class="comment">// Our camera never changes in this example.</span>
      m_camera<span class="operator">.</span>setToIdentity();
      m_camera<span class="operator">.</span>translate(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="operator">-</span><span class="number">1</span>);

      <span class="comment">// Light position is fixed.</span>
      m_program<span class="operator">-</span><span class="operator">&gt;</span>setUniformValue(m_lightPosLoc<span class="operator">,</span> QVector3D(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">70</span>));

      m_program<span class="operator">-</span><span class="operator">&gt;</span>release();
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>setupVertexAttribs()
  {
      m_logoVbo<span class="operator">.</span>bind();
      <span class="type"><a href="../qtgui/qopenglfunctions.html">QOpenGLFunctions</a></span> <span class="operator">*</span>f <span class="operator">=</span> <span class="type"><a href="../qtgui/qopenglcontext.html">QOpenGLContext</a></span><span class="operator">::</span>currentContext()<span class="operator">-</span><span class="operator">&gt;</span>functions();
      f<span class="operator">-</span><span class="operator">&gt;</span>glEnableVertexAttribArray(<span class="number">0</span>);
      f<span class="operator">-</span><span class="operator">&gt;</span>glEnableVertexAttribArray(<span class="number">1</span>);
      f<span class="operator">-</span><span class="operator">&gt;</span>glVertexAttribPointer(<span class="number">0</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> GL_FLOAT<span class="operator">,</span> GL_FALSE<span class="operator">,</span> <span class="number">6</span> <span class="operator">*</span> <span class="keyword">sizeof</span>(GLfloat)<span class="operator">,</span> <span class="number">0</span>);
      f<span class="operator">-</span><span class="operator">&gt;</span>glVertexAttribPointer(<span class="number">1</span><span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> GL_FLOAT<span class="operator">,</span> GL_FALSE<span class="operator">,</span> <span class="number">6</span> <span class="operator">*</span> <span class="keyword">sizeof</span>(GLfloat)<span class="operator">,</span> <span class="keyword">reinterpret_cast</span><span class="operator">&lt;</span><span class="type">void</span> <span class="operator">*</span><span class="operator">&gt;</span>(<span class="number">3</span> <span class="operator">*</span> <span class="keyword">sizeof</span>(GLfloat)));
      m_logoVbo<span class="operator">.</span>release();
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>paintGL()
  {
      glClear(GL_COLOR_BUFFER_BIT <span class="operator">|</span> GL_DEPTH_BUFFER_BIT);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);

      m_world<span class="operator">.</span>setToIdentity();
      m_world<span class="operator">.</span>rotate(<span class="number">180.0f</span> <span class="operator">-</span> (m_xRot <span class="operator">/</span> <span class="number">16.0f</span>)<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      m_world<span class="operator">.</span>rotate(m_yRot <span class="operator">/</span> <span class="number">16.0f</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      m_world<span class="operator">.</span>rotate(m_zRot <span class="operator">/</span> <span class="number">16.0f</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);

      <span class="type"><a href="../qtgui/qopenglvertexarrayobject.html">QOpenGLVertexArrayObject</a></span><span class="operator">::</span>Binder vaoBinder(<span class="operator">&amp;</span>m_vao);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>bind();
      m_program<span class="operator">-</span><span class="operator">&gt;</span>setUniformValue(m_projMatrixLoc<span class="operator">,</span> m_proj);
      m_program<span class="operator">-</span><span class="operator">&gt;</span>setUniformValue(m_mvMatrixLoc<span class="operator">,</span> m_camera <span class="operator">*</span> m_world);
      QMatrix3x3 normalMatrix <span class="operator">=</span> m_world<span class="operator">.</span>normalMatrix();
      m_program<span class="operator">-</span><span class="operator">&gt;</span>setUniformValue(m_normalMatrixLoc<span class="operator">,</span> normalMatrix);

      glDrawArrays(GL_TRIANGLES<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> m_logo<span class="operator">.</span>vertexCount());

      m_program<span class="operator">-</span><span class="operator">&gt;</span>release();
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>resizeGL(<span class="type">int</span> w<span class="operator">,</span> <span class="type">int</span> h)
  {
      m_proj<span class="operator">.</span>setToIdentity();
      m_proj<span class="operator">.</span>perspective(<span class="number">45.0f</span><span class="operator">,</span> GLfloat(w) <span class="operator">/</span> h<span class="operator">,</span> <span class="number">0.01f</span><span class="operator">,</span> <span class="number">100.0f</span>);
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event)
  {
      m_lastPos <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>pos();
  }

  <span class="type">void</span> GLWidget<span class="operator">::</span>mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type">int</span> dx <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>x() <span class="operator">-</span> m_lastPos<span class="operator">.</span>x();
      <span class="type">int</span> dy <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>y() <span class="operator">-</span> m_lastPos<span class="operator">.</span>y();

      <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">&gt;</span>buttons() <span class="operator">&amp;</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>LeftButton) {
          setXRotation(m_xRot <span class="operator">+</span> <span class="number">8</span> <span class="operator">*</span> dy);
          setYRotation(m_yRot <span class="operator">+</span> <span class="number">8</span> <span class="operator">*</span> dx);
      } <span class="keyword">else</span> <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">&gt;</span>buttons() <span class="operator">&amp;</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>RightButton) {
          setXRotation(m_xRot <span class="operator">+</span> <span class="number">8</span> <span class="operator">*</span> dy);
          setZRotation(m_zRot <span class="operator">+</span> <span class="number">8</span> <span class="operator">*</span> dx);
      }
      m_lastPos <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>pos();
  }

</pre>
</div>
<!-- @@@hellogl2/glwidget.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>