-
Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathmain.qml
175 lines (162 loc) · 5.6 KB
/
main.qml
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
import QtQuick 2.12
import QtQuick.Window 2.12
import Gt.Component 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Learn QSG")
//这个背景色设计感觉比较巧妙,所以从twotextureproviders示例拿出来了
ShaderEffect {
id: bg
anchors.fill: parent
property real tileSize: 16
property color color1: Qt.rgba(0.9, 0.9, 0.9, 1);
property color color2: Qt.rgba(0.8, 0.8, 0.8, 1);
property size pixelSize: Qt.size(width / tileSize, height / tileSize);
//vec2:pixelSize为画布尺寸和方格大小tileSize的比例,
// 后面再拿纹理坐标0-1乘上它就相当保持宽高比例的放大,
// width/tileSize=7表示显示7列格子,一个格子titleSize宽,
// coord*7则原本一个像素现在就是7倍,范围[0-1]变为[0-7]
//sin(vec2)的值域,vec=0-PI为正,PI-2PI为负,循环
// coord*7则sin的值会循环正负正负3.5次
//sign(x),x>0:y=1,x<0:y=-1,x=0:y=0
// 这样就把sin的数值变为了1,-1,0便于比较
// 这样横向循环正负1,竖向循环正负1就形成了一个棋盘
fragmentShader:
"
uniform lowp vec4 color1;
uniform lowp vec4 color2;
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
gl_FragColor = color2;
}
"
}
Column{
x: 10
y: 10
spacing: 10
Row{
spacing: 10
//点击文字切换item或者更新颜色
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
Text{
id: txt
font.pixelSize: 40
text: "Hello"
layer.enabled: true
}
MouseArea{
anchors.fill: parent
onClicked: {
txt.color = Qt.hsla(Math.random(),0.5,0.5,1);
texture.source = txt;
}
}
}
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
Text{
id: txt2
font.pixelSize: 40
text: "QSG"
layer.enabled: true
}
MouseArea{
anchors.fill: parent
onClicked: {
txt2.color = Qt.hsla(Math.random(),0.5,0.5,1);
texture.source = txt2;
}
}
}
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
MyTextureItem{
id: texture
width: source.width
height: source.height
source: txt
}
}
}//end Row
Row{
spacing: 10
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
Item {
id: box
width: 100
height: 50
Rectangle {
anchors.centerIn: parent
width: parent.width * 0.9
height: parent.width * 0.4
radius: width * 0.1;
gradient: Gradient {
GradientStop { position: 0; color: Qt.hsla(0.6, 0.9, 0.9, 1); }
GradientStop { position: 1; color: Qt.hsla(0.6, 0.6, 0.3, 1); }
}
//RotationAnimator on rotation { from: 0; to: 360; duration: 10000; loops: Animation.Infinite }
}
//visible: false
layer.enabled: true
}
}
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
Item {
id: text
width: box.width
height: box.height
Text {
anchors.centerIn: parent
color: "black" // Qt.hsla(0.8, 0.8, 0.8);
text: "Qt\nQuick"
horizontalAlignment: Text.AlignHCenter
font.bold: true
font.pixelSize: text.width * 0.25
//RotationAnimator on rotation { from: 360; to: 0; duration: 9000; loops: Animation.Infinite }
}
//visible: false
layer.enabled: true
}
}
Rectangle{
width: 100
height: 50
color: "transparent"
border.color: "red"
MyBlenderItem{
id: blender
width: box.width
height: box.height
source1: box
source2: text
}
}
}
}//end Column
}