15 def metaclass_eval(&blk)
16 metaclass.instance_eval(&blk)
37 Qt::Pixmap.from_image self
40 def self.painted(size, &blk)
41 Qt::Image.new(size.x, size.y, Qt::Image::Format_ARGB32_Premultiplied).tap do |img|
43 Qt::Painter.new(img).paint(&blk)
47 def self.from_renderer(size, renderer, id = nil)
48 img = Qt::Image.painted(size) do |p|
50 renderer.render(p, id)
61 self.x == other.x and self.y == other.y
65 "(#{self.x}, #{self.y})"
71 "[#{self.x}, #{self.y} - #{self.width}, #{self.height}]"
76 include PrintablePoint
80 include PrintablePoint
84 include PrintablePoint
100 include PrintableRect
104 def self.from_svg(size, file, id = nil)
105 from_renderer(size, Qt::SvgRenderer.new(file), id)
108 def self.from_renderer(size, renderer, id = nil)
109 Qt::Image.from_renderer(size, renderer, id).to_pix
114 def self.signal_map(sigmap)
116 signals *sigmap.map{|k, v| v || k }
119 def self.get_signal(sig)
120 (@signal_map || {})[sig] || sig
124 connect(SIGNAL(self.class.get_signal(sig)), &blk)
127 def in(interval, &blk)
128 Qt::Timer.in(interval, self, &blk)
137 def self.every(interval, &blk)
142 timer.connect(SIGNAL('timeout()')) { blk[time.elapsed] }
143 timer.start(interval)
144 # return the timer, so that the caller
145 # has a chance to keep it referenced, so
146 # that it is not garbage collected
150 def self.in(interval, target = nil, &blk)
151 single_shot(interval,
152 Qt::BlockInvocation.new(target, blk, 'invoke()'),
157 class KDE::Application
159 about = KDE::AboutData.new(
165 KDE::AboutData::License_GPL,
167 data[:authors].each do |name, email|
168 about.addAuthor(name, KDE::LocalizedString.new, email)
170 data[:contributors].each do |name, contribution|
171 about.addCredit(name, contribution)
173 about.bug_address = Qt::ByteArray.new(data[:bug_tracker])
175 KDE::CmdLineArgs.init(ARGV, about)
176 KDE::CmdLineOptions.new.tap do |opts|
177 data[:options].each do |opt, desc|
180 KDE::CmdLineArgs.add_cmd_line_options opts
188 def std_action(action, opts = {}, &blk)
189 target, slot = get_slot(opts[:slot], &blk)
190 KDE::StandardAction.send(action, target, slot, action_collection)
193 def get_slot(s = nil, &blk)
194 target, slot = if block_given?
195 [Qt::BlockInvocation.new(self, blk, 'invoke()'), SLOT(:invoke)]
201 def regular_action(name, opts, &blk)
202 icon = if opts[:icon]
207 KDE::Icon.new(opts[:icon].to_s)
211 KDE::Action.new(icon, opts[:text], self).tap do |a|
212 action_collection.add_action(name.to_s, a)
213 target, slot = get_slot(opts[:slot], &blk)
214 connect(a, SIGNAL('triggered(bool)'), target, slot)