Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 845e36bb3ecce380666d628d88446962 > files > 280

qtdatavis3d5-doc-5.12.6-1.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" />
<!-- qmlcustominput.qdoc -->
  <title>Qt Quick 2 Custom Input Example | Qt Data Visualization 5.12.6</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="qtdatavisualization-index.html">Qt Data Visualization</a></td><td >Qt Quick 2 Custom Input Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdatavisualization-index.html">Qt Data Visualization | Commercial or GPLv3</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#removing-default-input-handling">Removing Default Input Handling</a></li>
<li class="level1"><a href="#implementing-custom-selection-handling">Implementing Custom Selection Handling</a></li>
<li class="level1"><a href="#implementing-custom-zoom-handling">Implementing Custom Zoom Handling</a></li>
<li class="level1"><a href="#implementing-custom-camera-handling">Implementing Custom Camera Handling</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick 2 Custom Input Example</h1>
<span class="subtitle"></span>
<!-- $$$qmlcustominput-brief -->
<p>Customizing input in a QML application.</p>
<!-- @@@qmlcustominput -->
<!-- $$$qmlcustominput-description -->
<div class="descr"> <a name="details"></a>
<p>The Qt Quick 2 Custom Input example shows how to customize the 3D graph controls from Qt Quick 2 using the MouseArea to capture and process mouse events in QML. Custom input handling code in this example shows how the camera is now controlled by using NumberAnimation to animate the camera and item selection is done on mouseover rather than clicking any mouse buttons. Also the code shows how to implement similar zoom with mouse wheel functionality as the default input handler implements.</p>
<p class="centerAlign"><img src="images/qmlcustominput-example.png" alt="" /></p><a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="removing-default-input-handling"></a>
<h2 id="removing-default-input-handling">Removing Default Input Handling</h2>
<p>The default input handling mechanism is disabled by setting the inputHandler property to null.</p>
<pre class="qml">

  Scatter3D {
  ...
  inputHandler: null
  ...

</pre>
<a name="implementing-custom-selection-handling"></a>
<h2 id="implementing-custom-selection-handling">Implementing Custom Selection Handling</h2>
<p>The on mouseover selection handling is implemented using standard MouseArea to capture the mouse events. The mouse area is configured to capture hover events and has two custom properties for <code>mouseX</code> and <code>mouseY</code> to store the last known mouse coordinates.</p>
<pre class="qml">

  MouseArea {
      id: inputArea
      anchors.fill: parent
      hoverEnabled: true
      acceptedButtons: Qt.LeftButton | Qt.RightButton
      property int mouseX: -1
      property int mouseY: -1

</pre>
<p>Whenever a pointer movement related signal is received the code updates the <code>mouseX</code> and <code>mouseY</code> properties.</p>
<pre class="qml">

  onPositionChanged: {
      mouseX = mouse.x;
      mouseY = mouse.y;
  }

</pre>
<p>As the selection is one shot, and is cleared each time a 3D frame is rendered, a timer is setup to retrigger selection so that the selection moves to the item currently under the mouse cursor as the camera animates around the graph even when the mouse cursor is not moving.</p>
<pre class="qml">

  Timer {
      id: reselectTimer
      interval: 10
      running: true
      repeat: true
      onTriggered: {
          scatterGraph.scene.selectionQueryPosition = Qt.point(inputArea.mouseX, inputArea.mouseY);
      }
  }

</pre>
<a name="implementing-custom-zoom-handling"></a>
<h2 id="implementing-custom-zoom-handling">Implementing Custom Zoom Handling</h2>
<p>The camera has a zoom factor that represents amount of zoom in percentages. In this example the zoom range is limited between 10% and 500%. This range is then divided to four subranges where angleDelta is scaled to different amount of zoom change based on the current subrange.</p>
<pre class="cpp">

      ...
  onWheel: {
      // Adjust zoom level based on what zoom range we're in.
      var zoomLevel = scatterGraph.scene.activeCamera.zoomLevel;
      if (zoomLevel > 100)
          zoomLevel += wheel.angleDelta.y / 12.0;
      else if (zoomLevel > 50)
          zoomLevel += wheel.angleDelta.y / 60.0;
      else
          zoomLevel += wheel.angleDelta.y / 120.0;
      if (zoomLevel > 500)
          zoomLevel = 500;
      else if (zoomLevel < 10)
          zoomLevel = 10;

      scatterGraph.scene.activeCamera.zoomLevel = zoomLevel;
  }
      ...

</pre>
<a name="implementing-custom-camera-handling"></a>
<h2 id="implementing-custom-camera-handling">Implementing Custom Camera Handling</h2>
<p>The camera is animated to constantly rotate around the graph with two animations. The rotation around the graph is done with a simple NumberAnimation that just increments during 20 seconds from 0 degrees to 360 degrees and sets the <a href="q3dcamera.html#xRotation-prop">Q3DCamera::xRotation</a> property.</p>
<pre class="qml">

  NumberAnimation {
      id: cameraAnimationX
      loops: Animation.Infinite
      running: true
      target: scatterGraph.scene.activeCamera
      property:"xRotation"
      from: 0.0
      to: 360.0
      duration: 20000
  }

</pre>
<p>The camera movement up and down is implemented with a SequentialAnimation that varies the <a href="q3dcamera.html#yRotation-prop">Q3DCamera::yRotation</a> property of the camera from 5 degrees to 45 degrees and back with in and out easing.</p>
<pre class="qml">

  SequentialAnimation {
      id: cameraAnimationY
      loops: Animation.Infinite
      running: true

      NumberAnimation {
          target: scatterGraph.scene.activeCamera
          property:"yRotation"
          from: 5.0
          to: 45.0
          duration: 9000
          easing.type: Easing.InOutSine
      }

      NumberAnimation {
          target: scatterGraph.scene.activeCamera
          property:"yRotation"
          from: 45.0
          to: 5.0
          duration: 9000
          easing.type: Easing.InOutSine
      }
  }

</pre>
<p>Files:</p>
<ul>
<li><a href="qtdatavisualization-qmlcustominput-main-cpp.html">qmlcustominput/main.cpp</a></li>
<li><a href="qtdatavisualization-qmlcustominput-qml-qmlcustominput-data-qml.html">qmlcustominput/qml/qmlcustominput/Data.qml</a></li>
<li><a href="qtdatavisualization-qmlcustominput-qml-qmlcustominput-newbutton-qml.html">qmlcustominput/qml/qmlcustominput/NewButton.qml</a></li>
<li><a href="qtdatavisualization-qmlcustominput-qml-qmlcustominput-main-qml.html">qmlcustominput/qml/qmlcustominput/main.qml</a></li>
<li><a href="qtdatavisualization-qmlcustominput-qmlcustominput-pro.html">qmlcustominput/qmlcustominput.pro</a></li>
<li><a href="qtdatavisualization-qmlcustominput-qmlcustominput-qrc.html">qmlcustominput/qmlcustominput.qrc</a></li>
</ul>
</div>
<!-- @@@qmlcustominput -->
        </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>