1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 require 'plugins/plugin'
10 require 'constrained_text_item'
11 require 'board/item_bag'
12 require 'observer_utils'
14 class DigitalClock < Qt::GraphicsItemGroup
20 plugin :name => 'Digital Clock',
23 attr_reader :items, :rect, :clock
26 BASE_DIR = File.dirname(__FILE__)
27 ACTIVE_SKIN_RENDERER = Qt::SvgRenderer.new(
28 File.join(BASE_DIR, 'active_clock.svg'))
29 INACTIVE_SKIN_RENDERER = Qt::SvgRenderer.new(
30 File.join(BASE_DIR, 'inactive_clock.svg'))
33 super(nil, @scene = scene)
36 :time => ConstrainedTextItem.new(OFF_TEXT, self),
37 :player => ConstrainedTextItem.new('', self),
38 :caption => ConstrainedTextItem.new('', self)
44 def set_geometry(rect)
45 @rect = Qt::RectF.new(rect)
46 self.pos = @rect.top_left
52 add_item :skin, skin, :z => BACKGROUND_ZVALUE
53 @items[:time].constraint = Qt::RectF.new(
54 @rect.width * 0.4, @rect.height * 0.1,
55 @rect.width * 0.6, @rect.height * 0.62)
56 @items[:caption].constraint = Qt::RectF.new(
57 @rect.width * 0.02, @rect.height * 0.22,
58 @rect.width * 0.4, @rect.height * 0.38)
59 @items[:player].constraint = Qt::RectF.new(
60 @rect.width * 0.14, @rect.height * 0.68,
61 @rect.width * 0.69, @rect.height * 0.28)
67 @clock.delete_observer(self)
71 clock.add_observer(self)
76 min = data[:main] / 60
77 sec = data[:main] % 60
79 @items[:time].text = "%02d:%02d" % [min, sec]
86 INACTIVE_SKIN_RENDERER
88 Qt::Image.from_renderer(@rect.size, renderer).to_pix
92 @clock.start if @clock
111 @caption = d[:color].to_s.capitalize
112 @player = d[:player] || '(unknown)'
114 items[:caption].text = @caption
115 items[:player].text = @player