92 QWidget *widget = new QWidget(); |
92 QWidget *widget = new QWidget(); |
93 QBoxLayout *box = new QBoxLayout(dir); |
93 QBoxLayout *box = new QBoxLayout(dir); |
94 widget->setLayout(box); |
94 widget->setLayout(box); |
95 ctn->add(widget, true); |
95 ctn->add(widget, true); |
96 |
96 |
97 |
97 ui_container_add(obj, new UiBoxContainer(box)); |
98 |
98 |
99 return widget; |
99 return widget; |
100 } |
100 } |
101 |
101 |
102 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) { |
102 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) { |
104 } |
104 } |
105 |
105 |
106 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) { |
106 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) { |
107 return ui_box(obj, args, QBoxLayout::LeftToRight); |
107 return ui_box(obj, args, QBoxLayout::LeftToRight); |
108 } |
108 } |
|
109 |
|
110 |
|
111 /* -------------------- UiGridContainer -------------------- */ |
|
112 |
|
113 UiGridContainer::UiGridContainer(QGridLayout* grid, int margin, int columnspacing, int rowspacing) { |
|
114 this->current = NULL; |
|
115 this->grid = grid; |
|
116 grid->setContentsMargins(QMargins(margin, margin, margin, margin)); |
|
117 grid->setHorizontalSpacing(columnspacing); |
|
118 grid->setVerticalSpacing(rowspacing); |
|
119 ui_reset_layout(layout); |
|
120 } |
|
121 |
|
122 void UiGridContainer::add(QWidget* widget, bool fill) { |
|
123 if(layout.newline) { |
|
124 x = 0; |
|
125 y++; |
|
126 } |
|
127 |
|
128 Qt::Alignment alignment = Qt::AlignTop; |
|
129 grid->setColumnStretch(x, layout.hexpand ? 1 : 0); |
|
130 if(layout.vexpand) { |
|
131 grid->setRowStretch(y, 1); |
|
132 alignment = 0; |
|
133 } else { |
|
134 grid->setRowStretch(y, 0); |
|
135 } |
|
136 |
|
137 int colspan = layout.colspan > 0 ? layout.colspan : 1; |
|
138 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; |
|
139 |
|
140 grid->addWidget(widget, y, x, rowspan, colspan, alignment); |
|
141 x += colspan; |
|
142 |
|
143 ui_reset_layout(layout); |
|
144 current = widget; |
|
145 } |
|
146 |
|
147 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) { |
|
148 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); |
|
149 UI_APPLY_LAYOUT(ctn->layout, args); |
|
150 |
|
151 QWidget *widget = new QWidget(); |
|
152 QGridLayout *grid = new QGridLayout(); |
|
153 widget->setLayout(grid); |
|
154 ctn->add(widget, true); |
|
155 |
|
156 ui_container_add(obj, new UiGridContainer(grid, args.margin, args.columnspacing, args.rowspacing)); |
|
157 |
|
158 return widget; |
|
159 } |
|
160 |
|
161 |
|
162 |
|
163 /* -------------------- Container Helper Functions -------------------- */ |
|
164 |
|
165 void ui_container_begin_close(UiObject *obj) { |
|
166 obj->container_end->close = true; |
|
167 } |
|
168 |
|
169 int ui_container_finish(UiObject *obj) { |
|
170 if(obj->container_end->close) { |
|
171 ui_end_new(obj); |
|
172 return 0; |
|
173 } |
|
174 return 1; |
|
175 } |
|
176 |
|
177 |
|
178 /* |
|
179 * -------------------- Layout Functions -------------------- |
|
180 * |
|
181 * functions for setting layout attributes for the current container |
|
182 * |
|
183 */ |
|
184 |
|
185 void ui_newline(UiObject *obj) { |
|
186 UiContainerPrivate *ct = ui_obj_container(obj); |
|
187 ct->layout.newline = TRUE; |
|
188 } |