class FlowLayout

Public Class Methods

new(parent = nil, spacing = -1) click to toggle source
Calls superclass method
# File examples/layouts/flowlayouts/flowlayout.rb, line 29
        def initialize(parent = nil, spacing = -1)
            super(parent)
#           setMargin(margin)
            setSpacing(spacing)
                @itemList = []
        end

Public Instance Methods

addItem(item) click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 36
def addItem(item)
    @itemList << item
end
count() click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 40
def count()
    return @itemList.length()
end
doLayout(rect, testOnly) click to toggle source
# File 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() click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 56
def expandingDirections()
    return 0
end
hasHeightForWidth() click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 60
def hasHeightForWidth()
    return true
end
heightForWidth(width) click to toggle source
# File 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) click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 44
def itemAt(index)
    return @itemList[index]
end
minimumSize() click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 78
def minimumSize()
    size = Qt::Size.new
        @itemList.each { |item| size = size.expandedTo(item.minimumSize()) }
    size += Qt::Size.new(2*margin(), 2*margin())
    return size
end
setGeometry(rect) click to toggle source
Calls superclass method
# File examples/layouts/flowlayouts/flowlayout.rb, line 69
def setGeometry(rect)
    super(rect)
    doLayout(rect, false)
end
sizeHint() click to toggle source
# File examples/layouts/flowlayouts/flowlayout.rb, line 74
def sizeHint()
    return minimumSize()
end
takeAt(index) click to toggle source
# File 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