/usr/share/qt5/doc/qtfeedback/qtfeedback-hapticsquare-example.html is in qtfeedback5-doc-html 5.0~git20130529-0ubuntu13.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- hapticsquare.qdoc -->
<title>Haptic Square Example | Qt 5.0 </title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.0</li>
<li>Haptic Square Example</li>
<li id="buildversion">Qt 5.0.0 Reference Documentation</li>
</ul>
</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="#overview">Overview</a></li>
<li class="level2"><a href="#use-case">Use Case</a></li>
<li class="level1"><a href="#the-application">The Application</a></li>
<li class="level2"><a href="#the-dialog-class">The Dialog Class</a></li>
<li class="level1"><a href="#known-issues">Known Issues</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Haptic Square Example</h1>
<span class="subtitle"></span>
<!-- $$$hapticsquare-description -->
<div class="descr"> <a name="details"></a>
<a name="overview"></a>
<h2 id="overview">Overview</h2>
<p>This example shows how to use simple haptic effects in an application via the Qt Feedback API.</p>
<p>It provides an example of how to use the Qt Feedback</p>
<ul>
<li>play "system theme" haptic effects corresponding to certain predefined events</li>
<li>play a custom effect, single or repeating</li>
</ul>
<a name="use-case"></a>
<h3 >Use Case</h3>
<p>Compelling applications attempt to immerse the user in the application experience. There are many elements to an immersive experience, including a consistent and beautiful graphical user interface design, unobtrusive yet informative sound design, and intuitive program flow. Another important aspect of immersive applications is tactile feedback and haptic effects.</p>
<p>The QtFeedback API allows application developers to include tactile feedback into their application via a simple to use and extensible API. Some common uses for tactile feedback are:</p>
<ul>
<li>maintain consistency with system theme for tactile feedback about interface events (button clicks, scrolling, etc)</li>
<li>notify the user of an application-specific event (invalid operation, status change, etc)</li>
<li>multisensory user interface (status can be "read" by touching the screen, tactile interfaces, etc)</li>
<li>immersive gaming experiences (explosions, impacts, collisions, etc)</li>
</ul>
<p>This example application provides some short snippets which illustrate how the first two of those use cases may be fulfilled.</p>
<a name="the-application"></a>
<h2 id="the-application">The Application</h2>
<p>The application is designed to work on desktop and mobile platforms with minimal differences in code between the platforms. The interface consists of four buttons arranged into a square, each of which causes a different tactile effect to be played by the default tactile effect provider plugin on the platform.</p>
<p class="centerAlign"><img src="images/hapticsquare-example.png" alt="" /></p><ul>
<li>"Rumble!" plays a non-repeating effect with symmetric attack and decay</li>
<li>"Ocean" is a toggle button which plays a repeating ocean wave-like effect</li>
<li>"Click" plays the system theme effect for a basic button click</li>
<li>"Oops!" plays the system theme effect for a negative or invalid response</li>
</ul>
<p>The example implements two classes:</p>
<ul>
<li><code>HapticButton</code>: Implementation of a button. It inherits QWidget and sends signals for button clicks.</li>
<li><code>Dialog</code>: A QDialog subclass that displays the four <code>HapticButton</code>s mentioned above, connects them to its slots, and implements the functionality to play the haptic effects.</li>
</ul>
<a name="the-dialog-class"></a>
<h3 >The Dialog Class</h3>
<p>We will now go through the code for the <code>Dialog</code> class. Here is its definition:</p>
<pre class="cpp"><span class="keyword">class</span> HapticSquare : <span class="keyword">public</span> <span class="type">QWidget</span>
{
Q_OBJECT
<span class="keyword">public</span>:
HapticSquare();
<span class="operator">~</span>HapticSquare();
<span class="keyword">private</span> Q_SLOTS:
<span class="type">void</span> playRumble();
<span class="type">void</span> playOcean();
<span class="type">void</span> playButtonClick();
<span class="type">void</span> playNegativeEffect();
<span class="keyword">private</span>:
HapticButton <span class="operator">*</span>m_btnRumble;
HapticButton <span class="operator">*</span>m_btnOcean;
HapticButton <span class="operator">*</span>m_btnButtonClick;
HapticButton <span class="operator">*</span>m_btnNegativeEffect;
<span class="type"><a href="qfeedbackhapticseffect.html">QFeedbackHapticsEffect</a></span> m_rumble;
<span class="type"><a href="qfeedbackhapticseffect.html">QFeedbackHapticsEffect</a></span> m_ocean;
};</pre>
<p>The buttons are connected to the slots, which play the effects. We will now go through the implementation of <code>Dialog</code>.</p>
<p>The constructor starts by setting up the non-repeating haptic effect, which is played by clicking the <b>Rumble! Button</b>.</p>
<pre class="cpp">HapticSquare<span class="operator">::</span>HapticSquare()
{
m_rumble<span class="operator">.</span>setAttackIntensity(<span class="number">0.1</span>);
m_rumble<span class="operator">.</span>setAttackTime(<span class="number">250</span>);
m_rumble<span class="operator">.</span>setIntensity(<span class="number">1.0</span>);
m_rumble<span class="operator">.</span>setDuration(<span class="number">1000</span>);
m_rumble<span class="operator">.</span>setFadeTime(<span class="number">250</span>);
m_rumble<span class="operator">.</span>setFadeIntensity(<span class="number">0.1</span>);</pre>
<p>Custom haptics effects are created by setting up a <a href="qfeedbackhapticseffect.html">QFeedbackHapticsEffect</a>.</p>
<p>A haptics effect provides a fade-in of the effect's <a href="qfeedbackhapticseffect.html#intensity-prop">intensity()</a>. With vibration, you can think of the intensity as how hard the device will vibrate. The effect will start at <a href="qfeedbackhapticseffect.html#attackIntensity-prop">attackIntensity()</a> and interpolate to <a href="qfeedbackhapticseffect.html#intensity-prop">intensity()</a> in <a href="qfeedbackhapticseffect.html#attackTime-prop">attackTime()</a> milliseconds. When the effect ends, we have a similar fade-out, where the haptics effect's intensity will interpolate from <a href="qfeedbackhapticseffect.html#intensity-prop">intensity()</a> to <a href="qfeedbackhapticseffect.html#fadeTime-prop">fadeTime()</a> in <a href="qfeedbackhapticseffect.html#fadeTime-prop">fadeTime()</a> milliseconds. The effect will last for a total duration of <a href="qfeedbackhapticseffect.html#duration-prop">duration()</a> milliseconds.</p>
<p>We next set up the effect for the <b>Ocean Button</b>.</p>
<pre class="cpp"> m_ocean<span class="operator">.</span>setAttackIntensity(<span class="number">0.1</span>);
m_ocean<span class="operator">.</span>setAttackTime(<span class="number">450</span>);
m_ocean<span class="operator">.</span>setIntensity(<span class="number">0.8</span>);
m_ocean<span class="operator">.</span>setDuration(<span class="number">6000</span>);
m_ocean<span class="operator">.</span>setFadeTime(<span class="number">900</span>);
m_ocean<span class="operator">.</span>setFadeIntensity(<span class="number">0.05</span>);
m_ocean<span class="operator">.</span>setPeriod(<span class="number">1500</span>);</pre>
<p>The <code>m_ocean</code> is a periodic effect, i.e., it repeats after <a href="qfeedbackhapticseffect.html#period-prop">period()</a> milliseconds. Note that the <a href="qfeedbackhapticseffect.html#duration-prop">duration()</a> must be greater than the period in order for the periodicity of the effect to be discernable.</p>
<p>We then set up the GUI and connects the buttons to slots that will play the effects.</p>
<pre class="cpp"> m_btnRumble <span class="operator">=</span> <span class="keyword">new</span> HapticButton(tr(<span class="string">"Rumble!"</span>));
m_btnOcean <span class="operator">=</span> <span class="keyword">new</span> HapticButton(tr(<span class="string">"Ocean"</span>));
m_btnButtonClick <span class="operator">=</span> <span class="keyword">new</span> HapticButton(tr(<span class="string">"Click"</span>));
m_btnNegativeEffect <span class="operator">=</span> <span class="keyword">new</span> HapticButton(tr(<span class="string">"Oops!"</span>));
<span class="type">QGridLayout</span> <span class="operator">*</span>topLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QGridLayout</span>(<span class="keyword">this</span>);
topLayout<span class="operator">-</span><span class="operator">></span>addWidget(m_btnRumble<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
topLayout<span class="operator">-</span><span class="operator">></span>addWidget(m_btnOcean<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
topLayout<span class="operator">-</span><span class="operator">></span>addWidget(m_btnButtonClick<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
topLayout<span class="operator">-</span><span class="operator">></span>addWidget(m_btnNegativeEffect<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
connect(m_btnRumble<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(playRumble()));
connect(m_btnOcean<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(playOcean()));
connect(m_btnButtonClick<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(playButtonClick()));
connect(m_btnNegativeEffect<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(playNegativeEffect()));
}</pre>
<p>Let's look at the slots to see how the effects are played.</p>
<pre class="cpp"><span class="type">void</span> HapticSquare<span class="operator">::</span>playRumble()
{
m_rumble<span class="operator">.</span>start();
}
<span class="type">void</span> HapticSquare<span class="operator">::</span>playOcean()
{
<span class="keyword">if</span> (m_ocean<span class="operator">.</span>state() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qfeedbackeffect.html">QFeedbackEffect</a></span><span class="operator">::</span>Stopped) {
m_ocean<span class="operator">.</span>start();
} <span class="keyword">else</span> {
m_ocean<span class="operator">.</span>stop();
}
}</pre>
<p>With the <code>m_rumble</code>, we only have to call <a href="qfeedbackeffect.html#start">start()</a>. It will stop when the effect has finished, and can be played again by calling <a href="qfeedbackeffect.html#start">start()</a> again.</p>
<p>The periodic <code>m_ocean</code> effect is started the same way as the <code>m_rumble</code> effect, and may be stopped with the <a href="qfeedbackeffect.html#stop">stop()</a> function. It will start playing from the beginning again when <a href="qfeedbackeffect.html#start">start()</a> is called. We could also have paused the effect with <a href="qfeedbackeffect.html#pause">pause()</a>.</p>
<pre class="cpp"><span class="type">void</span> HapticSquare<span class="operator">::</span>playButtonClick()
{
<span class="type"><a href="qfeedbackeffect.html">QFeedbackEffect</a></span><span class="operator">::</span>playThemeEffect(<span class="type"><a href="qfeedbackeffect.html">QFeedbackEffect</a></span><span class="operator">::</span>ThemeBasicButton);
}
<span class="type">void</span> HapticSquare<span class="operator">::</span>playNegativeEffect()
{
<span class="type"><a href="qfeedbackeffect.html">QFeedbackEffect</a></span><span class="operator">::</span>playThemeEffect(<span class="type"><a href="qfeedbackeffect.html">QFeedbackEffect</a></span><span class="operator">::</span>ThemeNegativeTacticon);
}</pre>
<p>System theme effects are played with the static <a href="qfeedbackeffect.html#playThemeEffect">QFeedbackEffect::playThemeEffect</a>() function. Theme effects cannot be stopped or paused. There is no guarantee that the backend can play the effect; <a href="qfeedbackeffect.html#playThemeEffect">playThemeEffect()</a> will return false if the effect could not be played.</p>
<a name="known-issues"></a>
<h2 id="known-issues">Known Issues</h2>
<p>The example is not intended to exercise the entire API. Instead, it is a simple example which illustrates some simple uses of the API. Also, the example will not work correctly on platforms which do not have a QFeedbackHapticInterface (haptic effect provider) plugin loaded. On such platforms, clicking the buttons will have no effect. On Maemo5, periodic effects do not support attack or fade, and so the ocean effect is not smooth.</p>
</div>
<!-- @@@hapticsquare -->
<div class="footer">Copyright (c) 2011 Nokia Corporation and/or its subsidiaries. All rights reserved.</div>
</body>
</html>
|