Skip to content

Commit 939f3f2

Browse files
committed
import code snippets about qml
0 parents  commit 939f3f2

File tree

151 files changed

+5668
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+5668
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# C++ objects and libs
2+
3+
*.slo
4+
*.lo
5+
*.o
6+
*.a
7+
*.la
8+
*.lai
9+
*.so
10+
*.dll
11+
*.dylib
12+
13+
# Qt-es
14+
15+
/.qmake.cache
16+
/.qmake.stash
17+
*.pro.user
18+
*.pro.user.*
19+
*.qbs.user
20+
*.qbs.user.*
21+
*.moc
22+
moc_*.cpp
23+
qrc_*.cpp
24+
ui_*.h
25+
Makefile*
26+
*-build-*
27+
28+
# QtCreator
29+
30+
*.autosave
31+
32+
#QtCtreator Qml
33+
*.qmlproject.user
34+
*.qmlproject.user.*

button/button.qml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import QtQuick 2.2
2+
3+
Rectangle {
4+
color: "#A8C7D9"
5+
width: button.width + 30
6+
height: button.height + 20
7+
Button {
8+
id: button
9+
anchors.centerIn: parent
10+
}
11+
}

button/components/Icon.qml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import QtQuick 2.2
2+
3+
Canvas {
4+
id: icon
5+
6+
property bool highlighted
7+
property color color: highlighted ? secondaryColor : buttonColor
8+
property int numberOfPoints: 5
9+
onColorChanged: requestPaint()
10+
onPaint: {
11+
var numberOfPoints = 5
12+
var radius = width/2
13+
var ctx = getContext('2d')
14+
ctx.save();
15+
ctx.beginPath()
16+
ctx.fillStyle = icon.color
17+
ctx.clearRect(0, 0, width, height)
18+
ctx.translate(width/2, height/2)
19+
ctx.moveTo(0,0-radius);
20+
for (var i = 0; i < numberOfPoints; i++)
21+
{
22+
ctx.rotate(Math.PI / numberOfPoints)
23+
ctx.lineTo(0, 0 - (radius*0.45))
24+
ctx.rotate(Math.PI / numberOfPoints)
25+
ctx.lineTo(0, 0 - radius)
26+
}
27+
ctx.fill()
28+
ctx.restore()
29+
}
30+
}

codesnippets-joona.pro

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
TEMPLATE = aux
2+
3+
PROJECTS = button colorstrips fallingcubes scripts horizontalflow \
4+
layoutgrid layouts livepixels navigation \
5+
overlappingletters scalability splash timepicker \
6+
trees view views
7+
8+
message($${PROJECTS})
9+
OTHER_FILES += *.qml *.js
10+
for (PROJECT, PROJECTS) {
11+
OTHER_FILES += $${PROJECT}/*.qml \
12+
$${PROJECT}/*.js \
13+
$${PROJECT}/components/*.qml \
14+
$${PROJECT}/components/*.js
15+
}

codesnippets-joona.qmlproject

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* File generated by QtCreator */
2+
3+
import QmlProject 1.0
4+
5+
Project {
6+
/* Include .qml, .js, and image files from current directory and subdirectories */
7+
QmlFiles {
8+
directory: "."
9+
}
10+
JavaScriptFiles {
11+
directory: "."
12+
}
13+
ImageFiles {
14+
directory: "."
15+
}
16+
/* List of plugin directories passed to QML runtime */
17+
// importPaths: [ " ../exampleplugin " ]
18+
}

colorstrips/ColorColumn.qml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import QtQuick 1.0
2+
3+
Column {
4+
width: 800; height: 400
5+
property real pixelsPerRelativeHeight
6+
function rectangleColor() {
7+
var value = Math.random()
8+
var red = value < 0.4 ? 0.8+0.2*Math.random() : 0.1+0.4*Math.random()
9+
var green = value > 0.4 && value < 0.8 ? 0.7+0.3*Math.random() : 0.4+0.3*Math.random()
10+
var blue = value > 0.8 ? 0.6+0.2*Math.random() : 0.2*Math.random()
11+
return Qt.rgba(red, green, blue)
12+
}
13+
Component.onCompleted: {
14+
var totalRelativeHeight = 0
15+
for (var index = 0; index < children.length; index++) {
16+
if (children[index] !== repeater)
17+
totalRelativeHeight += children[index].relativeHeight
18+
}
19+
pixelsPerRelativeHeight = height/totalRelativeHeight
20+
}
21+
Repeater {
22+
id: repeater
23+
model: 40
24+
Rectangle {
25+
width: parent.width
26+
color: rectangleColor()
27+
height: Math.ceil(relativeHeight*pixelsPerRelativeHeight)
28+
property real value: Math.random()
29+
property real relativeHeight: Math.pow(Math.random(),3)
30+
}
31+
}
32+
}

colorstrips/ColorRow.qml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import QtQuick 1.0
2+
3+
Row {
4+
width: 800; height: 400
5+
property real pixelsPerRelativeWidth
6+
function rectangleColor() {
7+
var isRed = Math.random() < 0.1
8+
var grayness = 0.2+0.6*Math.random()
9+
var red = isRed ? grayness+0.6*Math.random()*(1-grayness) : grayness
10+
var green = isRed ? 0.5*grayness+0.5*Math.random()*grayness : 1.3*grayness
11+
var blue = isRed ? 0.8*grayness+0.4*Math.random()*grayness : 1.3*grayness
12+
return Qt.rgba(red, green, blue)
13+
}
14+
Component.onCompleted: {
15+
var totalRelativeWidth = 0
16+
for (var index = 0; index < children.length; index++) {
17+
if (children[index] !== repeater)
18+
totalRelativeWidth += children[index].relativeWidth
19+
}
20+
pixelsPerRelativeWidth = width/totalRelativeWidth
21+
}
22+
Repeater {
23+
id: repeater
24+
model: 80
25+
Rectangle {
26+
height: parent.height
27+
color: rectangleColor()
28+
width: Math.ceil(relativeWidth*pixelsPerRelativeWidth)
29+
property real relativeWidth: Math.pow(Math.random(),3)
30+
}
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import QtQuick 1.0
2+
3+
Column {
4+
width: 800; height: 400
5+
property real pixelsPerRelativeHeight
6+
Component.onCompleted: {
7+
var totalRelativeHeight = 0
8+
for (var index = 0; index < children.length; index++) {
9+
if (children[index] !== repeater)
10+
totalRelativeHeight += children[index].relativeHeight
11+
}
12+
pixelsPerRelativeHeight = height/totalRelativeHeight
13+
}
14+
Repeater {
15+
id: repeater
16+
model: 40
17+
ColorRow {
18+
width: parent.width
19+
height: Math.ceil(relativeHeight*pixelsPerRelativeHeight)
20+
property real relativeHeight: Math.pow(Math.random(),3)
21+
function rectangleColor() {
22+
var isBlue = Math.random() < 0.2
23+
var grayness = 0.2+0.6*Math.random()
24+
var red = isBlue ? 0.5*grayness+0.5*Math.random()*grayness : grayness
25+
var green = isBlue ? grayness+0.6*Math.random()*(1-grayness) : 1.3*grayness
26+
var blue = isBlue ? 0.7*grayness+0.3*Math.random()*grayness : 1.3*grayness
27+
return Qt.rgba(red, green, blue)
28+
}
29+
}
30+
}
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import QtQuick 1.0
2+
3+
Row {
4+
width: 800; height: 400
5+
property real pixelPerRelativeWidth
6+
Component.onCompleted: {
7+
var totalRelativeWidth = 0
8+
for (var index = 0; index < children.length; index++) {
9+
if (children[index] !== repeater)
10+
totalRelativeWidth += children[index].relativeWidth
11+
}
12+
pixelPerRelativeWidth = width/totalRelativeWidth
13+
}
14+
Repeater {
15+
id: repeater
16+
model: 50
17+
ColorColumn {
18+
height: parent.height
19+
width: Math.ceil(relativeWidth*pixelPerRelativeWidth)
20+
property real relativeWidth: Math.pow(Math.random(),3)
21+
function rectangleColor() {
22+
var value = Math.random()
23+
var blue = value < 0.4 ? 0.8+0.2*Math.random() : 0.1+0.4*Math.random()
24+
var red = value > 0.4 && value < 0.8 ? 0.7+0.3*Math.random() : 0.4+0.3*Math.random()
25+
var green = value > 0.8 ? 0.2+0.2*Math.random() : 0.2*Math.random()
26+
return Qt.rgba(red, green, blue)
27+
}
28+
}
29+
}
30+
}

fallingcubes/FallingCube.qml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Qt3D 2.0
2+
import QtQuick 2.0
3+
import Qt3D.Shapes 2.0
4+
5+
Item3D {
6+
id: fallingCube
7+
property color coolColor
8+
function reset() {
9+
yBehavior.enabled = false;
10+
fallingCube.y = 25
11+
yBehavior.enabled = true;
12+
fallingCube.x = 40*Math.random();
13+
fallingCube.y = -15
14+
}
15+
Component.onCompleted: y = -15
16+
x: 40*Math.random(); y: 30*Math.random()-10; z: 20*(Math.random()-0.5)
17+
Behavior on x { SmoothedAnimation { velocity: 2*Math.random() } }
18+
Behavior on y {
19+
id: yBehavior
20+
SmoothedAnimation { velocity: 6+Math.random()*6 }
21+
}
22+
Timer {
23+
interval: 100; repeat: true; running: true
24+
onTriggered: if (fallingCube.y < -9) fallingCube.reset()
25+
}
26+
Cube {
27+
scale: 2
28+
effect: GoochShading {
29+
coolColor: fallingCube.coolColor
30+
warmColor: Qt.rgba(0.9 + 0.1*Math.random(),
31+
0.2 + 0.2*Math.random(),
32+
0.2*Math.random())
33+
}
34+
transform: Rotation3D {
35+
axis: Qt.vector3d(Math.random(), Math.random(), Math.random())
36+
SequentialAnimation on angle {
37+
id: angleAnimation
38+
property real offset: 360*Math.random()
39+
property real duration: 3000+3000*Math.random()
40+
running: true; loops: Animation.Infinite
41+
NumberAnimation {
42+
from: angleAnimation.offset; to: 360
43+
duration: (360-angleAnimation.offset)*angleAnimation.duration/360
44+
}
45+
NumberAnimation {
46+
from: 0; to: angleAnimation.offset
47+
duration: angleAnimation.offset*angleAnimation.duration/360
48+
}
49+
}
50+
}
51+
}
52+
}

fallingcubes/GoochShading.qml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Qt3D 2.0
2+
import QtQuick 2.0
3+
4+
ShaderProgram {
5+
property color warmColor
6+
property color coolColor
7+
vertexShader: "
8+
attribute highp vec4 qt_Vertex;
9+
attribute highp vec3 qt_Normal;
10+
11+
uniform lowp vec4 warmColor;
12+
uniform lowp vec4 coolColor;
13+
14+
uniform highp mat3 qt_NormalMatrix;
15+
uniform highp mat4 qt_ModelViewProjectionMatrix;
16+
uniform highp mat4 qt_ModelViewMatrix;
17+
18+
varying float facingProjector;
19+
20+
struct qt_SingleLightParameters {
21+
mediump vec4 position;
22+
mediump vec3 spotDirection;
23+
mediump float spotExponent;
24+
mediump float spotCutoff;
25+
mediump float spotCosCutoff;
26+
mediump float constantAttenuation;
27+
mediump float linearAttenuation;
28+
mediump float quadraticAttenuation;
29+
};
30+
uniform qt_SingleLightParameters qt_Light;
31+
32+
void main(void)
33+
{
34+
highp vec4 vertex = qt_ModelViewMatrix * qt_Vertex;
35+
highp vec3 normal = normalize(qt_NormalMatrix * qt_Normal);
36+
highp vec3 light = normalize(qt_Light.position.xyz - vertex.xyz);
37+
facingProjector = clamp(dot(normal, light), 0.0, 1.0);
38+
gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
39+
}
40+
"
41+
fragmentShader: "
42+
uniform lowp vec4 warmColor;
43+
uniform lowp vec4 coolColor;
44+
45+
varying float facingProjector;
46+
47+
void main(void)
48+
{
49+
highp float ratio = 0.5 * (facingProjector + 1.0);
50+
gl_FragColor = mix(warmColor, coolColor, ratio);
51+
}
52+
"
53+
}

fallingcubes/fallingcubes.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
TEMPLATE = app
2+
QT += widgets
3+
QT += quick
4+
TARGET = fallingcubes
5+
SOURCES += main.cpp
6+
CONFIG += qt3dquick

0 commit comments

Comments
 (0)