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
84 include PrintablePoint
87 Qt::Point.new(x.to_i, y.to_i)
92 include PrintablePoint
104 include PrintableRect
108 include PrintableRect
112 def self.from_svg(size, file, id = nil)
113 from_renderer(size, Qt::SvgRenderer.new(file), id)
116 def self.from_renderer(size, renderer, id = nil)
117 Qt::Image.from_renderer(size, renderer, id).to_pix
122 def self.signal_map(sigmap)
124 signals *sigmap.map{|k, v| v || k }
127 def self.get_signal(sig)
128 (@signal_map || {})[sig] || sig
132 connect(SIGNAL(self.class.get_signal(sig)), &blk)
135 def in(interval, &blk)
136 Qt::Timer.in(interval, self, &blk)
145 def self.every(interval, &blk)
150 timer.connect(SIGNAL('timeout()')) { blk[time.elapsed] }
151 timer.start(interval)
152 # return the timer, so that the caller
153 # has a chance to keep it referenced, so
154 # that it is not garbage collected
158 def self.in(interval, target = nil, &blk)
159 single_shot(interval,
160 Qt::BlockInvocation.new(target, blk, 'invoke()'),
165 class KDE::Application
167 about = KDE::AboutData.new(
173 KDE::AboutData::License_GPL,
175 data[:authors].each do |name, email|
176 about.addAuthor(name, KDE::LocalizedString.new, email)
178 data[:contributors].each do |name, contribution|
179 about.addCredit(name, contribution)
181 about.bug_address = Qt::ByteArray.new(data[:bug_tracker])
183 KDE::CmdLineArgs.init(ARGV, about)
184 KDE::CmdLineOptions.new.tap do |opts|
185 data[:options].each do |opt, desc|
188 KDE::CmdLineArgs.add_cmd_line_options opts
196 def std_action(action, opts = {}, &blk)
197 target, slot = get_slot(opts[:slot], &blk)
198 KDE::StandardAction.send(action, target, slot, action_collection)
201 def get_slot(s = nil, &blk)
202 target, slot = if block_given?
203 [Qt::BlockInvocation.new(self, blk, 'invoke()'), SLOT(:invoke)]
209 def regular_action(name, opts, &blk)
210 icon = if opts[:icon]
215 KDE::Icon.new(opts[:icon].to_s)
219 KDE::Action.new(icon, opts[:text], self).tap do |a|
220 action_collection.add_action(name.to_s, a)
221 target, slot = get_slot(opts[:slot], &blk)
222 connect(a, SIGNAL('triggered(bool)'), target, slot)