qtext 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = qtext
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ Some extensions to qt4-qtruby to make it more rubyish
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/qtext.rb ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'Qt4'
5
+ require 'qtext/flags.rb'
6
+ require 'qtext/extensions.rb'
7
+
8
+ module QtExt
9
+
10
+ end
@@ -0,0 +1,269 @@
1
+ # need this here otherwise the definition of BigDecimal#to_variant
2
+ # causes and error
3
+ require 'Qt4'
4
+ require 'qtext/flags.rb'
5
+ require 'bigdecimal'
6
+
7
+ # Because Qt::Variant.new( obj ) is a PITA to type
8
+ class Object
9
+ def to_variant
10
+ begin
11
+ Qt::Variant.fromValue( self )
12
+ rescue Exception => e
13
+ puts e.backtrace.join( "\n" )
14
+ puts "error converting #{self.inspect} to variant: #{e.message}"
15
+ nil.to_variant
16
+ end
17
+ end
18
+ end
19
+
20
+ class Class
21
+ def construct_exec( *args, &block )
22
+ raise "block is nil" if block.nil?
23
+ inst = self.new( *args )
24
+ # using the Rails implementation, included in Qt
25
+ block.bind( inst )[*args]
26
+ # return the newly configured instance
27
+ inst
28
+ end
29
+
30
+ def construct( *args, &block )
31
+ raise "block is nil" if block.nil?
32
+ inst = self.new( *args )
33
+ yield( inst )
34
+ inst
35
+ end
36
+ end
37
+
38
+ class NilClass
39
+ def to_variant
40
+ Qt::Variant.invalid
41
+ end
42
+ end
43
+
44
+ class Date
45
+ def to_variant
46
+ self.to_s.to_variant
47
+ end
48
+ end
49
+
50
+ class BigDecimal
51
+ def to_variant
52
+ self.to_f.to_variant
53
+ end
54
+ end
55
+
56
+ # convenience methods
57
+ module Qt
58
+
59
+ class Base
60
+ # use the cursor constant for the application override cursor
61
+ # while the block is executing.
62
+ # Return the value of the block
63
+ def override_cursor( cursor_constant, &block )
64
+ Qt::Application.setOverrideCursor( Qt::Cursor.new( cursor_constant ) )
65
+ retval = yield
66
+ Qt::Application.restoreOverrideCursor
67
+ retval
68
+ end
69
+ end
70
+
71
+ class CheckBox
72
+ def value
73
+ checkState == qt_checked
74
+ end
75
+
76
+ def value=( obj )
77
+ # This seems backwards to me, but it works
78
+ setCheckState( ( obj == false ? Qt::Unchecked : Qt::Checked ) )
79
+ end
80
+ end
81
+
82
+ class RadioButton
83
+ def value
84
+ is_checked == true
85
+ end
86
+
87
+ def value=( bool )
88
+ setChecked( bool )
89
+ end
90
+ end
91
+
92
+ class Enum
93
+ def to_variant
94
+ to_i.to_variant
95
+ end
96
+ end
97
+
98
+ class ItemSelection
99
+ include Enumerable
100
+
101
+ def each( &block )
102
+ index = 0
103
+ max = self.count
104
+ while index < max
105
+ yield( self.at( index ) )
106
+ index += 1
107
+ end
108
+ end
109
+
110
+ def size
111
+ self.count
112
+ end
113
+
114
+ end
115
+
116
+ class ItemSelectionRange
117
+ def single_cell?
118
+ self.top == self.bottom && self.left == self.right
119
+ end
120
+ end
121
+
122
+ # This provides a bunch of methods to get easy access to the entity
123
+ # and it's values directly from the index without having to keep
124
+ # asking the model and jumping through other unncessary hoops
125
+ class ModelIndex
126
+ # Because using Qt::ModelIndex.new the whole time is wasteful
127
+ def self.invalid
128
+ @@invalid ||= ModelIndex.new
129
+ end
130
+
131
+ alias_method :old_inspect, :inspect
132
+ def inspect
133
+ #<Qt::ModelIndex:0xb6004e8c>
134
+ # fetch address from superclass inspect
135
+ super =~ /ModelIndex:(.*)>/
136
+ # format nicely
137
+ #~ "#<Qt::ModelIndex:#{$1} xy=(#{row},#{column}) gui_value=#{gui_value}>"
138
+ "#<Qt::ModelIndex:#{$1} xy=(#{row},#{column})>"
139
+ end
140
+
141
+ # sort by row, then column
142
+ def <=>( other )
143
+ row_comp = self.row <=> other.row
144
+ if row_comp == 0
145
+ self.column <=> other.column
146
+ else
147
+ row_comp
148
+ end
149
+ end
150
+
151
+ end
152
+
153
+ # make keystrokes easier to work with
154
+ class KeyEvent
155
+ # override otherwise the new method_missing fails
156
+ # to call the old_method_missing
157
+ def modifiers
158
+ old_method_missing( :modifiers )
159
+ end
160
+
161
+ # override otherwise the new method_missing fails
162
+ # to call the old_method_missing
163
+ def key
164
+ old_method_missing( :key )
165
+ end
166
+
167
+ # override otherwise the new method_missing fails
168
+ # to call the old_method_missing
169
+ def text
170
+ old_method_missing( :text )
171
+ end
172
+
173
+ # is the control key pressed?
174
+ def ctrl?
175
+ modifiers & Qt::ControlModifier.to_i == Qt::ControlModifier.to_i
176
+ end
177
+
178
+ alias_method :old_method_missing, :method_missing
179
+
180
+ # shortcut for the Qt::Key_Whatever constants
181
+ # just say event.whatever?
182
+ def method_missing( sym, *args )
183
+ begin
184
+ if sym.to_s[-1] == "?"[0]
185
+ key?( sym.to_s[0..-2] )
186
+ else
187
+ old_method_missing( sym, args )
188
+ end
189
+ rescue Exception => e
190
+ old_method_missing( sym, args )
191
+ end
192
+ end
193
+
194
+ def key?( name )
195
+ key == eval( "Qt::Key_#{name.to_s.camelize}" )
196
+ end
197
+
198
+ end
199
+
200
+ class Rect
201
+ alias_method :old_inspect, :inspect
202
+ def inspect
203
+ "#<Qt::Rect x=#{self.x} y=#{self.y} w=#{self.width} h=#{self.height}>"
204
+ end
205
+ end
206
+
207
+ class Region
208
+ def inspect
209
+ "#<Qt::Region bounding_rect=#{self.bounding_rect.inspect}>"
210
+ end
211
+ end
212
+
213
+ class TabWidget
214
+ include Enumerable
215
+ def each_tab( &block )
216
+ save_index = self.current_index
217
+ (0...self.count).each do |i|
218
+ yield( self.widget(i) )
219
+ end
220
+ end
221
+ alias_method :each, :each_tab
222
+ end
223
+
224
+ class Variant
225
+ # return an empty variant
226
+ def self.invalid
227
+ @@invalid ||= Variant.new
228
+ end
229
+
230
+ # because the qtruby inspect doesn't provide the value
231
+ alias_method :old_inspect, :inspect
232
+ def inspect
233
+ "#<Qt::Variant value=#{self.value} typeName=#{self.typeName}>"
234
+ end
235
+
236
+ # return the string of the value of this variant
237
+ def to_s
238
+ self.value.to_s
239
+ end
240
+ end
241
+
242
+ class Widget
243
+ # add a signal with the given signature, and create
244
+ # a method called method_name which will return the signal
245
+ # ready to be used in a connect. If method_name is not provided
246
+ # the method will be named as the name part of signature
247
+ def self.construct_signal( signature, method_name = nil )
248
+ # add the signal
249
+ q_signal( signature )
250
+
251
+ # add an accessor method that returns the result of SIGNAL
252
+ if method_name.nil?
253
+ md = /([\w_]+) *\(/.match( signature )
254
+ base_method_name = md[1]
255
+ method_name = base_method_name + '_signal'
256
+ end
257
+
258
+ # create the accessor method which returns
259
+ # a signal ready to be connected
260
+ define_method method_name do
261
+ SIGNAL( signature )
262
+ end
263
+
264
+ # TODO create the connection method
265
+ end
266
+ end
267
+
268
+ end
269
+
@@ -0,0 +1,101 @@
1
+ require 'Qt4'
2
+
3
+ =begin rdoc
4
+ The Qt bindings look up constants for each call. This module
5
+ caches the constant values. Most of these are called for each
6
+ cell in a table, so caching them gives us a good performance
7
+ increase.
8
+ =end
9
+ module QtFlags
10
+ def item_boolean_flags
11
+ @item_boolean_flags ||= Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable
12
+ end
13
+
14
+ def qt_item_is_editable
15
+ @qt_item_is_editable ||= Qt::ItemIsEditable
16
+ end
17
+
18
+ def qt_display_role
19
+ @qt_display_role ||= Qt::DisplayRole
20
+ end
21
+
22
+ def qt_edit_role
23
+ @qt_edit_role ||= Qt::EditRole
24
+ end
25
+
26
+ def qt_paste_role
27
+ @qt_paste_role ||= Qt::PasteRole
28
+ end
29
+
30
+ def qt_checkstate_role
31
+ @qt_checkstate_role ||= Qt::CheckStateRole
32
+ end
33
+
34
+ def qt_text_alignment_role
35
+ @qt_text_alignment_role ||= Qt::TextAlignmentRole
36
+ end
37
+
38
+ def qt_size_hint_role
39
+ @qt_size_hint_role ||= Qt::SizeHintRole
40
+ end
41
+
42
+ def qt_checked
43
+ @qt_checked ||= Qt::Checked
44
+ end
45
+
46
+ def qt_unchecked
47
+ @qt_unchecked ||= Qt::Unchecked
48
+ end
49
+
50
+ def qt_alignleft
51
+ @qt_alignleft ||= Qt::AlignLeft
52
+ end
53
+
54
+ def qt_alignright
55
+ @qt_alignright ||= Qt::AlignRight
56
+ end
57
+
58
+ def qt_aligncenter
59
+ @qt_aligncenter ||= Qt::AlignCenter
60
+ end
61
+
62
+ def qt_decoration_role
63
+ @qt_decoration_role ||= Qt::DecorationRole
64
+ end
65
+
66
+ def qt_background_role
67
+ @qt_background_role ||= Qt::BackgroundRole
68
+ end
69
+
70
+ def qt_font_role
71
+ @qt_font_role ||= Qt::FontRole
72
+ end
73
+
74
+ def qt_foreground_role
75
+ @qt_foreground_role ||= Qt::ForegroundRole
76
+ end
77
+
78
+ def qt_tooltip_role
79
+ @qt_tooltip_role ||= Qt::ToolTipRole
80
+ end
81
+
82
+ # ewww
83
+ def const_as_string( constant )
84
+ case constant
85
+ when qt_text_alignment_role; 'Qt::TextAlignmentRole'
86
+ when qt_checkstate_role; 'Qt::CheckStateRole'
87
+ when qt_edit_role; 'Qt:EditRole'
88
+ when qt_display_role; 'Qt::DisplayRole'
89
+ when Qt::ToolTipRole; 'Qt::ToolTipRole'
90
+ when Qt::StatusTipRole; 'Qt::StatusTipRole'
91
+ when Qt::DecorationRole; 'Qt::DecorationRole'
92
+ when Qt::BackgroundRole; 'Qt::BackgroundRole'
93
+ when Qt::FontRole; 'Qt::FontRole'
94
+ when Qt::ForegroundRole; 'Qt::ForegroundRole'
95
+ when Qt::TextColorRole; 'Qt::TextColorRole'
96
+
97
+ else "#{constant} unknown"
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,9 @@
1
+ module Qtext #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 3
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/qtext'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestQtext < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qtext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - FIXME full name
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-17 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
25
+ description: description of gem
26
+ email:
27
+ - panic@semiosix.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.txt
34
+ files:
35
+ - README.txt
36
+ - lib/qtext.rb
37
+ - lib/qtext/version.rb
38
+ - lib/qtext/flags.rb
39
+ - lib/qtext/extensions.rb
40
+ has_rdoc: true
41
+ homepage: http://qtext.rubyforge.org
42
+ post_install_message: |+
43
+
44
+ For more information on qtext, see http://qtext.rubyforge.org
45
+
46
+ NOTE: Change this information in PostInstall.txt
47
+ You can also delete it if you don't want it.
48
+
49
+
50
+ rdoc_options:
51
+ - --main
52
+ - README.txt
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: qtext
70
+ rubygems_version: 1.2.0
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: description of gem
74
+ test_files:
75
+ - test/test_qtext.rb
76
+ - test/test_helper.rb