1 class ConstrainedTextItem < Qt::GraphicsItem
2 def initialize(text, parent, constraint, opts = {})
6 @constraint = constraint
8 @font = opts[:font] || Qt::Font.new
9 @color = opts[:color] || Qt::Color.new(Qt::black)
11 @brect = Qt::FontMetrics.new(@font).bounding_rect(@text)
13 0.9 * @constraint.width / @brect.width,
14 @constraint.height / @brect.height].min
17 def paint(p, opts, widget)
20 p.draw_rect @constraint
22 p.translate(@constraint.center)
23 p.scale(@factor, @factor)
24 p.translate(-@brect.center)
25 p.draw_text(0, 0, @text)