This file is indexed.

/usr/share/qt5/doc/qtwebkitexamples/qtwebkitexamples-webkitwidgets-scroller-wheel-example.html is in qtwebkit5-examples-doc-html 5.5.1+dfsg-2build1.

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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- wheel.qdoc -->
  <title>Wheel Scroller Example | Qt WebKit Examples 5.5</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.5</li>
<li><a href="qtwebkitexamples-index.html">Qt WebKit Examples</a></li>
<li>Wheel Scroller Example</li>
<li id="buildversion">Qt 5.5.1 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="#basics">Basics</a></li>
<li class="level1"><a href="#the-wheel-widget-class">The Wheel Widget class</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Wheel Scroller Example</h1>
<span class="subtitle"></span>
<!-- $$$webkitwidgets/scroller/wheel-description -->
<div class="descr"> <a name="details"></a>
<p>The Wheel Scroller Example shows how to use <a href="../qtwidgets/qscroller.html">QScroller</a>, <a href="../qtgui/qscrollevent.html">QScrollEvent</a> and <a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a> to implement smooth scrolling for a custom Widget.</p>
<p class="centerAlign"><img src="images/wheel-example.png" alt="" /></p><a name="basics"></a>
<h2 id="basics">Basics</h2>
<p>The <a href="../qtwidgets/qscroller.html">QScroller</a> class is the main part of the smooth scrolling mechanism in Qt. It keeps track of the current scroll position and speed and updates the object through events. <a href="../qtwidgets/qscroller.html">QScroller</a> will get touch events via the QFlickGesture. It will query the target object through a <a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a> for the scroll area and other information. <a href="../qtwidgets/qscroller.html">QScroller</a> will send QScrollEvents to inform the target object about the current scroll position. The target object (usually a <a href="../qtwidgets/qwidget.html">QWidget</a> or a <a href="../qtwidgets/qgraphicsobject.html">QGraphicsObject</a>) will then need to update it's graphical representation to reflect the new scroll position.</p>
<a name="the-wheel-widget-class"></a>
<h2 id="the-wheel-widget-class">The Wheel Widget class</h2>
<p>To demonstrate how to use the <a href="../qtwidgets/qscroller.html">QScroller</a> we implement a <a href="../qtwidgets/qwidget.html">QWidget</a> that looks and works like the wheel of a slot machine. The wheel can be started via touch events and will continue getting slower. Additionally the wheel should appear as if no border exists (which would seem unnatural) and the scrolling should snap to center one item.</p>
<p>In the widget we need to grab the QFlickGesture. The gesture itself will setAcceptTouchEvents for us, so we don't need to do that here.</p>
<pre class="cpp">    <span class="type"><a href="../qtwidgets/qscroller.html">QScroller</a></span><span class="operator">::</span>grabGesture(<span class="keyword">this</span><span class="operator">,</span> touch <span class="operator">?</span> <span class="type"><a href="../qtwidgets/qscroller.html">QScroller</a></span><span class="operator">::</span>TouchGesture : <span class="type"><a href="../qtwidgets/qscroller.html">QScroller</a></span><span class="operator">::</span>LeftMouseButtonGesture);</pre>
<p>The widget will get gesture events but in addition we also will get the events from <a href="../qtwidgets/qscroller.html">QScroller</a>. We will need to accept the <a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a> to indicate that a scrolling should really be started from the given position.</p>
<pre class="cpp">    <span class="keyword">case</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>ScrollPrepare:
    {
        <span class="comment">// We set the snap positions as late as possible so that we are sure</span>
        <span class="comment">// we get the correct itemHeight</span>
        <span class="type"><a href="../qtwidgets/qscroller.html">QScroller</a></span> <span class="operator">*</span>scroller <span class="operator">=</span> <span class="type"><a href="../qtwidgets/qscroller.html">QScroller</a></span><span class="operator">::</span>scroller(<span class="keyword">this</span>);
        scroller<span class="operator">-</span><span class="operator">&gt;</span>setSnapPositionsY( WHEEL_SCROLL_OFFSET<span class="operator">,</span> itemHeight() );

        <span class="type"><a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a></span> <span class="operator">*</span>se <span class="operator">=</span> <span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type"><a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(e);
        se<span class="operator">-</span><span class="operator">&gt;</span>setViewportSize(<span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span>(size()));
        <span class="comment">// we claim a huge scrolling area and a huge content position and</span>
        <span class="comment">// hope that the user doesn't notice that the scroll area is restricted</span>
        se<span class="operator">-</span><span class="operator">&gt;</span>setContentPosRange(<span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="number">0.0</span><span class="operator">,</span> <span class="number">0.0</span><span class="operator">,</span> <span class="number">0.0</span><span class="operator">,</span> WHEEL_SCROLL_OFFSET <span class="operator">*</span> <span class="number">2</span>));
        se<span class="operator">-</span><span class="operator">&gt;</span>setContentPos(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="number">0.0</span><span class="operator">,</span> WHEEL_SCROLL_OFFSET <span class="operator">+</span> m_currentItem <span class="operator">*</span> itemHeight() <span class="operator">+</span> m_itemOffset));
        se<span class="operator">-</span><span class="operator">&gt;</span>accept();
        <span class="keyword">return</span> <span class="keyword">true</span>;
    }</pre>
<p>We should call all three set functions form <a href="../qtgui/qscrollprepareevent.html">QScrollPrepareEvent</a>.</p>
<ul>
<li><code>setViewportSize</code> to indicate our viewport size. Actually the given code could be improved by giving our size minus the borders.</li>
<li><code>setMaxContentPos</code> to indicate the maximum values for the scroll position. The minimum values are implicitely set to 0. In our example we give a very high number here and hope that the user is not patient enough to scroll until the very end.</li>
<li><code>setContentPos</code> to indicate the current scroll position. We give a position in the middle of the huge scroll area. Actually we give this position every time a new scroll is started so the user will only reach the end if he continuously scrolls in one direction which is not very likely.</li>
</ul>
<p>The handling of the <a href="../qtgui/qscrollevent.html">QScrollEvent</a> is a lengthly code not fully shown here.</p>
<pre class="cpp">    <span class="keyword">case</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>Scroll:
    {
        <span class="type"><a href="../qtgui/qscrollevent.html">QScrollEvent</a></span> <span class="operator">*</span>se <span class="operator">=</span> <span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type"><a href="../qtgui/qscrollevent.html">QScrollEvent</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(e);

        <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> y <span class="operator">=</span> se<span class="operator">-</span><span class="operator">&gt;</span>contentPos()<span class="operator">.</span>y();
        <span class="type">int</span> iy <span class="operator">=</span> y <span class="operator">-</span> WHEEL_SCROLL_OFFSET;
        <span class="type">int</span> ih <span class="operator">=</span> itemHeight();</pre>
<p>In principle it does three steps.</p>
<ul>
<li>It calculates and updates the current scroll position as given by <a href="../qtwidgets/qscroller.html">QScroller</a>.</li>
<li>It repaints the widget so that the new position is shown.</li>
<li>It centers the item as soon as the scrolling stopps.</li>
</ul>
<p>The following code does the centering.</p>
<pre class="cpp">        <span class="comment">// -- calculate the current item position and offset and redraw the widget</span>
        <span class="type">int</span> ic <span class="operator">=</span> itemCount();
        <span class="keyword">if</span> (ic<span class="operator">&gt;</span><span class="number">0</span>) {
            m_currentItem <span class="operator">=</span> iy <span class="operator">/</span> ih <span class="operator">%</span> ic;
            m_itemOffset <span class="operator">=</span> iy <span class="operator">%</span> ih;

            <span class="comment">// take care when scrolling backwards. Modulo returns negative numbers</span>
            <span class="keyword">if</span> (m_itemOffset <span class="operator">&lt;</span> <span class="number">0</span>) {
                m_itemOffset <span class="operator">+</span><span class="operator">=</span> ih;
                m_currentItem<span class="operator">-</span><span class="operator">-</span>;
            }

            <span class="keyword">if</span> (m_currentItem <span class="operator">&lt;</span> <span class="number">0</span>)
                m_currentItem <span class="operator">+</span><span class="operator">=</span> ic;
        }
        <span class="comment">// -- repaint</span>
        update();

        se<span class="operator">-</span><span class="operator">&gt;</span>accept();
        <span class="keyword">return</span> <span class="keyword">true</span>;</pre>
<p>We check if the scrolling is finished which is indicated in the <a href="../qtgui/qscrollevent.html">QScrollEvent</a> by the <code>isLast</code> flag. We then check if the item is not already centered and if not start a new scroll by calling <a href="../qtwidgets/qscroller.html#scrollTo">QScroller::scrollTo</a>.</p>
<p>As you can see the <a href="../qtwidgets/qscroller.html">QScroller</a> can be used for other things besides simple scroll areas.</p>
<p>Files:</p>
<ul>
<li><a href="qtwebkitexamples-webkitwidgets-scroller-wheel-wheelwidget-cpp.html">webkitwidgets/scroller/wheel/wheelwidget.cpp</a></li>
<li><a href="qtwebkitexamples-webkitwidgets-scroller-wheel-wheelwidget-h.html">webkitwidgets/scroller/wheel/wheelwidget.h</a></li>
<li><a href="qtwebkitexamples-webkitwidgets-scroller-wheel-main-cpp.html">webkitwidgets/scroller/wheel/main.cpp</a></li>
<li><a href="qtwebkitexamples-webkitwidgets-scroller-wheel-wheel-pro.html">webkitwidgets/scroller/wheel/wheel.pro</a></li>
</ul>
</div>
<!-- @@@webkitwidgets/scroller/wheel -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 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>