1 require 'plugins/plugin'
2 require 'constrained_text_item'
3 require 'board/item_bag'
5 class DigitalClock < Qt::GraphicsItemGroup
11 plugin :name => 'Digital Clock',
12 :keywords => %w(clock)
14 attr_reader :items, :rect
17 BASE_DIR = File.dirname(__FILE__)
18 ACTIVE_SKIN_RENDERER = Qt::SvgRenderer.new(
19 File.join(BASE_DIR, 'active_clock.svg'))
20 INACTIVE_SKIN_RENDERER = Qt::SvgRenderer.new(
21 File.join(BASE_DIR, 'inactive_clock.svg'))
24 super(nil, @scene = scene)
27 :time => ConstrainedTextItem.new(OFF_TEXT, self),
28 :player => ConstrainedTextItem.new('', self),
29 :caption => ConstrainedTextItem.new('', self)
35 def set_geometry(rect)
36 @rect = Qt::RectF.new(rect)
37 self.pos = @rect.top_left
43 add_item :skin, skin, :z => BACKGROUND_ZVALUE
44 @items[:time].constraint = Qt::RectF.new(
45 @rect.width * 0.4, @rect.height * 0.1,
46 @rect.width * 0.6, @rect.height * 0.62)
47 @items[:caption].constraint = Qt::RectF.new(
48 @rect.width * 0.02, @rect.height * 0.22,
49 @rect.width * 0.4, @rect.height * 0.38)
50 @items[:player].constraint = Qt::RectF.new(
51 @rect.width * 0.14, @rect.height * 0.68,
52 @rect.width * 0.69, @rect.height * 0.28)
58 @clock.delete_observer(self)
62 clock.add_observer(self)
67 min = data[:main] / 60
68 sec = data[:main] % 60
70 @items[:time].text = "%02d:%02d" % [min, sec]
77 INACTIVE_SKIN_RENDERER
79 Qt::Image.from_renderer(@rect.size, renderer).to_pix
83 @clock.start if @clock
102 @caption = d[:color].to_s.capitalize
103 @player = d[:player] || '(unknown)'
105 items[:caption].text = @caption
106 items[:player].text = @player