Skip to content

Commit

Permalink
Fixed qmllint warnings for code samples of chapter 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
eunoia-cl committed Oct 16, 2021
1 parent 262b11e commit b92afd8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 56 deletions.
23 changes: 2 additions & 21 deletions docs/ch10-effects/particle-painters.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,11 @@ Until now we have only used the image based particle painter to visualize partic

The ItemParticle can be used to emit QML items as particles. For this, you need to specify your own delegate to the particle.

```qml
ItemParticle {
id: particle
system: particleSystem
delegate: itemDelegate
}
```
<<< @/docs/ch10-effects/src/particles/itemparticle.qml#M2

Our delegate, in this case, is a random image (using *Math.random()*), visualized with a white border and a random size.

```qml
Component {
id: itemDelegate
Item {
id: container
width: 32*Math.ceil(Math.random()*3); height: width
Image {
anchors.fill: parent
anchors.margins: 4
source: 'assets/'+images[Math.floor(Math.random()*9)]
}
}
}
```
<<< @/docs/ch10-effects/src/particles/itemparticle.qml#M3

We emit 4 images per second with a lifespan of 4 seconds each. The particles fade automatically in and out.

Expand Down
75 changes: 40 additions & 35 deletions docs/ch10-effects/src/particles/itemparticle.qml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
/*
* Copyright (c) 2013, Juergen Bocklage-Ryannel, Johan Thelin
* All rights reserved.
*
* 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 editors 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 "AS IS" 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 <COPYRIGHT HOLDER> 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.
*/
Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin
All rights reserved.
import QtQuick 2.5
import QtQuick.Particles 2.0
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holder 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 "AS IS" 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 HOLDER 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.
*/

import QtQuick
import QtQuick.Particles

Rectangle {
id: root
Expand All @@ -46,7 +49,7 @@ Rectangle {

]

// M1>>
// #region M1
ParticleSystem {
id: particleSystem
}
Expand All @@ -59,29 +62,31 @@ Rectangle {
emitRate: 4
lifeSpan: 2000
}
// <<M1
// #endregion M1


// M2>>
// #region M2
ItemParticle {
id: particle
system: particleSystem
delegate: itemDelegate
}
// <<M2
// #endregion M2

// M3>>
// #region M3
Component {
id: itemDelegate

Item {
id: container
width: 32*Math.ceil(Math.random()*3); height: width
width: 32 * Math.ceil(Math.random() * 3)
height: width
Image {
anchors.fill: parent
anchors.margins: 4
source: 'assets/'+images[Math.floor(Math.random()*9)]
source: 'assets/' + root.images[Math.floor(Math.random() * 9)]
}
}
}
// <<M3
// #endregion M3
}

0 comments on commit b92afd8

Please sign in to comment.