Class: FlowLayout
- Defined in:
- ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb
Instance Method Summary collapse
- #addItem(item) ⇒ Object
- #count ⇒ Object
- #doLayout(rect, testOnly) ⇒ Object
- #expandingDirections ⇒ Object
- #hasHeightForWidth ⇒ Object
- #heightForWidth(width) ⇒ Object
-
#initialize(parent = nil, spacing = -1)) ⇒ FlowLayout
constructor
A new instance of FlowLayout.
- #itemAt(index) ⇒ Object
- #minimumSize ⇒ Object
- #setGeometry(rect) ⇒ Object
- #sizeHint ⇒ Object
- #takeAt(index) ⇒ Object
Constructor Details
#initialize(parent = nil, spacing = -1)) ⇒ FlowLayout
Returns a new instance of FlowLayout.
29 30 31 32 33 34 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 29 def initialize(parent = nil, spacing = -1) super(parent) # setMargin(margin) setSpacing(spacing) @itemList = [] end |
Instance Method Details
#addItem(item) ⇒ Object
36 37 38 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 36 def addItem(item) @itemList << item end |
#count ⇒ Object
40 41 42 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 40 def count() return @itemList.length() end |
#doLayout(rect, testOnly) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 85 def doLayout(rect, testOnly) x = rect.x y = rect.y lineHeight = 0 @itemList.each do |item| nextX = x + item.sizeHint().width() + spacing() if nextX - spacing() > rect.right() && lineHeight > 0 x = rect.x() y = y + lineHeight + spacing() nextX = x + item.sizeHint().width() + spacing() lineHeight = 0 end if !testOnly item.setGeometry(Qt::Rect.new(Qt::Point.new(x, y), item.sizeHint())) end x = nextX lineHeight = [lineHeight, item.sizeHint().height()].max end return y + lineHeight - rect.y() end |
#expandingDirections ⇒ Object
56 57 58 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 56 def () return 0 end |
#hasHeightForWidth ⇒ Object
60 61 62 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 60 def hasHeightForWidth() return true end |
#heightForWidth(width) ⇒ Object
64 65 66 67 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 64 def heightForWidth(width) height = doLayout(Qt::Rect.new(0, 0, width, 0), true) return height end |
#itemAt(index) ⇒ Object
44 45 46 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 44 def itemAt(index) return @itemList[index] end |
#minimumSize ⇒ Object
78 79 80 81 82 83 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 78 def minimumSize() size = Qt::Size.new @itemList.each { |item| size = size.(item.minimumSize()) } size += Qt::Size.new(2*margin(), 2*margin()) return size end |
#setGeometry(rect) ⇒ Object
69 70 71 72 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 69 def setGeometry(rect) super(rect) doLayout(rect, false) end |
#sizeHint ⇒ Object
74 75 76 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 74 def sizeHint() return minimumSize() end |
#takeAt(index) ⇒ Object
48 49 50 51 52 53 54 |
# File 'ext/ruby/qtruby/examples/layouts/flowlayouts/flowlayout.rb', line 48 def takeAt(index) if index >= 0 && index < @itemList.length return @itemList.delete_at(index) else return nil end end |