Class: BorderLayout
- Defined in:
- ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb
Defined Under Namespace
Classes: ItemWrapper
Constant Summary collapse
- West =
0
- North =
1
- South =
2
- East =
3
- Center =
4
- MinimumSize =
0
- SizeHint =
1
Instance Method Summary collapse
- #add(item, position) ⇒ Object
-
#addItem(item) ⇒ Object
def initialize(spacing) setSpacing(spacing) end.
- #addWidget(widget, position) ⇒ Object
- #calculateSize(sizeType) ⇒ Object
- #count ⇒ Object
- #expandingDirections ⇒ Object
- #hasHeightForWidth ⇒ Object
-
#initialize(parent = nil, margin = 0, spacing = -1)) ⇒ BorderLayout
constructor
A new instance of BorderLayout.
- #itemAt(index) ⇒ Object
- #minimumSize ⇒ Object
- #setGeometry(rect) ⇒ Object
- #sizeHint ⇒ Object
- #takeAt(index) ⇒ Object
Constructor Details
#initialize(parent = nil, margin = 0, spacing = -1)) ⇒ BorderLayout
Returns a new instance of BorderLayout.
39 40 41 42 43 44 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 39 def initialize(parent = nil, margin = 0, spacing = -1) @list = [] super(parent) setMargin(margin) setSpacing(spacing) end |
Instance Method Details
#add(item, position) ⇒ Object
163 164 165 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 163 def add(item, position) @list << ItemWrapper.new(item, position) end |
#addItem(item) ⇒ Object
def initialize(spacing)
setSpacing(spacing)
end
50 51 52 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 50 def addItem(item) add(item, West) end |
#addWidget(widget, position) ⇒ Object
54 55 56 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 54 def addWidget(, position) add(Qt::WidgetItem.new(), position) end |
#calculateSize(sizeType) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 167 def calculateSize(sizeType) totalSize = Qt::Size.new (0...@list.length).each do |i| wrapper = @list[i] position = wrapper.position if sizeType == MinimumSize itemSize = wrapper.item.minimumSize else # (sizeType == SizeHint) itemSize = wrapper.item.sizeHint end if position == North || position == South || position == Center totalSize.height += itemSize.height end if position == West || position == East || position == Center totalSize.width += itemSize.width end end return totalSize end |
#count ⇒ Object
66 67 68 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 66 def count() return @list.length() end |
#expandingDirections ⇒ Object
58 59 60 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 58 def () return Qt::Horizontal | Qt::Vertical end |
#hasHeightForWidth ⇒ Object
62 63 64 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 62 def hasHeightForWidth() return false end |
#itemAt(index) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 70 def itemAt(index) wrapper = @list[index] if !wrapper.nil? return wrapper.item else return nil end end |
#minimumSize ⇒ Object
79 80 81 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 79 def minimumSize() return calculateSize(MinimumSize) end |
#setGeometry(rect) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 83 def setGeometry(rect) center = 0 eastWidth = 0 westWidth = 0 northHeight = 0 southHeight = 0 centerHeight = 0 super(rect) (0...@list.length).each do |i| wrapper = @list[i] item = wrapper.item position = wrapper.position if position == North item.geometry = Qt::Rect.new(rect.x, northHeight, rect.width, item.sizeHint.height) northHeight += item.geometry.height + spacing() elsif position == South item.geometry = Qt::Rect.new(item.geometry.x, item.geometry.y, rect.width, item.sizeHint.height) southHeight += item.geometry().height() + spacing() item.geometry = Qt::Rect.new(rect.x, rect.y + rect.height - southHeight + spacing(), item.geometry.width, item.geometry.height) elsif position == Center center = wrapper end end centerHeight = rect.height() - northHeight - southHeight (0...@list.length).each do |i| wrapper = @list[i] item = wrapper.item position = wrapper.position if position == West item.geometry = Qt::Rect.new(rect.x + westWidth, northHeight, item.sizeHint.width, centerHeight) westWidth += item.geometry.width + spacing() elsif position == East item.geometry = Qt::Rect.new(item.geometry.x, item.geometry.y, item.sizeHint.width, centerHeight) eastWidth += item.geometry.width + spacing() item.geometry = Qt::Rect.new( rect.x + rect.width - eastWidth + spacing, northHeight, item.geometry.width, item.geometry.height) end end if !center.nil? center.item.geometry = Qt::Rect.new(westWidth, northHeight, rect.width - eastWidth - westWidth, centerHeight) end end |
#sizeHint ⇒ Object
151 152 153 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 151 def sizeHint() return calculateSize(SizeHint) end |
#takeAt(index) ⇒ Object
155 156 157 158 159 160 161 |
# File 'ext/ruby/qtruby/examples/layouts/borderlayout/borderlayout.rb', line 155 def takeAt(index) if index >= 0 && index < @list.length() layoutStruct = @list.delete_at(index) return layoutStruct.item end return nil end |