qtbindings 4.8.6.3-x64-mingw32 → 4.8.6.4-x64-mingw32

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