qt_connect 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,340 @@
1
+ =begin
2
+ **
3
+ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
+ ** Contact: Qt Software Information (qt-info@nokia.com)
5
+ **
6
+ ** This file is part of the Graphics Dojo project on Qt Labs.
7
+ **
8
+ ** This file may be used under the terms of the GNU General Public
9
+ ** License version 2.0 or 3.0 as published by the Free Software Foundation
10
+ ** and appearing in the file LICENSE.GPL included in the packaging of
11
+ ** this file. Please review the following information to ensure GNU
12
+ ** General Public Licensing requirements will be met:
13
+ ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
14
+ ** http://www.gnu.org/copyleft/gpl.html.
15
+ **
16
+ ** If you are unsure which license is appropriate for your use, please
17
+ ** contact the sales department at qt-sales@nokia.com.
18
+ **
19
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
+ **
22
+ ** see original article 'Maps with a Magnifying Glass' by Ariya Hidayat
23
+ ** (http://labs.trolltech.com/blogs/2009/07/29/maps-with-a-magnifying-glass/)
24
+ **
25
+ ** Ruby implementation and minor modifications by Cees Zeelenberg
26
+ ** (c.zeelenberg@computer.org)
27
+ =end
28
+
29
+ require 'qt_connect'
30
+
31
+ MAP_HTML=%Q[
32
+ <html>
33
+ <head>
34
+ <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
35
+ <script type="text/javascript">
36
+ var map;
37
+ function initialize() {
38
+ var myOptions = {
39
+ zoom: 15,
40
+ center: new google.maps.LatLng(51.4772,0.0),
41
+ disableDefaultUI: true,
42
+ mapTypeId: google.maps.MapTypeId.ROADMAP
43
+ }
44
+ map = new google.maps.Map(document.getElementById("map_canvas"),
45
+ myOptions);
46
+ var marker = new google.maps.Marker({map: map, position:
47
+ map.getCenter()});
48
+ return true;
49
+ }
50
+ </script>
51
+ </head>
52
+ <body style="margin:0px; padding:0px;">
53
+ <div id="map_canvas" style="width:100%; height:100%"></div>
54
+ </body></html>
55
+ </html>
56
+ ]
57
+ HOLD_TIME=701
58
+ MAX_MAGNIFIER=229
59
+ #
60
+ # the GMaps class should really inherit from Qt:WebView
61
+ # but at the time of writing this caused a problem with 'paintEvent', which could not
62
+ # provide access to the paint device.
63
+ # the disadvantage of this workaround is that keyboard and mouse-events are not passed on
64
+ # to the Google application
65
+
66
+ class GMaps < Qt::Widget
67
+
68
+ def initialize(parent)
69
+ @parent=parent
70
+ super(parent)
71
+ @timer=Qt::Timer.new
72
+ @timer.singleShot=true
73
+ @timer.timeout.connect{triggerLoading}
74
+ @pressed=false
75
+ @snapped=false
76
+ @zoomed=false
77
+ @zoomPage=Qt::WebPage.new(self)
78
+ @zoomPage.repaintRequested.connect{update()}
79
+ @mainPage=Qt::WebPage.new(self)
80
+
81
+ @mainFrame=@mainPage.mainFrame
82
+ @mainFrame.setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff)
83
+ @mainFrame.setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff)
84
+ content=MAP_HTML
85
+ @mainFrame.setHtml(content)
86
+ @zoomFrame=@zoomPage.mainFrame
87
+ @zoomFrame.setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff)
88
+ @zoomFrame.setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff)
89
+ @zoomFrame.loadFinished.connect{ |tf| triggerLoading}
90
+ content=MAP_HTML.gsub("zoom: 15", "zoom: 16")
91
+ @zoomFrame.setHtml(content)
92
+ @pressPos=Qt::Point.new
93
+ @dragPos=Qt::Point.new
94
+ @tapTimer=Qt::BasicTimer.new
95
+ @zoomPixmap=Qt::Pixmap.new
96
+ @maskPixmap=Qt::Pixmap.new
97
+ @normalPixmapSize=Qt::Size.new
98
+
99
+ end
100
+
101
+ def setCenter(latitude,longitude)
102
+ @lat=latitude
103
+ @lng=longitude
104
+ @dlat=0.0
105
+ @dlng=0.0
106
+ @mousePos=@lastPos
107
+ @code = "map.setCenter(new google.maps.LatLng(#{latitude}, #{longitude}));"
108
+ @mainFrame.evaluateJavaScript(@code)
109
+ @zoomFrame.evaluateJavaScript(@code)
110
+ code = "map.getBounds().toUrlValue(5)"
111
+ return unless coors=(@mainFrame.evaluateJavaScript(code)).toString
112
+ fx1,fy1,fx2,fy2=coors.split(',').map{ |f| f.to_f}
113
+ @dlat=(fx2-fx1)/size.width
114
+ @dlng=(fy2-fy1)/size.height
115
+ end
116
+
117
+ def setMagnifierMode(mode)
118
+ code=%Q[map.setMapTypeId(google.maps.MapTypeId.#{mode.to_s.upcase});]
119
+ @zoomFrame.evaluateJavaScript(code)
120
+ end
121
+
122
+ def setPanelMode(mode)
123
+ code=%Q[map.setMapTypeId(google.maps.MapTypeId.#{mode.to_s.upcase});]
124
+ @mainFrame.evaluateJavaScript(code)
125
+ end
126
+
127
+ def setZoom(zoomfactor)
128
+ code=%Q[map.setZoom(#{zoomfactor});]
129
+ @mainFrame.evaluateJavaScript(code)
130
+ code=%Q[map.setZoom(#{zoomfactor+1});]
131
+ @zoomFrame.evaluateJavaScript(code)
132
+ end
133
+
134
+ def triggerLoading()
135
+ code = "initialize();"
136
+ xm=@mainFrame.evaluateJavaScript(code).toBool
137
+ xz=@zoomFrame.evaluateJavaScript(code).toBool
138
+ Qt::Timer.singleShot(1000,self,:triggerLoading) unless xm && xz
139
+ end
140
+
141
+ def timerEvent(event)
142
+ super(event)
143
+ if (!@zoomed)
144
+ @zoomed = true
145
+ @tapTimer.stop()
146
+ @mainPage.viewportSize=size
147
+ @zoomPage.viewportSize=self.size*2
148
+ lat = @mainFrame.evaluateJavaScript("map.getCenter().lat()").toDouble
149
+ lng = @mainFrame.evaluateJavaScript("map.getCenter().lng()").toDouble
150
+ setCenter(lat, lng);
151
+ end
152
+ update();
153
+ end
154
+ def mousePressEvent(event)
155
+ @pressed = @snapped = true
156
+ @pressPos = @dragPos = event.pos()
157
+ @tapTimer.stop()
158
+ @tapTimer.start(HOLD_TIME, self)
159
+ super(event)
160
+ end
161
+
162
+ def mouseReleaseEvent(event)
163
+ @pressed = @snapped = false
164
+ @tapTimer.stop()
165
+ if (!@zoomed)
166
+ super(event)
167
+ else
168
+ @zoomed = false
169
+ event.accept()
170
+ update();
171
+ end
172
+ end
173
+ def mouseMoveEvent(event)
174
+ @mousePos ||= event.pos
175
+ @lastPos=event.pos()
176
+ if (!@zoomed)
177
+ if (!@pressed || !@snapped)
178
+ begin
179
+ deltamouse=@lastPos-@mousePos
180
+ newlat=@lat+@dlat*deltamouse.y
181
+ newlng=@lng-@dlng*deltamouse.x
182
+ setCenter(newlat,newlng)
183
+ rescue
184
+ end
185
+ return
186
+ else
187
+ threshold=40
188
+ delta = event.pos() - @pressPos
189
+ if (@snapped)
190
+ @snapped &= (delta.x() < threshold)
191
+ @snapped &= (delta.y() < threshold)
192
+ @snapped &= (delta.x() > -threshold)
193
+ @snapped &= (delta.y() > -threshold)
194
+ end
195
+ (@tapTimer.stop() ; super(event)) if (!@snapped)
196
+ end
197
+ else
198
+ @dragPos = event.pos();
199
+ update();
200
+ end
201
+ end
202
+
203
+ def paintEvent(event)
204
+ if @normalPixmapSize !=self.size
205
+ @normalPixmapSize=size
206
+ @mainPage.viewportSize=size
207
+ @zoomPage.viewportSize=size * 2
208
+ end
209
+ @painter=Qt::Painter.new(self)
210
+ @painter.renderHint=Qt::Painter::Antialiasing
211
+ @painter.save
212
+ @mainFrame.render(@painter,event.region)
213
+ @painter.restore
214
+ if @zoomed
215
+ dim = [width(), height()].min
216
+ magnifierSize = [MAX_MAGNIFIER, dim * 2 / 3].min
217
+ radius = magnifierSize / 2
218
+ ring = radius - 15
219
+ box = Qt::Size.new(magnifierSize, magnifierSize)
220
+
221
+ if (@maskPixmap.size() != box)
222
+ @maskPixmap = Qt::Pixmap.new(box) {fill(Qt::Color.new(Qt::transparent))}
223
+ g=Qt::RadialGradient.new {
224
+ setCenter(radius, radius)
225
+ setFocalPoint(radius, radius)
226
+ setRadius(radius)
227
+ setColorAt(1.0, Qt::Color.new(255, 255, 255, 0))
228
+ setColorAt(0.5, Qt::Color.new(128, 128, 128, 255))
229
+ }
230
+ Qt::Painter.new(@maskPixmap) { |p|
231
+ p.setRenderHint(Qt::Painter::Antialiasing)
232
+ p.setCompositionMode(Qt::Painter::CompositionMode_Source)
233
+ p.setBrush(Qt::Brush.new(g))
234
+ p.setPen(Qt::NoPen)
235
+ p.drawRect(@maskPixmap.rect())
236
+ p.setBrush(Qt::Brush.new(Qt::Color.new(Qt::transparent)))
237
+ p.drawEllipse(g.center(), ring, ring)
238
+ p.end
239
+ }
240
+ end
241
+ center_xy=@dragPos - Qt::Point.new(0,radius/2)
242
+ ulhc_xy = center_xy - Qt::Point.new(radius, radius)
243
+ zoom_ulhc_xy = center_xy * 2 - Qt::Point.new(radius, radius)
244
+ center_xy_f=Qt::PointF.new(center_xy.x.to_f,center_xy.y.to_f)
245
+
246
+ if (@zoomPixmap.size() != box)
247
+ @zoomPixmap = Qt::Pixmap.new(box) { fill(Qt::Color.new(Qt::lightGray))}
248
+ end
249
+ Qt::Painter.new(@zoomPixmap) { |zp|
250
+ zp.translate(-zoom_ulhc_xy)
251
+ region=Qt::Region.new(Qt::Rect.new(zoom_ulhc_xy, box))
252
+ @zoomFrame.render(zp,region)
253
+ zp.end
254
+ }
255
+ @clippath=Qt::PainterPath.new{addEllipse(center_xy_f, ring.to_f, ring.to_f)}
256
+
257
+ @painter.clipPath=@clippath
258
+ @painter.drawPixmap(ulhc_xy, @zoomPixmap)
259
+ @painter.clipping=false
260
+ @painter.drawPixmap(ulhc_xy, @maskPixmap)
261
+ @painter.pen=Qt::gray
262
+ @painter.drawPath(@clippath)
263
+ end
264
+ @painter.end
265
+ end
266
+
267
+ end
268
+
269
+ if $0==__FILE__
270
+
271
+ PLACES={ "&Oslo"=>[59.9138204, 10.7387413],
272
+ "&Berlin"=>[52.5056819, 13.3232027],
273
+ "&Jakarta"=>[-6.211544, 106.845172],
274
+ "The &Hague"=>[52.075489,4.309369],
275
+ "&Geelong"=>[-38.1445,144.3710]
276
+ }
277
+ MODES=[:hybrid,:roadmap,:satellite,:terrain]
278
+ ZOOMRANGE=(14..17)
279
+
280
+ class MapZoom < Qt::MainWindow
281
+ def initialize
282
+ super
283
+ @map = GMaps.new(self)
284
+ setCentralWidget(@map)
285
+ placeMenu = menuBar().addMenu("&Place")
286
+ placeGroup=Qt::ActionGroup.new(self)
287
+ PLACES.each{ |city,coordinates|
288
+ Qt::Action.new(city, self){ |action|
289
+ action.triggered.connect{@map.setCenter(*coordinates)}
290
+ action.checkable=true
291
+ placeMenu.addAction(action)
292
+ }
293
+ }
294
+ settingsMenu = menuBar().addMenu("&Settings")
295
+ magnifierSubMenu=settingsMenu.addMenu("Magnifier")
296
+ panelSubMenu=settingsMenu.addMenu("Panel")
297
+ zoomSubMenu=settingsMenu.addMenu("Zoomfactor")
298
+
299
+ magnifierGroup=Qt::ActionGroup.new(self)
300
+ MODES.each{ |mode|
301
+ Qt::Action.new(mode.to_s.capitalize,self){ |action|
302
+ action.triggered.connect{@map.setMagnifierMode(mode)}
303
+ action.checkable=true
304
+ action.checked=true if mode==:roadmap
305
+ magnifierSubMenu.addAction(action)
306
+ magnifierGroup.addAction(action)
307
+ }
308
+ }
309
+ panelGroup=Qt::ActionGroup.new(self)
310
+ MODES.each{ |mode|
311
+ Qt::Action.new(mode.to_s.capitalize,self){ |action|
312
+ action.triggered.connect{@map.setPanelMode(mode)}
313
+ action.checkable=true
314
+ action.checked=true if mode==:roadmap
315
+ panelSubMenu.addAction(action)
316
+ panelGroup.addAction(action)
317
+ }
318
+ }
319
+ zoomGroup=Qt::ActionGroup.new(self)
320
+ ZOOMRANGE.each{ |zoomfactor|
321
+ Qt::Action.new(zoomfactor.to_s,self){ |action|
322
+ action.triggered.connect{@map.setZoom(zoomfactor)}
323
+ action.checkable=true
324
+ action.checked=true if zoomfactor==15
325
+ zoomSubMenu.addAction(action)
326
+ zoomGroup.addAction(action)
327
+ }
328
+ }
329
+ end
330
+ end
331
+
332
+
333
+ a = Qt::Application.new(ARGV)
334
+ w = MapZoom.new
335
+ w.setWindowTitle("Maps (powered by Google)")
336
+ w.resize(600,450)
337
+ w.show()
338
+ a.exec
339
+
340
+ end
@@ -0,0 +1,13 @@
1
+
2
+ public interface SignalActions {
3
+ void signal0();
4
+ void signal1(Object a1);
5
+ void signal2(Object a1,Object a2);
6
+ void signal3(Object a1,Object a2,Object a3);
7
+ void signal4(Object a1,Object a2,Object a3,Object a4);
8
+ void signal5(Object a1,Object a2,Object a3,Object a4,Object a5);
9
+ void signal6(Object a1,Object a2,Object a3,Object a4,Object a5,Object a6);
10
+ void signal7(Object a1,Object a2,Object a3,Object a4,Object a5,Object a6,Object a7);
11
+ void signal8(Object a1,Object a2,Object a3,Object a4,Object a5,Object a6,Object a7,Object a8);
12
+ void signal9(Object a1,Object a2,Object a3,Object a4,Object a5,Object a6,Object a7,Object a8,Object a9);
13
+ }
@@ -0,0 +1,10 @@
1
+ if RUBY_PLATFORM =~ /java/
2
+ require 'qt_connect'
3
+ else
4
+ begin
5
+ require 'Qt4'
6
+ rescue LoadError
7
+ raise "qt_connect for Ruby requires the qtbindings gem installed "
8
+ end
9
+ require 'qt_connect'
10
+ end
@@ -0,0 +1,12 @@
1
+ if RUBY_PLATFORM =~ /java/
2
+ require 'java'
3
+ require 'signalactions.jar'
4
+ require 'qt_connect/qt_jbindings'
5
+ require 'qt_connect/qt_compat'
6
+
7
+ else
8
+ require 'Qt'
9
+ require 'qtwebkit'
10
+ require 'qt_connect/qt_sugar'
11
+
12
+ end
@@ -0,0 +1,700 @@
1
+ =begin
2
+
3
+ Author: Cees Zeelenberg (c.zeelenberg@computer.org)
4
+ Copyright: (c) 2010-2012 by Cees Zeelenberg
5
+ License: This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published
7
+ by the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version. *
9
+
10
+ This software extends the basic qt_jbindings API with functionality to
11
+ improve compatibility with the existing QtRuby API:
12
+ - same shorthand notations for Enums
13
+ - patches to classes where the API is slightly different to support
14
+ both interfaces (ongoing work)
15
+ - support for the QtRuby signals/slot interface in addition
16
+ to the QtJambi signals interface
17
+ - implementations of Qt::Variant and Qt::ModelIndex to allow single source
18
+ maintenance for QtRuby and QtJRuby
19
+
20
+
21
+ =end
22
+ module Qt
23
+
24
+ module Internal
25
+
26
+ # for all constants which inherit from the Enum class or are "public static final int" fields
27
+ # define a shorthand notation to be compatible with the Ruby version of qtbindings
28
+ # e.g. Qt::PenStyle::SolidLine can be abbreviated to Qt::SolidLine
29
+ #suppress clashing or otherwise undesirable shorthands with an entry in the DONT_ABBREVIATE hash.
30
+
31
+ DONT_ABBREVIATE= {
32
+ 'Qt::WindowType::Widget' => true,
33
+ 'Qt::WindowType::Dialog' => true,
34
+ 'Qt::WindowType::ToolTip' => true,
35
+ 'Qt::WindowType::SplashScreen' => true,
36
+
37
+ 'Qt::Style::PixelMetric::CustomEnum' => true,
38
+ 'Qt::Style::PrimitiveElement::CustomEnum' => true,
39
+ 'Qt::Style::ContentsType::CustomEnum' => true,
40
+ 'Qt::Style::ComplexControl::CustomEnum' => true,
41
+ 'Qt::Style::SubElement::CustomEnum' => true,
42
+ 'Qt::Style::ControlElement::CustomEnum' => true,
43
+ 'Qt::Style::StandardPixmap::CustomEnum' => true,
44
+ }
45
+ end
46
+
47
+ # 'create_constants' is called whenever new Module or Class is activated
48
+ #qtclass Java::ComTrollTechQtGui::QDockWidget (Class)
49
+ #qtname Qt::Dockwidget (String)
50
+ def self.create_constants(qtclass,qtname)
51
+ qtclass.class_eval{
52
+ constants.dup.each{ |c|
53
+ embedded_class=eval("#{qtclass.name}::#{c}")
54
+ next unless embedded_class.respond_to?(:java_class)
55
+ ancestors=(embedded_class.respond_to?(:ancestors)) ? embedded_class.ancestors : []
56
+ if ancestors.include? java.lang.Enum
57
+ embedded_class.values.to_ary.each{ |s|
58
+ symbol=s.toString
59
+ next if Qt::Internal::DONT_ABBREVIATE["#{qtname}::#{c}::#{symbol}"]
60
+ next if symbol=~/\A[^A-Z].*\Z/
61
+ next if const_defined?(symbol)
62
+ qtclass.class_eval("#{symbol}=#{qtclass.name}::#{c}::#{symbol}") rescue next
63
+ }
64
+ else
65
+ #could be class with public static final int field(s)
66
+ fields=embedded_class.java_class.fields rescue next
67
+ fields.each{ |field|
68
+ next unless field.static? && field.final? && field.public? && (field.value_type=="int")
69
+ symbol=field.name
70
+ value=Java.java_to_ruby(field.static_value)
71
+ qtclass.class_eval("#{symbol}=#{value}") rescue next
72
+ }
73
+ end
74
+ }
75
+ }
76
+ end
77
+
78
+ create_constants(self,'Qt')
79
+
80
+ #compat QtRuby4 (fails for WindowType)
81
+ WidgetType=WindowType::Widget
82
+ #WindowType=WindowType::Window
83
+ DialogType=WindowType::Dialog
84
+ SheetType=WindowType::Sheet
85
+ DrawerType=WindowType::Drawer
86
+ PopupType=WindowType::Popup
87
+ ToolType=WindowType::Tool
88
+ ToolTipType=WindowType::ToolTip
89
+ SplashScreenType=WindowType::SplashScreen
90
+ DesktopType=WindowType::Desktop
91
+ SubWindowType=WindowType::SubWindow
92
+
93
+ #deal with Qt::blue etc.
94
+ def Qt.method_missing(method,*args)
95
+ return Color.send(method) if Color.respond_to?(method)
96
+ return Color.new(*args).rgba if method==:qRgba
97
+ super(*args)
98
+ end
99
+
100
+ class MetaObject < QtJambi::QObject
101
+ def self.connectSlotsByName(arg)
102
+ arg.connectSlotsByName()
103
+ end
104
+ end
105
+
106
+ #mutable boolean for compatibility compatibility with qtruby
107
+ #
108
+ class Boolean
109
+ attr_accessor :value
110
+ def initialize(b=false) @value = b end
111
+ def nil?
112
+ return !@value
113
+ end
114
+ end
115
+
116
+
117
+ class ModelIndex
118
+ class <<self
119
+ def new
120
+ return nil
121
+ end
122
+ end
123
+ end
124
+
125
+ #
126
+ #following are patches to QtJambi classes, mostly for compatibility with qtruby
127
+ #Corresponding Procs are 'class_eval-ed' when a Qt class is activated
128
+ #see companion code: qt_jbindings Qt#const_missing
129
+ # 'signature' calls are for documentation only (e.g. classexplorer.rb) and have
130
+ # no effect on the functionality
131
+ module Internal
132
+
133
+ signature "void Qt::AbstractSlider.range=(Range)"
134
+ AbstractSlider=Proc.new do
135
+ def range=(arg)
136
+ if arg.kind_of? Range
137
+ return setRange(arg.begin, arg.exclude_end? ? arg.end - 1 : arg.end)
138
+ else
139
+ return setRange(arg)
140
+ end
141
+ end
142
+ end
143
+
144
+
145
+ #QtRuby uses: Qt::AbstractTextDocumentLayout::PaintContext.new
146
+ #QtJambi : Qt::AbstractTextDocumentLayout_PaintContext
147
+ AbstractTextDocumentLayout=Proc.new do
148
+ self.const_set('PaintContext',Qt::AbstractTextDocumentLayout_PaintContext)
149
+ end
150
+
151
+ #example\dialogs\simplewizard
152
+ signature "Qt::ByteArray Qt::ByteArray.+(Object)"
153
+ ByteArray=Proc.new do
154
+ def +(o)
155
+ self.clone.append(o)
156
+ end
157
+ end
158
+
159
+ signature "static Qt::DataStream Qt::DataStream.new"
160
+ signature "static Qt::DataStream Qt::DataStream.new(Qt::IODevice)"
161
+ signature "static Qt::DataStream Qt::DataStream.new(Qt::ByteArray)"
162
+ signature "static Qt::DataStream Qt::DataStream.new(Qt::ByteArray, Qt::IODevice::OpenMode)"
163
+ signature "static Qt::DataStream Qt::DataStream.new(Qt::ByteArray, int openmode)"
164
+ signature "static Qt::DataStream Qt::DataStream.new(Qt::ByteArray, Qt::IODevice::OpenModeFlag[])"
165
+ signature "void Qt::DataStream.setVersion(Enum)"
166
+ signature "Qt::DataStream Qt::DataStream.<<(Object)"
167
+ signature "Qt::DataStream Qt::DataStream.>>(Object)"
168
+ DataStream=Proc.new do
169
+ class << self
170
+ alias :orig_new :new
171
+ def new(*a,&block)
172
+ args=a.dup
173
+ args[1]=Qt::IODevice::OpenMode.new(args[1]) if (args.size>1) && args[1].kind_of?(Fixnum)
174
+ return orig_new(*args,&block)
175
+ end
176
+ end
177
+ alias orig_setVersion setVersion
178
+ def setVersion(a)
179
+ orig_setVersion(a.respond_to?(:value) ? a.value : a)
180
+ end
181
+ alias set_version setVersion
182
+ alias version= setVersion
183
+ def <<(arg)
184
+ case arg
185
+ when String ; writeString(arg)
186
+ when Float,Java::Float ; writeFloat(arg)
187
+ when Fixnum,Java::Int ; writeInt(arg)
188
+ when Java::Double ; writeDouble(arg)
189
+ when Java::ComTrolltechQtGui::QPixmap,
190
+ Java::ComTrolltechQtGui::QImage,
191
+ Java::ComTrolltechQtCore::QPointF,
192
+ Java::ComTrolltechQtCore::QPoint,
193
+ Java::ComTrolltechQtCore::QRect,
194
+ Java::ComTrolltechQtCore::QRectF,
195
+ Java::ComTrolltechQtGui::QRegion,
196
+ Java::ComTrolltechQtCore::QSize,
197
+ Java::ComTrolltechQtCore::QSizeF
198
+ arg.writeTo(self)
199
+ else
200
+ raise "Qt::Datastream: no '<<' for #{arg.class}"
201
+ end
202
+ self # allows concatenation
203
+ end
204
+ def >>(arg)
205
+ case arg
206
+ when String ; arg=readString
207
+ when Float ; arg=readFloat
208
+ when Fixnum ; arg=readInt
209
+ when Java::ComTrolltechQtGui::QPixmap,
210
+ Java::ComTrolltechQtGui::QImage,
211
+ Java::ComTrolltechQtCore::QPointF,
212
+ Java::ComTrolltechQtCore::QPoint,
213
+ Java::ComTrolltechQtCore::QRect,
214
+ Java::ComTrolltechQtCore::QRectF,
215
+ Java::ComTrolltechQtGui::QRegion,
216
+ Java::ComTrolltechQtCore::QSize,
217
+ Java::ComTrolltechQtCore::QSizeF
218
+ arg.readFrom(self)
219
+ else
220
+ raise "Qt::Datastream: no '>>' for #{arg.class}"
221
+ end
222
+ self
223
+ end
224
+ end
225
+ signature "void Qt::DoubleSpinBox.range=(Range)"
226
+ DoubleSpinBox=Proc.new do
227
+ def range=(arg)
228
+ if arg.kind_of? Range
229
+ return setRange(arg.begin, arg.exclude_end? ? arg.end - 1 : arg.end)
230
+ else
231
+ return setRange(arg)
232
+ end
233
+ end
234
+ end
235
+ #examples\draganddrop\draggabletext
236
+ signature "Qt::DropAction Qt::Drag.start"
237
+ signature "Qt::DropAction Qt::Drag.start(Fixnum dropactions)"
238
+ signature "Qt::DropAction Qt::Drag.start(Qt::DropAction[])"
239
+ signature "Qt::DropAction Qt::Drag.start(Qt::DropActions)"
240
+ signature "Qt::DropAction Qt::Drag.start(Qt::DropActions,Qt::DropAction)"
241
+ Drag=Proc.new do
242
+ alias orig_exec exec
243
+ def exec(*a)
244
+ args=a.dup
245
+ args[0]=Qt::DropActions.new(args[0]) if args[0].kind_of? Fixnum
246
+ orig_exec(*args)
247
+ end
248
+ alias :start :exec
249
+ end
250
+ #example\dialogs\findfile
251
+ signature "boolean Qt::File.open(Fixnum openmode)"
252
+ File=Proc.new do
253
+ alias orig_open open
254
+ def open(a)
255
+ arg=(a.kind_of?(Fixnum)) ? Qt::IODevice::OpenMode.new(a) : a
256
+ orig_open(arg)
257
+ end
258
+ end
259
+
260
+ signature "static java.lang.String Qt::FileDialog.getSaveFileName(Qt::Widget,String,String,String filter)"
261
+ signature "static java.lang.String Qt::FileDialog.getOpenFileName(Qt::Widget,String,String,String filter)"
262
+ signature "static java.util.List Qt::FileDialog.getOpenFileNames(Qt::Widget,String,String,String filter)"
263
+ FileDialog=Proc.new do
264
+ class << self
265
+ #getSaveFileName
266
+ alias orig_getSaveFileName getSaveFileName
267
+ def getSaveFileName(*a)
268
+ args=a.dup
269
+ args[3]=self::Filter.new(args[3]) if args.size==4 && (args[3].kind_of?(String))
270
+ orig_getSaveFileName(*args)
271
+ end
272
+ alias get_save_file_name getSaveFileName
273
+ #getOpenFilename
274
+ alias orig_getOpenFileName getOpenFileName
275
+ def getOpenFileName(*a)
276
+ args=a.dup
277
+ args[3]=self::Filter.new(args[3]) if args.size==4 && (args[3].kind_of?(String))
278
+ orig_getOpenFileName(*args)
279
+ end
280
+ alias get_open_file_name getOpenFileName
281
+ #getOpenFilenames
282
+ alias orig_getOpenFileNames getOpenFileNames
283
+ def getOpenFileNames(*a)
284
+ args=a.dup
285
+ args[3]=self::Filter.new(args[3]) if args.size==4 && (args[3].kind_of?(String))
286
+ orig_getOpenFileNames(*args)
287
+ end
288
+ alias get_open_file_names getOpenFileNames
289
+ end
290
+ end
291
+ #examples\dialogs\standarddialogs
292
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok)"
293
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok,Qt::Font)"
294
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok,Qt::Font,Qt::Widget,String)"
295
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok,Qt::Widget)"
296
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok,Qt::Font,Qt::Widget)"
297
+ signature "static Qt::Font Qt:FontDialog.getFont(Qt::Boolean ok,Qt::Font,Qt::Widget,String,Qt::FontDialog::FontDialogOptions)"
298
+ FontDialog=Proc.new do
299
+ class << self
300
+ alias orig_getFont getFont
301
+ def getFont(*a)
302
+ args=a.dup
303
+ if args[0].kind_of? Qt::Boolean
304
+ ok=args.shift
305
+ result=orig_getFont(*args)
306
+ ok.value=result.ok
307
+ result.font
308
+ else
309
+ orig_getFont(*args)
310
+ end
311
+ end
312
+ alias get_font getFont
313
+ end
314
+ end
315
+ #examples\draganddrop\fridgemagnets
316
+ signature "Qt::Size Qt::FontMetrics.size(Enum,String)"
317
+ FontMetrics=Proc.new do
318
+ alias :orig_size :size
319
+ def size(*a)
320
+ args=a.dup
321
+ args[0]=args[0].value if args[0].respond_to?(:value)
322
+ orig_size(*args)
323
+ end
324
+ end
325
+ signature "static java.lang.String Qt::InputDialog.getItem(Qt::Widget parent,String title,String label,java.util.List,int current,bool editable,Qt::Boolean ok)"
326
+ signature "static java.lang.String Qt::InputDialog.getText(Qt::Widget parent,String title,String label,Qt::LineEdit::EchoMode mode,String text,Qt::Boolean ok)"
327
+ signature "static java.lang.String Qt::InputDialog.getInteger(Qt::Widget parent,String title,String label,int value,int minvalue,int maxvalue,int decimals,Qt::Boolean ok)"
328
+ signature "static java.lang.String Qt::InputDialog.getInt(Qt::Widget parent,String title,String label,int value,int minvalue,int maxvalue,int decimals,Qt::Boolean ok)"
329
+ signature "static java.lang.String Qt::InputDialog.getDouble(Qt::Widget parent,String title,String label,Float value,Float minvalue,Float maxvalue,int decimals,Qt::Boolean ok)"
330
+ InputDialog=Proc.new do
331
+ class << self
332
+ #getInt
333
+ #getInteger
334
+ alias orig_getInt getInt
335
+ def getInt(*a)
336
+ args=a.dup
337
+ if args[-1].kind_of? Qt::Boolean
338
+ ok=args.pop
339
+ result=orig_getInt(*args)
340
+ ok.value=(result.nil?) ? false : true
341
+ result
342
+ else
343
+ orig_getInt(*args)
344
+ end
345
+ end
346
+ alias get_int getInt
347
+ alias getInteger getInt
348
+ alias get_integer getInt
349
+ #getDouble
350
+ alias orig_getDouble getDouble
351
+ def getDouble(*a)
352
+ args=a.dup
353
+ if args[-1].kind_of? Qt::Boolean
354
+ ok=args.pop
355
+ result=orig_getDouble(*args)
356
+ ok.value=(result.nil?) ? false : true
357
+ result
358
+ else
359
+ orig_getDouble(*args)
360
+ end
361
+ end
362
+ alias get_double getDouble
363
+ #getItem
364
+ alias :orig_getItem :getItem
365
+ def getItem(*a)
366
+ args=a.dup
367
+ if args[-1].kind_of? Qt::Boolean
368
+ ok=args.pop
369
+ result=orig_getItem(*args)
370
+ ok.value=(result.nil?) ? false : true
371
+ result
372
+ else
373
+ orig_getItem(*args)
374
+ end
375
+ end
376
+ alias get_item getItem
377
+ #getText
378
+ alias :orig_getText :getText
379
+ def getText(*a)
380
+ args=a.dup
381
+ if args[-1].kind_of? Qt::Boolean
382
+ ok=args.pop
383
+ result=orig_getText(*args)
384
+ ok.value=(result.nil?) ? false : true
385
+ result
386
+ else
387
+ orig_getText(*args)
388
+ end
389
+ end
390
+ alias :get_text :getText
391
+ end
392
+ end
393
+
394
+ signature "void Qt::Label.setAlignment(Fixnum)"
395
+ Label=Proc.new do
396
+ alias :orig_setAlignment :setAlignment
397
+ def setAlignment(a)
398
+ a=Qt::Alignment.new(a) if a.kind_of?(Fixnum)
399
+ orig_setAlignment(a)
400
+ end
401
+ alias :'alignment=' :setAlignment
402
+ end
403
+
404
+ #examples\layout\borderlayout
405
+ signature "int Qt::Layout.spacing"
406
+ signature "void Qt::Layout.setSpacing(int)"
407
+ Layout=Proc.new do
408
+ alias :spacing :widgetSpacing
409
+ alias :setSpacing :setWidgetSpacing
410
+ alias :set_spacing :setWidgetSpacing
411
+ end
412
+
413
+ signature "void Qt::ListWidgetItem.setTextAlignment(Qt::AlignmentFlag)"
414
+ signature "void Qt::ListWidgetItem.setFlags(int)"
415
+
416
+ ListWidgetItem=Proc.new do
417
+ alias :orig_setTextAlignment :setTextAlignment
418
+ def setTextAlignment(a)
419
+ arg=(a.respond_to?(:value)) ? a.value : a
420
+ orig_setTextAlignment(arg)
421
+ end
422
+ alias textAlignment= setTextAlignment
423
+ #examples\draganddrop\puzzle
424
+ alias :orig_setFlags :setFlags
425
+ def setFlags(a)
426
+ arg=(a.kind_of? Fixnum) ? Qt::ItemFlags.new(a) : a
427
+ orig_setFlags(arg)
428
+ end
429
+ alias :set_flags :setFlags
430
+ end
431
+
432
+ #examples\dialogs\standarddialogs
433
+ signature "static Qt::MessageBox::StandardButton Qt::MessageBox.critical(Qt::Widget,String,String"+
434
+ ",Qt::MessageBox::StandardButton,Qt::MessageBox::StandardButton,Qt::MessageBox::StandardButton)"
435
+ signature "static Qt::MessageBox::StandardButton Qt::MessageBox.question(Qt::Widget,String,String"+
436
+ ",Qt::MessageBox::StandardButton,Qt::MessageBox::StandardButton,Qt::MessageBox::StandardButton)"
437
+ MessageBox=Proc.new do
438
+ class<<self
439
+ alias orig_critical critical
440
+ def critical(*a)
441
+ args=a.dup
442
+ (a.size-4).times{ x=args.pop ; args[-1] |= x}
443
+ orig_critical(*args)
444
+ end
445
+ alias orig_question question
446
+ def question(*a)
447
+ args=a.dup
448
+ (a.size-4).times{ x=args.pop ; args[-1] |= x}
449
+ orig_question(*args)
450
+ end
451
+ end
452
+ end
453
+ signature "void Qt::Painter.drawText(Qt::Rect,Qt::Alignment,String)"
454
+ Painter=Proc.new do
455
+ alias orig_drawText drawText
456
+ def drawText(*a)
457
+ args=a.dup
458
+ args[1]=args[1].value if (args[1].respond_to?(:value))
459
+ orig_drawText(*args)
460
+ end
461
+ alias draw_text drawText
462
+ end
463
+
464
+ #examples\draganddrop\dragabletext
465
+ Palette=Proc.new do
466
+ #Background=ColorRole::Window (Background is Obsolete)
467
+ const_set('Background',const_get(:ColorRole).const_get(:Window))
468
+ end
469
+
470
+ signature "void Qt::ProgressDialog.range=(Range)"
471
+ ProgressDialog=Proc.new do
472
+ def range=(arg)
473
+ if arg.kind_of? Range
474
+ return setRange(arg.begin, arg.exclude_end? ? arg.end - 1 : arg.end)
475
+ else
476
+ return setRange(arg)
477
+ end
478
+ end
479
+ end
480
+
481
+ SignalMapper=Proc.new do
482
+ def mapped
483
+ return mappedQObject
484
+ end
485
+ end
486
+
487
+ signature "static Qt::SizePolicy Qt::SizePolicy.new"
488
+ signature "static Qt::SizePolicy Qt::SizePolicy.new(Qt::SizePolicy::Policy,Qt::SizePolicy::Policy,Qt::SizePolicy::ControlType)"
489
+ signature "static Qt::SizePolicy Qt::SizePolicy.new(Qt::SizePolicy::Policy,Qt::SizePolicy::Policy)"
490
+ signature "static Qt::SizePolicy Qt::SizePolicy.new(int,int,int)"
491
+ signature "static Qt::SizePolicy Qt::SizePolicy.new(int,int)"
492
+ SizePolicy=Proc.new do
493
+ class << self
494
+ alias :orig_new :new
495
+ def new(*args,&block)
496
+ args=args.map{ |arg| arg.kind_of?(Fixnum) ? Qt::SizePolicy::Policy.resolve(arg) : arg}
497
+ return orig_new(*args,&block)
498
+ end
499
+ end
500
+ end
501
+
502
+ signature "void Qt::SpinBox.range=(Range)"
503
+ SpinBox=Proc.new do
504
+ def range=(arg)
505
+ if arg.kind_of? Range
506
+ return setRange(arg.begin, arg.exclude_end? ? arg.end - 1 : arg.end)
507
+ else
508
+ return setRange(arg)
509
+ end
510
+ end
511
+ end
512
+
513
+ #examples\dialogs\findfiles
514
+ signature "void Qt::TableWidgetItem.setFlags(Fixnum flags)"
515
+ signature "void Qt::TableWidgetItem.setTextAlignment(Qt::AlignmentFlag)"
516
+ TableWidgetItem=Proc.new do
517
+ alias orig_setTextAlignment setTextAlignment
518
+ def setTextAlignment(a)
519
+ arg=(a.respond_to?(:value)) ? a.value : a
520
+ orig_setTextAlignment(arg)
521
+ end
522
+ alias textAlignment= setTextAlignment
523
+ alias set_text_alignment setTextAlignment
524
+
525
+ alias orig_setFlags setFlags
526
+ def setFlags(*a)
527
+ args=a.dup
528
+ args[0]=Qt::ItemFlags.new(args[0]) if args[0].kind_of? Fixnum
529
+ orig_setFlags(*args)
530
+ end
531
+ alias set_flags setFlags
532
+ alias flags= setFlags
533
+ end
534
+
535
+ signature "void Qt::TextCharFormat.setFontWeight(Qt::Enumerator)"
536
+ TextCharFormat=Proc.new do
537
+ alias :orig_fw :setFontWeight
538
+ def setFontWeight(val)
539
+ orig_fw( (val.respond_to? :value) ? val.value : val)
540
+ end
541
+ alias :set_font_weight :setFontWeight
542
+ alias :'fontWeight=' :setFontWeight
543
+ end
544
+
545
+ #require 'jruby/core_ext'
546
+ signature "void Qt::TextStream.<<(String)"
547
+ signature "void Qt::TextStream.>>(String)"
548
+ TextStream=Proc.new do
549
+ def <<(a)
550
+ self.writeString(a)
551
+ end
552
+ def >>(a)
553
+ a.replace(readString)
554
+ end
555
+ end
556
+
557
+ signature "static Object Qt::Variant.new(Object)"
558
+ signature "static Object Qt::Variant.fromValue(Object)"
559
+ Variant=Proc.new do
560
+ class << self
561
+ def new(obj=nil)
562
+ return obj
563
+ end
564
+ alias fromValue new
565
+ alias from_value new
566
+ end
567
+ end
568
+ end #Internal
569
+
570
+ AlignTrailing=AlignRight
571
+ AlignLeading=AlignLeft
572
+ end #QT
573
+
574
+ Qt::Internal::signature "void Qt::Object.connect(Qt::Object,Symbol,Qt::Object,Symbol)"
575
+ Qt::Internal::signature "void Qt::Object.connect(Qt::Object,Symbol,Qt::Object,String)"
576
+ Qt::Internal::signature "void Qt::Object.disconnect(Qt::Object,Symbol,Qt::Object,Symbol)"
577
+ Qt::Internal::signature "void Qt::Object.disconnect(Qt::Object,Symbol,Qt::Object,String)"
578
+ Qt::Internal::signature "int Qt::Object.qRgba(int,int,int,int)"
579
+ Qt::Internal::signature "static java.lang.String Qt::Object.tr(String)"
580
+ Qt::Internal::signature "Qt::SignalEmitter Qt::Object.sender"
581
+ Java::ComTrolltechQtCore::QObject.class_eval{
582
+ #connect(producer,SIGNAL('sig1'),consumer,SLOT('sig2'))
583
+ #connect(producer,SIGNAL('sig1'),consumer,SIGNAL('sig2')
584
+ #SIGNAL generates :sig1 (Symbol, only name of signal)
585
+ #SLOT generates 'sig1(a,b)' (String, full signature)
586
+ def connect(producer,sig1,consumer,sig2,type=0)
587
+ #see if Signal is of type QSignalEmitter or of type Qt::Signal
588
+ signal1=producer.java_class.field(sig1).value(producer) rescue signal1=producer.send(sig1)
589
+ #puts "connect #{signal1}(#{signal1.class}) => #{sig2}(#{sig2.class}) #{caller[0]}"
590
+ if sig2.kind_of?(String)
591
+ if md=sig2.match(/([^(]+)\([.]*/)
592
+ n=0 ; sig2.gsub(/ (\([^,)]+)|(,[^,)]+) | (,[^,)]+) /x){n+=1}
593
+ sig2=(n.to_s+md[1].strip)
594
+ end
595
+ #puts "signal->slot #{signal1}.connect(#{consumer},#{sig2.to_sym} #{caller[0]})"
596
+ return signal1.connect(consumer,sig2.to_sym)
597
+ end
598
+ signal2=consumer.java_class.field(sig2).value(consumer) rescue signal2=consumer.send(sig2)
599
+ #puts "signal->signal #{signal1}.connect(#{signal2}) #{caller[0]}"
600
+ return signal1.connect(signal2)
601
+ end
602
+
603
+ def disconnect(producer,sig1,consumer,sig2)
604
+ if sig2.kind_of?(String) && (md=sig2.match(/([^(]+)\([.]*/))
605
+ n=0 ; sig2.gsub(/ (\([^,)]+)|(,[^,)]+) | (,[^,)]+) /x){n+=1}
606
+ sig2=(n.to_s+md[1].strip).to_sym
607
+ end
608
+ sig2=sig2.to_sym
609
+ producer.java_class.field(sig1).value(producer).disconnect(consumer,sig2) rescue producer.send(sig1).disconnect(consumer,sig2)
610
+ end
611
+ def sender
612
+ #signalSender ia a static method of QSignalEmitter => Ruby Class Method
613
+ return QtJambi::QSignalEmitter.signalSender()
614
+ end
615
+ #'doc_was_epibrated(a1,a2)' => :'2doc_was_epibrated'
616
+ #'doc_was_cooked()' => :'0doc_was_cooked'
617
+ def SLOT(signature)
618
+ return signature if signature.kind_of? String
619
+ s=signature.to_s
620
+ return s if s.match(/([^(]+)\([.]*/)
621
+ return s+'()'
622
+ end
623
+ def SIGNAL(signature)
624
+ if signature.kind_of? Symbol
625
+ return signature
626
+ else
627
+ if md=signature.match(/([^(]+)\([.]*/)
628
+ return md[1].strip.to_sym
629
+ end
630
+ return signature.to_sym
631
+ end
632
+ end
633
+
634
+ def self.slots(*signallist) ; end
635
+ #emit signal(a1,a2..)
636
+ def emit(signal)
637
+ signal.emit
638
+ end
639
+
640
+ def qRgba(*args)
641
+ return Color.new(*args).rgba
642
+ end
643
+ def self.tr(s)
644
+ return self.new.tr(s)
645
+ end
646
+
647
+ }
648
+ #try using Qt.Variant type conversions if all else fails
649
+ class Object
650
+ def method_missing(m,*args,&block)
651
+ #puts "missing #{m} for #{self.class} #{caller[0].split('/')[-1]}"
652
+ method=((m==:toBool) || (m==:to_bool)) ? :toBoolean : m
653
+ return Qt::Variant.send(method,self) if com.trolltech.qt.QVariant.respond_to? method
654
+ return super
655
+ end
656
+ end
657
+
658
+ class Class
659
+
660
+ RX0=/([^(]+)\([.]*/ #name(.....
661
+ RX1=/\A[A-Z]+\z/ #1+ alpha => alt_m==m
662
+ RX2=/([A-Z]+)([A-Z][a-z])/
663
+ RX3=/([a-z\d])([A-Z])/
664
+
665
+ def signals(*signallist)
666
+ signallist.each{ |signature|
667
+ if signature.kind_of? String
668
+ if md=signature.match(RX0)
669
+ m=md[1].strip
670
+ else
671
+ m=signature.strip
672
+ end
673
+ else
674
+ m=signature.to_s
675
+ end
676
+ alt_m =(m=~RX1) ? m.downcase : m.gsub(RX2, '\1_\2').gsub(RX3, '\1_\2').tr("-","_").downcase
677
+ self.class_eval(%Q[
678
+ def #{m}(*args)
679
+ if @_#{m}
680
+ @_#{m}.setargs(*args)
681
+ return @_#{m}
682
+ else
683
+ return @_#{m}=Qt::Signal.new(self)
684
+ end
685
+ end
686
+ #{(alt_m==m) ? '' : "alias :#{alt_m} :#{m}"}
687
+ ])
688
+ }
689
+
690
+ end
691
+ end
692
+
693
+ class NilClass
694
+ def valid?
695
+ return false
696
+ end
697
+ end
698
+
699
+
700
+