This file is indexed.

/usr/share/qt5/doc/qtquick/qtquick-demos-clocks-example.html is in qtdeclarative5-doc-html 5.5.1-2ubuntu6.

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- clocks.qdoc -->
  <title>Qt Quick Demo - Clocks | Qt Quick 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="qtquick-index.html">Qt Quick</a></li>
<li>Qt Quick Demo - Clocks</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="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#displaying-data-generated-by-list-models">Displaying Data Generated by List Models</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Demo - Clocks</h1>
<span class="subtitle"></span>
<!-- $$$demos/clocks-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/qtquick-demo-clocks-small.png" alt="" /></p><p><i>Clocks</i> demonstrates using a <a href="qml-qtquick-listview.html">ListView</a> type to display data generated by a <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a>. The delegate used by the model is specified as a custom QML type that is specified in the Clock.qml file.</p>
<p>JavaScript methods are used to fetch the current time in several cities in different time zones and QML types are used to display the time on a clock face with animated clock hands.</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="displaying-data-generated-by-list-models"></a>
<h2 id="displaying-data-generated-by-list-models">Displaying Data Generated by List Models</h2>
<p>In the clocks.qml file, we use a <a href="qml-qtquick-rectangle.html">Rectangle</a> type to create the application main window:</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
    <span class="name">id</span>: <span class="name">root</span>
    <span class="name">width</span>: <span class="number">640</span>; <span class="name">height</span>: <span class="number">320</span>
    <span class="name">color</span>: <span class="string">&quot;#646464&quot;</span></pre>
<p>We use a <a href="qml-qtquick-listview.html">ListView</a> type to display a list of the items provided by a <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a> type:</p>
<pre class="qml">    <span class="type"><a href="qml-qtquick-listview.html">ListView</a></span> {
        <span class="name">id</span>: <span class="name">clockview</span>
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">orientation</span>: <span class="name">ListView</span>.<span class="name">Horizontal</span>
        <span class="name">cacheBuffer</span>: <span class="number">2000</span>
        <span class="name">snapMode</span>: <span class="name">ListView</span>.<span class="name">SnapOneItem</span>
        <span class="name">highlightRangeMode</span>: <span class="name">ListView</span>.<span class="name">ApplyRange</span>

        <span class="name">delegate</span>: <span class="name">Content</span>.Clock { <span class="name">city</span>: <span class="name">cityName</span>; <span class="name">shift</span>: <span class="name">timeShift</span> }
        <span class="name">model</span>: <span class="name">ListModel</span> {
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;New York&quot;</span>; <span class="name">timeShift</span>: -<span class="number">4</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;London&quot;</span>; <span class="name">timeShift</span>: <span class="number">0</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;Oslo&quot;</span>; <span class="name">timeShift</span>: <span class="number">1</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;Mumbai&quot;</span>; <span class="name">timeShift</span>: <span class="number">5.5</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;Tokyo&quot;</span>; <span class="name">timeShift</span>: <span class="number">9</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;Brisbane&quot;</span>; <span class="name">timeShift</span>: <span class="number">10</span> }
            <span class="type">ListElement</span> { <span class="name">cityName</span>: <span class="string">&quot;Los Angeles&quot;</span>; <span class="name">timeShift</span>: -<span class="number">8</span> }
        }
    }</pre>
<p>List elements are defined like other QML types except that they contain a collection of <i>role</i> definitions instead of properties. Roles both define how the data is accessed and include the data itself.</p>
<p>For each list element, we use the <code>cityName</code> role to specify the name of a city and the <code>timeShift</code> role to specify a time zone as a positive or negative offset from UTC (coordinated universal time).</p>
<p>The Clock custom type is used as the <a href="qml-qtquick-listview.html">ListView</a>'s <code>delegate</code>, defining the visual appearance of list items. To use the Clock type, we add an import statement that imports the folder called <code>content</code> where the type is located:</p>
<pre class="qml">import &quot;content&quot; as Content</pre>
<p>We use an <a href="qtquick-imageelements-example.html#image">Image</a> type to display arrows that indicate whether users can flick the view to see more clocks on the left or right:</p>
<pre class="qml">    <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
        <span class="name">anchors</span>.left: <span class="name">parent</span>.<span class="name">left</span>
        <span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
        <span class="name">anchors</span>.margins: <span class="number">10</span>
        <span class="name">source</span>: <span class="string">&quot;content/arrow.png&quot;</span>
        <span class="name">rotation</span>: -<span class="number">90</span>
        <span class="name">opacity</span>: <span class="name">clockview</span>.<span class="name">atXBeginning</span> ? <span class="number">0</span> : <span class="number">0.5</span>
        Behavior on <span class="name">opacity</span> { <span class="type"><a href="qml-qtquick-numberanimation.html">NumberAnimation</a></span> { <span class="name">duration</span>: <span class="number">500</span> } }
    }

    <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
        <span class="name">anchors</span>.right: <span class="name">parent</span>.<span class="name">right</span>
        <span class="name">anchors</span>.bottom: <span class="name">parent</span>.<span class="name">bottom</span>
        <span class="name">anchors</span>.margins: <span class="number">10</span>
        <span class="name">source</span>: <span class="string">&quot;content/arrow.png&quot;</span>
        <span class="name">rotation</span>: <span class="number">90</span>
        <span class="name">opacity</span>: <span class="name">clockview</span>.<span class="name">atXEnd</span> ? <span class="number">0</span> : <span class="number">0.5</span>
        Behavior on <span class="name">opacity</span> { <span class="type"><a href="qml-qtquick-numberanimation.html">NumberAnimation</a></span> { <span class="name">duration</span>: <span class="number">500</span> } }
    }
}</pre>
<p>We use the <code>opacity</code> property to hide the arrows when the list view is located at the beginning or end of the x axis.</p>
<p>In Clock.qml, we define a <code>timeChanged()</code> function in which we use methods from the JavaScript <code>Date</code> object to fetch the current time in UTC and to adjust it to the correct time zone:</p>
<pre class="qml">    <span class="keyword">function</span> <span class="name">timeChanged</span>() {
        var <span class="name">date</span> = new <span class="name">Date</span>;
        <span class="name">hours</span> <span class="operator">=</span> <span class="name">internationalTime</span> ? <span class="name">date</span>.<span class="name">getUTCHours</span>() <span class="operator">+</span> <span class="name">Math</span>.<span class="name">floor</span>(<span class="name">clock</span>.<span class="name">shift</span>) : <span class="name">date</span>.<span class="name">getHours</span>()
        <span class="name">night</span> <span class="operator">=</span> ( <span class="name">hours</span> <span class="operator">&lt;</span> <span class="number">7</span> <span class="operator">||</span> <span class="name">hours</span> <span class="operator">&gt;</span> <span class="number">19</span> )
        <span class="name">minutes</span> <span class="operator">=</span> <span class="name">internationalTime</span> ? <span class="name">date</span>.<span class="name">getUTCMinutes</span>() <span class="operator">+</span> ((<span class="name">clock</span>.<span class="name">shift</span> <span class="operator">%</span> <span class="number">1</span>) <span class="operator">*</span> <span class="number">60</span>) : <span class="name">date</span>.<span class="name">getMinutes</span>()
        <span class="name">seconds</span> <span class="operator">=</span> <span class="name">date</span>.<span class="name">getUTCSeconds</span>();
    }</pre>
<p>We use a Timer type to update the time at intervals of 100 milliseconds:</p>
<pre class="qml">    <span class="type">Timer</span> {
        <span class="name">interval</span>: <span class="number">100</span>; <span class="name">running</span>: <span class="number">true</span>; <span class="name">repeat</span>: <span class="number">true</span>;
        <span class="name">onTriggered</span>: <span class="name">clock</span>.<span class="name">timeChanged</span>()
    }</pre>
<p>We use <a href="qtquick-imageelements-example.html#image">Image</a> types within an <a href="qml-qtquick-item.html">Item</a> type to display the time on an analog clock face. Different images are used for daytime and nighttime hours:</p>
<pre class="qml">    <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
        <span class="name">anchors</span>.centerIn: <span class="name">parent</span>
        <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">240</span>

        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> { <span class="name">id</span>: <span class="name">background</span>; <span class="name">source</span>: <span class="string">&quot;clock.png&quot;</span>; <span class="name">visible</span>: <span class="name">clock</span>.<span class="name">night</span> <span class="operator">==</span> <span class="number">false</span> }
        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> { <span class="name">source</span>: <span class="string">&quot;clock-night.png&quot;</span>; <span class="name">visible</span>: <span class="name">clock</span>.<span class="name">night</span> <span class="operator">==</span> <span class="number">true</span> }</pre>
<p>A <a href="qml-qtquick-rotation.html">Rotation</a> transform applied to <a href="qtquick-imageelements-example.html#image">Image</a> types provides a way to rotate the clock hands. The <code>origin</code> property holds the point that stays fixed relative to the parent as the rest of the item rotates. The <code>angle</code> property determines the angle to rotate the hands in degrees clockwise.</p>
<pre class="qml">        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
            <span class="name">x</span>: <span class="number">92.5</span>; <span class="name">y</span>: <span class="number">27</span>
            <span class="name">source</span>: <span class="string">&quot;hour.png&quot;</span>
            <span class="name">transform</span>: <span class="name">Rotation</span> {
                <span class="name">id</span>: <span class="name">hourRotation</span>
                <span class="name">origin</span>.x: <span class="number">7.5</span>; <span class="name">origin</span>.y: <span class="number">73</span>;
                <span class="name">angle</span>: (<span class="name">clock</span>.<span class="name">hours</span> <span class="operator">*</span> <span class="number">30</span>) <span class="operator">+</span> (<span class="name">clock</span>.<span class="name">minutes</span> <span class="operator">*</span> <span class="number">0.5</span>)
                Behavior on <span class="name">angle</span> {
                    <span class="type"><a href="qml-qtquick-springanimation.html">SpringAnimation</a></span> { <span class="name">spring</span>: <span class="number">2</span>; <span class="name">damping</span>: <span class="number">0.2</span>; <span class="name">modulus</span>: <span class="number">360</span> }
                }
            }
        }

        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
            <span class="name">x</span>: <span class="number">93.5</span>; <span class="name">y</span>: <span class="number">17</span>
            <span class="name">source</span>: <span class="string">&quot;minute.png&quot;</span>
            <span class="name">transform</span>: <span class="name">Rotation</span> {
                <span class="name">id</span>: <span class="name">minuteRotation</span>
                <span class="name">origin</span>.x: <span class="number">6.5</span>; <span class="name">origin</span>.y: <span class="number">83</span>;
                <span class="name">angle</span>: <span class="name">clock</span>.<span class="name">minutes</span> <span class="operator">*</span> <span class="number">6</span>
                Behavior on <span class="name">angle</span> {
                    <span class="type"><a href="qml-qtquick-springanimation.html">SpringAnimation</a></span> { <span class="name">spring</span>: <span class="number">2</span>; <span class="name">damping</span>: <span class="number">0.2</span>; <span class="name">modulus</span>: <span class="number">360</span> }
                }
            }
        }

        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
            <span class="name">x</span>: <span class="number">97.5</span>; <span class="name">y</span>: <span class="number">20</span>
            <span class="name">source</span>: <span class="string">&quot;second.png&quot;</span>
            <span class="name">transform</span>: <span class="name">Rotation</span> {
                <span class="name">id</span>: <span class="name">secondRotation</span>
                <span class="name">origin</span>.x: <span class="number">2.5</span>; <span class="name">origin</span>.y: <span class="number">80</span>;
                <span class="name">angle</span>: <span class="name">clock</span>.<span class="name">seconds</span> <span class="operator">*</span> <span class="number">6</span>
                Behavior on <span class="name">angle</span> {
                    <span class="type"><a href="qml-qtquick-springanimation.html">SpringAnimation</a></span> { <span class="name">spring</span>: <span class="number">2</span>; <span class="name">damping</span>: <span class="number">0.2</span>; <span class="name">modulus</span>: <span class="number">360</span> }
                }
            }
        }

        <span class="type"><a href="qml-qtquick-image.html">Image</a></span> {
            <span class="name">anchors</span>.centerIn: <span class="name">background</span>; <span class="name">source</span>: <span class="string">&quot;center.png&quot;</span>
        }</pre>
<p>We use a <a href="qml-qtquick-behavior.html">Behavior</a> type on the <code>angle</code> property to apply a <a href="qml-qtquick-springanimation.html">SpringAnimation</a> when the time changes. The <code>spring</code> and <code>damping</code> properties enable the spring-like motion of the clock hands, and a <code>modulus</code> of <code>360</code> makes the animation target values wrap around at a full circle.</p>
<p>We use a <a href="qml-qtquick-text.html">Text</a> type to display the city name below the clock:</p>
<pre class="qml">        <span class="type"><a href="qml-qtquick-text.html">Text</a></span> {
            <span class="name">id</span>: <span class="name">cityLabel</span>
            <span class="name">y</span>: <span class="number">210</span>; <span class="name">anchors</span>.horizontalCenter: <span class="name">parent</span>.<span class="name">horizontalCenter</span>
            <span class="name">color</span>: <span class="string">&quot;white&quot;</span>
            <span class="name">font</span>.family: <span class="string">&quot;Helvetica&quot;</span>
            <span class="name">font</span>.bold: <span class="number">true</span>; <span class="name">font</span>.pixelSize: <span class="number">16</span>
            <span class="name">style</span>: <span class="name">Text</span>.<span class="name">Raised</span>; <span class="name">styleColor</span>: <span class="string">&quot;black&quot;</span>
        }</pre>
<p>Files:</p>
<ul>
<li><a href="qtquick-demos-clocks-clocks-qml.html">demos/clocks/clocks.qml</a></li>
<li><a href="qtquick-demos-clocks-content-clock-qml.html">demos/clocks/content/Clock.qml</a></li>
<li><a href="qtquick-demos-clocks-main-cpp.html">demos/clocks/main.cpp</a></li>
<li><a href="qtquick-demos-clocks-clocks-pro.html">demos/clocks/clocks.pro</a></li>
<li><a href="qtquick-demos-clocks-clocks-qmlproject.html">demos/clocks/clocks.qmlproject</a></li>
<li><a href="qtquick-demos-clocks-clocks-qrc.html">demos/clocks/clocks.qrc</a></li>
</ul>
</div>
<p><b>See also </b>QML Applications.</p>
<!-- @@@demos/clocks -->
        </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>