qtbindings 4.8.6.3-x86-mingw32 → 4.8.6.4-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/bin/2.4/rbrcc.exe +0 -0
- data/bin/2.4/rbuic4.exe +0 -0
- data/bin/2.4/smokeapi.exe +0 -0
- data/bin/2.4/smokedeptool.exe +0 -0
- data/examples/tutorial/t10/cannon.rb +72 -72
- data/examples/tutorial/t10/lcdrange.rb +45 -45
- data/examples/tutorial/t10/t10.rb +55 -55
- data/examples/tutorial/t11/cannon.rb +123 -124
- data/examples/tutorial/t11/lcdrange.rb +45 -45
- data/examples/tutorial/t11/t11.rb +65 -65
- data/examples/tutorial/t12/cannon.rb +157 -158
- data/examples/tutorial/t12/lcdrange.rb +58 -59
- data/examples/tutorial/t12/t12.rb +65 -66
- data/examples/tutorial/t13/cannon.rb +206 -208
- data/examples/tutorial/t13/gamebrd.rb +112 -113
- data/examples/tutorial/t13/lcdrange.rb +59 -60
- data/examples/tutorial/t13/t13.rb +11 -11
- data/examples/tutorial/t14/cannon.rb +262 -263
- data/examples/tutorial/t14/gamebrd.rb +122 -123
- data/examples/tutorial/t14/lcdrange.rb +61 -63
- data/examples/tutorial/t14/t14.rb +11 -11
- data/examples/tutorial/t3/t3.rb +17 -18
- data/examples/tutorial/t4/t4.rb +23 -25
- data/examples/tutorial/t5/t5.rb +35 -37
- data/examples/tutorial/t6/t6.rb +48 -52
- data/examples/tutorial/t7/lcdrange.rb +32 -32
- data/examples/tutorial/t7/t7.rb +40 -42
- data/examples/tutorial/t8/cannon.rb +37 -38
- data/examples/tutorial/t8/lcdrange.rb +45 -45
- data/examples/tutorial/t8/t8.rb +43 -43
- data/examples/tutorial/t9/cannon.rb +44 -45
- data/examples/tutorial/t9/lcdrange.rb +46 -46
- data/examples/tutorial/t9/t9.rb +43 -43
- data/lib/2.4/libqtruby4shared.dll +0 -0
- data/lib/2.4/libsmokebase.dll +0 -0
- data/lib/2.4/libsmokeqtcore.dll +0 -0
- data/lib/2.4/libsmokeqtdeclarative.dll +0 -0
- data/lib/{2.1 → 2.4}/libsmokeqtgui.dll +0 -0
- data/lib/2.4/libsmokeqthelp.dll +0 -0
- data/lib/2.4/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.4/libsmokeqtnetwork.dll +0 -0
- data/lib/2.4/libsmokeqtopengl.dll +0 -0
- data/lib/2.4/libsmokeqtscript.dll +0 -0
- data/lib/2.4/libsmokeqtsql.dll +0 -0
- data/lib/2.4/libsmokeqtsvg.dll +0 -0
- data/lib/2.4/libsmokeqttest.dll +0 -0
- data/lib/2.4/libsmokeqtuitools.dll +0 -0
- data/lib/2.4/libsmokeqtwebkit.dll +0 -0
- data/lib/2.4/libsmokeqtxml.dll +0 -0
- data/lib/2.4/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.4/qtdeclarative.so +0 -0
- data/lib/2.4/qtruby4.so +0 -0
- data/lib/2.4/qtscript.so +0 -0
- data/lib/2.4/qttest.so +0 -0
- data/lib/2.4/qtuitools.so +0 -0
- data/lib/2.4/qtwebkit.so +0 -0
- data/lib/Qt4.rb +119 -111
- data/lib/qtbindings_version.rb +2 -2
- data/qtbindings.gemspec +18 -18
- data/qtbindingsnative.gemspec +19 -19
- metadata +38 -115
- data/bin/2.0/rbrcc.exe +0 -0
- data/bin/2.0/rbuic4.exe +0 -0
- data/bin/2.0/smokeapi.exe +0 -0
- data/bin/2.0/smokedeptool.exe +0 -0
- data/bin/2.1/rbrcc.exe +0 -0
- data/bin/2.1/rbuic4.exe +0 -0
- data/bin/2.1/smokeapi.exe +0 -0
- data/bin/2.1/smokedeptool.exe +0 -0
- data/bin/2.2/rbrcc.exe +0 -0
- data/bin/2.2/rbuic4.exe +0 -0
- data/bin/2.2/smokeapi.exe +0 -0
- data/bin/2.2/smokedeptool.exe +0 -0
- data/bin/2.3/rbrcc.exe +0 -0
- data/bin/2.3/rbuic4.exe +0 -0
- data/bin/2.3/smokeapi.exe +0 -0
- data/bin/2.3/smokedeptool.exe +0 -0
- data/lib/2.0/libqtruby4shared.dll +0 -0
- data/lib/2.0/libsmokebase.dll +0 -0
- data/lib/2.0/libsmokeqtcore.dll +0 -0
- data/lib/2.0/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.0/libsmokeqtgui.dll +0 -0
- data/lib/2.0/libsmokeqthelp.dll +0 -0
- data/lib/2.0/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.0/libsmokeqtnetwork.dll +0 -0
- data/lib/2.0/libsmokeqtopengl.dll +0 -0
- data/lib/2.0/libsmokeqtscript.dll +0 -0
- data/lib/2.0/libsmokeqtsql.dll +0 -0
- data/lib/2.0/libsmokeqtsvg.dll +0 -0
- data/lib/2.0/libsmokeqttest.dll +0 -0
- data/lib/2.0/libsmokeqtuitools.dll +0 -0
- data/lib/2.0/libsmokeqtwebkit.dll +0 -0
- data/lib/2.0/libsmokeqtxml.dll +0 -0
- data/lib/2.0/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.0/qtdeclarative.so +0 -0
- data/lib/2.0/qtruby4.so +0 -0
- data/lib/2.0/qtscript.so +0 -0
- data/lib/2.0/qttest.so +0 -0
- data/lib/2.0/qtuitools.so +0 -0
- data/lib/2.0/qtwebkit.so +0 -0
- data/lib/2.1/libqtruby4shared.dll +0 -0
- data/lib/2.1/libsmokebase.dll +0 -0
- data/lib/2.1/libsmokeqtcore.dll +0 -0
- data/lib/2.1/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.1/libsmokeqthelp.dll +0 -0
- data/lib/2.1/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.1/libsmokeqtnetwork.dll +0 -0
- data/lib/2.1/libsmokeqtopengl.dll +0 -0
- data/lib/2.1/libsmokeqtscript.dll +0 -0
- data/lib/2.1/libsmokeqtsql.dll +0 -0
- data/lib/2.1/libsmokeqtsvg.dll +0 -0
- data/lib/2.1/libsmokeqttest.dll +0 -0
- data/lib/2.1/libsmokeqtuitools.dll +0 -0
- data/lib/2.1/libsmokeqtwebkit.dll +0 -0
- data/lib/2.1/libsmokeqtxml.dll +0 -0
- data/lib/2.1/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.1/qtdeclarative.so +0 -0
- data/lib/2.1/qtruby4.so +0 -0
- data/lib/2.1/qtscript.so +0 -0
- data/lib/2.1/qttest.so +0 -0
- data/lib/2.1/qtuitools.so +0 -0
- data/lib/2.1/qtwebkit.so +0 -0
- data/lib/2.2/libqtruby4shared.dll +0 -0
- data/lib/2.2/libsmokebase.dll +0 -0
- data/lib/2.2/libsmokeqtcore.dll +0 -0
- data/lib/2.2/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.2/libsmokeqtgui.dll +0 -0
- data/lib/2.2/libsmokeqthelp.dll +0 -0
- data/lib/2.2/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.2/libsmokeqtnetwork.dll +0 -0
- data/lib/2.2/libsmokeqtopengl.dll +0 -0
- data/lib/2.2/libsmokeqtscript.dll +0 -0
- data/lib/2.2/libsmokeqtsql.dll +0 -0
- data/lib/2.2/libsmokeqtsvg.dll +0 -0
- data/lib/2.2/libsmokeqttest.dll +0 -0
- data/lib/2.2/libsmokeqtuitools.dll +0 -0
- data/lib/2.2/libsmokeqtwebkit.dll +0 -0
- data/lib/2.2/libsmokeqtxml.dll +0 -0
- data/lib/2.2/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.2/qtdeclarative.so +0 -0
- data/lib/2.2/qtruby4.so +0 -0
- data/lib/2.2/qtscript.so +0 -0
- data/lib/2.2/qttest.so +0 -0
- data/lib/2.2/qtuitools.so +0 -0
- data/lib/2.2/qtwebkit.so +0 -0
- data/lib/2.3/libqtruby4shared.dll +0 -0
- data/lib/2.3/libsmokebase.dll +0 -0
- data/lib/2.3/libsmokeqtcore.dll +0 -0
- data/lib/2.3/libsmokeqtdeclarative.dll +0 -0
- data/lib/2.3/libsmokeqtgui.dll +0 -0
- data/lib/2.3/libsmokeqthelp.dll +0 -0
- data/lib/2.3/libsmokeqtmultimedia.dll +0 -0
- data/lib/2.3/libsmokeqtnetwork.dll +0 -0
- data/lib/2.3/libsmokeqtopengl.dll +0 -0
- data/lib/2.3/libsmokeqtscript.dll +0 -0
- data/lib/2.3/libsmokeqtsql.dll +0 -0
- data/lib/2.3/libsmokeqtsvg.dll +0 -0
- data/lib/2.3/libsmokeqttest.dll +0 -0
- data/lib/2.3/libsmokeqtuitools.dll +0 -0
- data/lib/2.3/libsmokeqtwebkit.dll +0 -0
- data/lib/2.3/libsmokeqtxml.dll +0 -0
- data/lib/2.3/libsmokeqtxmlpatterns.dll +0 -0
- data/lib/2.3/qtdeclarative.so +0 -0
- data/lib/2.3/qtruby4.so +0 -0
- data/lib/2.3/qtscript.so +0 -0
- data/lib/2.3/qttest.so +0 -0
- data/lib/2.3/qtuitools.so +0 -0
- data/lib/2.3/qtwebkit.so +0 -0
- data/lib/qtbindings_qt_version.rb +0 -2
@@ -1,45 +1,45 @@
|
|
1
|
-
require 'Qt'
|
2
|
-
|
3
|
-
class LCDRange < Qt::Widget
|
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
|
-
end
|
1
|
+
require 'Qt'
|
2
|
+
|
3
|
+
class LCDRange < Qt::Widget
|
4
|
+
signals 'valueChanged(int)'
|
5
|
+
slots 'setValue(int)', 'setRange(int, int)'
|
6
|
+
|
7
|
+
def initialize(parent = nil)
|
8
|
+
super
|
9
|
+
lcd = Qt::LCDNumber.new(2)
|
10
|
+
@slider = Qt::Slider.new(Qt::Horizontal)
|
11
|
+
@slider.range = 0..99
|
12
|
+
@slider.setValue(0)
|
13
|
+
connect(@slider, SIGNAL('valueChanged(int)'), lcd, SLOT('display(int)'))
|
14
|
+
connect(@slider, SIGNAL('valueChanged(int)'), SIGNAL('valueChanged(int)'))
|
15
|
+
|
16
|
+
layout = Qt::VBoxLayout.new
|
17
|
+
layout.addWidget(lcd)
|
18
|
+
layout.addWidget(@slider)
|
19
|
+
setLayout(layout)
|
20
|
+
|
21
|
+
setFocusProxy(@slider)
|
22
|
+
end
|
23
|
+
|
24
|
+
def value()
|
25
|
+
@slider.value()
|
26
|
+
end
|
27
|
+
|
28
|
+
def setValue(value)
|
29
|
+
@slider.setValue(value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def range=(r)
|
33
|
+
setRange(r.begin, r.end)
|
34
|
+
end
|
35
|
+
|
36
|
+
def setRange(minVal, maxVal)
|
37
|
+
if minVal < 0 || maxVal > 99 || minVal > maxVal
|
38
|
+
qWarning("LCDRange::setRange(#{minVal},#{maxVal})\n" +
|
39
|
+
"\tRange must be 0..99\n" +
|
40
|
+
"\tand minVal must not be greater than maxVal")
|
41
|
+
return
|
42
|
+
end
|
43
|
+
@slider.setRange(minVal, maxVal)
|
44
|
+
end
|
45
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$VERBOSE = true; $:.unshift File.dirname($0)
|
3
|
-
|
4
|
-
require 'Qt'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
class MyWidget < Qt::Widget
|
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
|
-
end
|
60
|
-
|
61
|
-
app = Qt::Application.new(ARGV)
|
62
|
-
widget = MyWidget.new
|
63
|
-
widget.setGeometry(
|
64
|
-
widget.show
|
65
|
-
app.exec
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$VERBOSE = true; $:.unshift File.dirname($0)
|
3
|
+
|
4
|
+
require 'Qt'
|
5
|
+
require_relative 'lcdrange.rb'
|
6
|
+
require_relative 'cannon.rb'
|
7
|
+
|
8
|
+
class MyWidget < Qt::Widget
|
9
|
+
def initialize(parent = nil)
|
10
|
+
super
|
11
|
+
quit = Qt::PushButton.new('Quit')
|
12
|
+
quit.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
|
13
|
+
|
14
|
+
connect(quit, SIGNAL('clicked()'), $qApp, SLOT('quit()'))
|
15
|
+
|
16
|
+
angle = LCDRange.new(self)
|
17
|
+
angle.range = 5..70
|
18
|
+
|
19
|
+
force = LCDRange.new(self)
|
20
|
+
force.range = 10..50
|
21
|
+
|
22
|
+
cannonField = CannonField.new(self)
|
23
|
+
|
24
|
+
connect(angle, SIGNAL('valueChanged(int)'),
|
25
|
+
cannonField, SLOT('setAngle(int)'))
|
26
|
+
connect(cannonField, SIGNAL('angleChanged(int)'),
|
27
|
+
angle, SLOT('setValue(int)'))
|
28
|
+
|
29
|
+
connect(force, SIGNAL('valueChanged(int)'),
|
30
|
+
cannonField, SLOT('setForce(int)'))
|
31
|
+
connect(cannonField, SIGNAL('forceChanged(int)'),
|
32
|
+
force, SLOT('setValue(int)'))
|
33
|
+
|
34
|
+
shoot = Qt::PushButton.new('&Shoot')
|
35
|
+
shoot.setFont(Qt::Font.new('Times', 18, Qt::Font::Bold))
|
36
|
+
|
37
|
+
connect(shoot, SIGNAL('clicked()'), cannonField, SLOT('shoot()'))
|
38
|
+
|
39
|
+
topLayout = Qt::HBoxLayout.new
|
40
|
+
topLayout.addWidget(shoot)
|
41
|
+
topLayout.addStretch(1)
|
42
|
+
|
43
|
+
leftLayout = Qt::VBoxLayout.new()
|
44
|
+
leftLayout.addWidget(angle)
|
45
|
+
leftLayout.addWidget(force)
|
46
|
+
|
47
|
+
gridLayout = Qt::GridLayout.new
|
48
|
+
gridLayout.addWidget(quit, 0, 0)
|
49
|
+
gridLayout.addLayout(topLayout, 0, 1)
|
50
|
+
gridLayout.addLayout(leftLayout, 1, 0)
|
51
|
+
gridLayout.addWidget(cannonField, 1, 1, 2, 1)
|
52
|
+
gridLayout.setColumnStretch(1, 10)
|
53
|
+
setLayout(gridLayout)
|
54
|
+
|
55
|
+
angle.setValue(60)
|
56
|
+
force.setValue(25)
|
57
|
+
angle.setFocus()
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
app = Qt::Application.new(ARGV)
|
62
|
+
widget = MyWidget.new
|
63
|
+
widget.setGeometry(100, 100, 500, 355)
|
64
|
+
widget.show
|
65
|
+
app.exec
|
@@ -1,158 +1,157 @@
|
|
1
|
-
include Math
|
2
|
-
require 'Qt'
|
3
|
-
|
4
|
-
class CannonField < Qt::Widget
|
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
|
-
end
|
1
|
+
include Math
|
2
|
+
require 'Qt'
|
3
|
+
|
4
|
+
class CannonField < Qt::Widget
|
5
|
+
signals 'hit()', 'missed()', 'angleChanged(int)', 'forceChanged(int)'
|
6
|
+
slots 'setAngle(int)', 'setForce(int)', 'shoot()', 'moveShot()', 'newTarget()'
|
7
|
+
|
8
|
+
def initialize(parent = nil)
|
9
|
+
super
|
10
|
+
@currentAngle = 45
|
11
|
+
@currentForce = 0
|
12
|
+
@timerCount = 0
|
13
|
+
@autoShootTimer = Qt::Timer.new(self)
|
14
|
+
connect(@autoShootTimer, SIGNAL('timeout()'),
|
15
|
+
self, SLOT('moveShot()'));
|
16
|
+
@shootAngle = 0
|
17
|
+
@shootForce = 0
|
18
|
+
@target = Qt::Point.new(0, 0)
|
19
|
+
setPalette(Qt::Palette.new(Qt::Color.new(250, 250, 200)))
|
20
|
+
setAutoFillBackground(true)
|
21
|
+
newTarget()
|
22
|
+
@barrelRect = Qt::Rect.new(33, -4, 15, 8)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setAngle(degrees)
|
26
|
+
if degrees < 5
|
27
|
+
degrees = 5
|
28
|
+
elsif degrees > 70
|
29
|
+
degrees = 70
|
30
|
+
end
|
31
|
+
if @currentAngle == degrees
|
32
|
+
return
|
33
|
+
end
|
34
|
+
@currentAngle = degrees
|
35
|
+
update(cannonRect())
|
36
|
+
emit angleChanged(@currentAngle)
|
37
|
+
end
|
38
|
+
|
39
|
+
def setForce(newton)
|
40
|
+
if newton < 0
|
41
|
+
newton = 0
|
42
|
+
end
|
43
|
+
if @currentForce == newton
|
44
|
+
return
|
45
|
+
end
|
46
|
+
@currentForce = newton
|
47
|
+
emit forceChanged(@currentForce)
|
48
|
+
end
|
49
|
+
|
50
|
+
def shoot()
|
51
|
+
if @autoShootTimer.isActive()
|
52
|
+
return
|
53
|
+
end;
|
54
|
+
@timerCount = 0
|
55
|
+
@shootAngle = @currentAngle
|
56
|
+
@shootForce = @currentForce
|
57
|
+
@autoShootTimer.start(50)
|
58
|
+
end
|
59
|
+
|
60
|
+
@@currentForceirst_time = true
|
61
|
+
|
62
|
+
def newTarget()
|
63
|
+
if @@currentForceirst_time
|
64
|
+
@@currentForceirst_time = false
|
65
|
+
midnight = Qt::Time.new(0, 0, 0)
|
66
|
+
srand(midnight.secsTo(Qt::Time.currentTime()))
|
67
|
+
end
|
68
|
+
r = Qt::Region.new(targetRect())
|
69
|
+
@target = Qt::Point.new(200 + rand(190),
|
70
|
+
10 + rand(255))
|
71
|
+
repaint(r.unite(Qt::Region.new(targetRect())))
|
72
|
+
end
|
73
|
+
|
74
|
+
def moveShot()
|
75
|
+
r = Qt::Region.new(shotRect())
|
76
|
+
@timerCount += 1
|
77
|
+
|
78
|
+
shotR = shotRect()
|
79
|
+
|
80
|
+
if shotR.intersects(targetRect())
|
81
|
+
@autoShootTimer.stop()
|
82
|
+
emit hit()
|
83
|
+
elsif shotR.x() > width() || shotR.y() > height()
|
84
|
+
@autoShootTimer.stop()
|
85
|
+
emit missed()
|
86
|
+
else
|
87
|
+
r = r.unite(Qt::Region.new(shotR))
|
88
|
+
end
|
89
|
+
|
90
|
+
update(r)
|
91
|
+
end
|
92
|
+
|
93
|
+
def paintEvent(e)
|
94
|
+
painter = Qt::Painter.new(self)
|
95
|
+
paintCannon(painter)
|
96
|
+
if @autoShootTimer.isActive()
|
97
|
+
paintShot(painter)
|
98
|
+
end
|
99
|
+
paintTarget(painter)
|
100
|
+
painter.end()
|
101
|
+
end
|
102
|
+
|
103
|
+
def paintShot(painter)
|
104
|
+
painter.setPen(Qt::NoPen)
|
105
|
+
painter.setBrush(Qt::Brush.new(Qt::black))
|
106
|
+
painter.drawRect(shotRect())
|
107
|
+
end
|
108
|
+
|
109
|
+
def paintTarget(painter)
|
110
|
+
painter.setBrush(Qt::Brush.new(Qt::red))
|
111
|
+
painter.setPen(Qt::Pen.new(Qt::Color.new(Qt::black)))
|
112
|
+
painter.drawRect(targetRect())
|
113
|
+
end
|
114
|
+
|
115
|
+
def paintCannon(painter)
|
116
|
+
painter.setPen(Qt::NoPen)
|
117
|
+
painter.setBrush(Qt::Brush.new(Qt::blue))
|
118
|
+
|
119
|
+
painter.save()
|
120
|
+
painter.translate(0, height())
|
121
|
+
painter.drawPie(Qt::Rect.new(-35, -35, 70, 70), 0, 90 * 16)
|
122
|
+
painter.rotate(- @currentAngle)
|
123
|
+
painter.drawRect(@barrelRect)
|
124
|
+
painter.restore()
|
125
|
+
end
|
126
|
+
|
127
|
+
def cannonRect()
|
128
|
+
r = Qt::Rect.new(0, 0, 50, 50)
|
129
|
+
r.moveBottomLeft(rect().bottomLeft())
|
130
|
+
return r
|
131
|
+
end
|
132
|
+
|
133
|
+
def shotRect()
|
134
|
+
gravity = 4.0
|
135
|
+
|
136
|
+
time = @timerCount / 4.0
|
137
|
+
velocity = @shootForce
|
138
|
+
radians = @shootAngle * 3.14159265 / 180.0
|
139
|
+
|
140
|
+
velx = velocity * cos(radians)
|
141
|
+
vely = velocity * sin(radians)
|
142
|
+
x0 = (@barrelRect.right() + 5.0) * cos(radians)
|
143
|
+
y0 = (@barrelRect.right() + 5.0) * sin(radians)
|
144
|
+
x = x0 + velx * time
|
145
|
+
y = y0 + vely * time - 0.5 * gravity * time * time
|
146
|
+
|
147
|
+
r = Qt::Rect.new(0, 0, 6, 6);
|
148
|
+
r.moveCenter(Qt::Point.new(x.round, height() - 1 - y.round))
|
149
|
+
return r
|
150
|
+
end
|
151
|
+
|
152
|
+
def targetRect()
|
153
|
+
r = Qt::Rect.new(0, 0, 20, 10)
|
154
|
+
r.moveCenter(Qt::Point.new(@target.x(), height() - 1 - @target.y()));
|
155
|
+
return r
|
156
|
+
end
|
157
|
+
end
|