15 def metaclass_eval(&blk)
16 metaclass.instance_eval(&blk)
24 return i if yield item
49 Qt::Pixmap.from_image self
52 def self.painted(size, &blk)
53 Qt::Image.new(size.x, size.y, Qt::Image::Format_ARGB32_Premultiplied).tap do |img|
55 Qt::Painter.new(img).paint(&blk)
59 def self.from_renderer(size, renderer, id = nil)
60 img = Qt::Image.painted(size) do |p|
62 renderer.render(p, id)
73 self.x == other.x and self.y == other.y
77 "(#{self.x}, #{self.y})"
83 "[#{self.x}, #{self.y} - #{self.width}, #{self.height}]"
88 include PrintablePoint
96 include PrintablePoint
99 Qt::Point.new(x.to_i, y.to_i)
104 include PrintablePoint
116 include PrintablePoint
128 include PrintableRect
132 include PrintableRect
136 def self.from_svg(size, file, id = nil)
137 from_renderer(size, Qt::SvgRenderer.new(file), id)
140 def self.from_renderer(size, renderer, id = nil)
141 Qt::Image.from_renderer(size, renderer, id).to_pix
146 def self.signal_map(sigmap)
148 signals *sigmap.map{|k, v| v || k }
151 def self.get_signal(sig)
152 (@signal_map || {})[sig] || sig
156 connect(SIGNAL(self.class.get_signal(sig)), &blk)
159 def in(interval, &blk)
160 Qt::Timer.in(interval, self, &blk)
169 def self.every(interval, &blk)
174 timer.connect(SIGNAL('timeout()')) { blk[time.elapsed] }
175 timer.start(interval)
176 # return the timer, so that the caller
177 # has a chance to keep it referenced, so
178 # that it is not garbage collected
182 def self.in(interval, target = nil, &blk)
183 single_shot(interval,
184 Qt::BlockInvocation.new(target, blk, 'invoke()'),
189 class KDE::Application
191 about = KDE::AboutData.new(
197 KDE::AboutData::License_GPL,
199 data[:authors].each do |name, email|
200 about.addAuthor(name, KDE::LocalizedString.new, email)
202 data[:contributors].each do |name, contribution|
203 about.addCredit(name, contribution)
205 about.bug_address = Qt::ByteArray.new(data[:bug_tracker])
207 KDE::CmdLineArgs.init(ARGV, about)
208 KDE::CmdLineOptions.new.tap do |opts|
209 data[:options].each do |opt, desc|
212 KDE::CmdLineArgs.add_cmd_line_options opts
220 def std_action(action, opts = {}, &blk)
221 target, slot = get_slot(opts[:slot], &blk)
222 KDE::StandardAction.send(action, target, slot, action_collection)
225 def get_slot(s = nil, &blk)
226 target, slot = if block_given?
227 [Qt::BlockInvocation.new(self, blk, 'invoke()'), SLOT(:invoke)]
233 def regular_action(name, opts, &blk)
234 icon = if opts[:icon]
239 KDE::Icon.new(opts[:icon].to_s)
243 KDE::Action.new(icon, opts[:text], self).tap do |a|
244 action_collection.add_action(name.to_s, a)
245 target, slot = get_slot(opts[:slot], &blk)
246 connect(a, SIGNAL('triggered(bool)'), target, slot)