ui/qt/container.cpp

changeset 115
e57ca2747782
parent 112
c3f2f16fa4b8
equal deleted inserted replaced
114:3da24640513a 115:e57ca2747782
80 80
81 void UiBoxContainer::add(QWidget* widget, UiLayout& layout) { 81 void UiBoxContainer::add(QWidget* widget, UiLayout& layout) {
82 bool fill = layout.fill; 82 bool fill = layout.fill;
83 if(hasStretchedWidget && fill) { 83 if(hasStretchedWidget && fill) {
84 fill = false; 84 fill = false;
85 fprintf(stderr, "UiError: container has 2 filled widgets"); 85 fprintf(stderr, "UiError: container has 2 filled widgets\n");
86 }
87
88 if(singleChild) {
89 fill = true;
90 if(hasChild) {
91 fprintf(stderr, "UiError: single child container already has a child\n");
92 }
86 } 93 }
87 94
88 uic_layout_setup_margin(&layout); 95 uic_layout_setup_margin(&layout);
89 widget = ui_widget_set_margin(widget, layout.margin_left, layout.margin_right, layout.margin_top, layout.margin_bottom); 96 widget = ui_widget_set_margin(widget, layout.margin_left, layout.margin_right, layout.margin_top, layout.margin_bottom);
90 box->addWidget(widget); 97 box->addWidget(widget);
101 108
102 if(fill) { 109 if(fill) {
103 hasStretchedWidget = true; 110 hasStretchedWidget = true;
104 } 111 }
105 current = widget; 112 current = widget;
113 hasChild = true;
106 } 114 }
107 115
108 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) { 116 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) {
109 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); 117 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
110 UiLayout layout = UI_ARGS2LAYOUT(args); 118 UiLayout layout = UI_ARGS2LAYOUT(args);
237 245
238 return widget; 246 return widget;
239 } 247 }
240 248
241 249
250 /* ------------------------------ Frame ------------------------------ */
251
252 UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) {
253 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
254 UiLayout layout = UI_ARGS2LAYOUT(args);
255
256 bool createBox = true;
257 bool singleChild = false;
258 QBoxLayout::Direction dir = QBoxLayout::TopToBottom;
259 QGroupBox *widget = new QGroupBox();
260 if(args->label) {
261 widget->setTitle(args->label);
262 }
263
264 switch(args->subcontainer) {
265 default: break;
266 case UI_CONTAINER_HBOX: {
267 dir = QBoxLayout::LeftToRight;
268 break;
269 }
270 case UI_CONTAINER_GRID: {
271 createBox = false;
272 break;
273 }
274 case UI_CONTAINER_NO_SUB: {
275 singleChild = true;
276 }
277 }
278
279 if(createBox) {
280 QBoxLayout *box = new QBoxLayout(dir);
281 widget->setLayout(box);
282
283 UiBoxContainer *container = new UiBoxContainer(box);
284 ui_obj_add_container(obj, container);
285
286 container->singleChild = singleChild;
287 } else {
288 QGridLayout *grid = new QGridLayout();
289 widget->setLayout(grid);
290
291 ui_obj_add_container(obj, new UiGridContainer(
292 grid,
293 args->padding,
294 args->columnspacing,
295 args->rowspacing,
296 false,
297 false,
298 false,
299 false));
300 }
301
302
303 ctn->add(widget, layout);
304
305 return widget;
306 }
307
242 /* ---------------------------- UiSidebar ---------------------------- */ 308 /* ---------------------------- UiSidebar ---------------------------- */
243 309
244 UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs *args) { 310 UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs *args) {
245 QVariant v = obj->widget->property("ui_sidebar"); 311 QVariant v = obj->widget->property("ui_sidebar");
246 QDockWidget *dock = (QDockWidget*)v.value<void*>(); 312 QDockWidget *dock = (QDockWidget*)v.value<void*>();

mercurial