3 ParseException = Class.new(Exception)
17 def metaclass_eval(&blk)
18 metaclass.instance_eval(&blk)
26 return i if yield item
51 Qt::Pixmap.from_image self
54 def self.painted(size, &blk)
55 Qt::Image.new(size.x, size.y, Qt::Image::Format_ARGB32_Premultiplied).tap do |img|
57 Qt::Painter.new(img).paint(&blk)
61 def self.from_renderer(size, renderer, id = nil)
62 img = Qt::Image.painted(size) do |p|
64 renderer.render(p, id)
75 self.x == other.x and self.y == other.y
79 "(#{self.x}, #{self.y})"
85 "[#{self.x}, #{self.y} - #{self.width}, #{self.height}]"
90 include PrintablePoint
98 include PrintablePoint
101 Qt::Point.new(x.to_i, y.to_i)
106 include PrintablePoint
118 include PrintablePoint
130 include PrintableRect
134 include PrintableRect
138 def self.from_svg(size, file, id = nil)
139 from_renderer(size, Qt::SvgRenderer.new(file), id)
142 def self.from_renderer(size, renderer, id = nil)
143 Qt::Image.from_renderer(size, renderer, id).to_pix
148 def self.signal_map(sigmap)
150 signals *sigmap.map{|k, v| v || k }
153 def self.get_signal(sig)
154 (@signal_map || {})[sig] || sig
158 connect(SIGNAL(self.class.get_signal(sig)), &blk)
161 def in(interval, &blk)
162 Qt::Timer.in(interval, self, &blk)
171 def self.every(interval, &blk)
176 timer.connect(SIGNAL('timeout()')) { blk[time.elapsed] }
177 timer.start(interval)
178 # return the timer, so that the caller
179 # has a chance to keep it referenced, so
180 # that it is not garbage collected
184 def self.in(interval, target = nil, &blk)
185 single_shot(interval,
186 Qt::BlockInvocation.new(target, blk, 'invoke()'),
192 def removing_rows(parent, first, last)
197 begin_remove_rows(parent || Qt::ModelIndex.new, first, last)
205 def inserting_rows(parent, first, last)
210 begin_insert_rows(parent || Qt::ModelIndex.new, first, last)
219 class KDE::Application
221 about = KDE::AboutData.new(
227 KDE::AboutData::License_GPL,
229 data[:authors].each do |name, email|
230 about.addAuthor(name, KDE::LocalizedString.new, email)
232 data[:contributors].each do |name, contribution|
233 about.addCredit(name, contribution)
235 about.bug_address = Qt::ByteArray.new(data[:bug_tracker])
237 KDE::CmdLineArgs.init(ARGV, about)
238 KDE::CmdLineOptions.new.tap do |opts|
239 data[:options].each do |opt, desc|
242 KDE::CmdLineArgs.add_cmd_line_options opts
250 def std_action(action, opts = {}, &blk)
251 target, slot = get_slot(opts[:slot], &blk)
252 KDE::StandardAction.method_missing(action, target, slot, action_collection)
255 def get_slot(s = nil, &blk)
256 target, slot = if block_given?
257 [Qt::BlockInvocation.new(self, blk, 'invoke()'), SLOT(:invoke)]
263 def regular_action(name, opts, &blk)
264 icon = if opts[:icon]
269 KDE::Icon.new(opts[:icon].to_s)
273 KDE::Action.new(icon, opts[:text], self).tap do |a|
274 action_collection.add_action(name.to_s, a)
275 target, slot = get_slot(opts[:slot], &blk)
276 connect(a, SIGNAL('triggered(bool)'), target, slot)