Class: AnalogClock
- Inherits:
-
Qt::Widget
- Object
- Qt::Base
- Qt::Widget
- AnalogClock
- Defined in:
- ext/ruby/qtruby/examples/widgets/analogclock/analogclock.rb
Overview
an analog clock widget using an internal Qt::Timer
Instance Method Summary collapse
-
#initialize(parent = nil) ⇒ AnalogClock
constructor
A new instance of AnalogClock.
- #paintEvent(e) ⇒ Object
Methods inherited from Qt::Widget
Methods inherited from Qt::Base
#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~
Constructor Details
#initialize(parent = nil) ⇒ AnalogClock
Returns a new instance of AnalogClock.
33 34 35 36 37 38 39 40 41 42 |
# File 'ext/ruby/qtruby/examples/widgets/analogclock/analogclock.rb', line 33 def initialize(parent = nil) super(parent) @timer = Qt::Timer.new(self) connect(@timer, SIGNAL('timeout()'), self, SLOT('update()')) @timer.start(1000) setWindowTitle(tr("Analog Clock")) resize(200, 200) end |
Instance Method Details
#paintEvent(e) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'ext/ruby/qtruby/examples/widgets/analogclock/analogclock.rb', line 44 def paintEvent(e) hourHand = Qt::Polygon.new( [ Qt::Point.new(7, 8), Qt::Point.new(-7, 8), Qt::Point.new(0, -40) ] ) minuteHand = Qt::Polygon.new( [ Qt::Point.new(7, 8), Qt::Point.new(-7, 8), Qt::Point.new(0, -70) ] ) hourColor = Qt::Color.new(127, 0, 127) minuteColor = Qt::Color.new(0, 127, 127, 191) side = width() < height() ? width() : height() time = Qt::Time.currentTime painter = Qt::Painter.new(self) painter.renderHint = Qt::Painter::Antialiasing painter.translate(width() / 2, height() / 2) painter.scale(side / 200.0, side / 200.0) painter.pen = Qt::NoPen painter.brush = Qt::Brush.new(hourColor) painter.save painter.rotate(30.0 * ((time.hour + time.minute / 60.0))) painter.drawConvexPolygon(hourHand) painter.restore painter.pen = hourColor (0...12).each do |i| painter.drawLine(88, 0, 96, 0) painter.rotate(30.0) end painter.pen = Qt::NoPen painter.brush = Qt::Brush.new(minuteColor) painter.save painter.rotate(6.0 * (time.minute + time.second / 60.0)) painter.drawConvexPolygon(minuteHand) painter.restore painter.pen = minuteColor (0...60).each do |j| if (j % 5) != 0 painter.drawLine(92, 0, 96, 0) end painter.rotate(6.0) end painter.end end |