| 40 |
40 |
| 41 static void delete_container(UiContainerPrivate *ct) { |
41 static void delete_container(UiContainerPrivate *ct) { |
| 42 delete ct; |
42 delete ct; |
| 43 } |
43 } |
| 44 |
44 |
| 45 void ui_container_add(UiObject *obj, UiContainerPrivate *ct) { |
45 void ui_obj_add_container(UiObject *obj, UiContainerPrivate *ct) { |
| 46 UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX)); |
46 UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX)); |
| 47 container->close = 0; |
47 container->close = 0; |
| 48 container->container = ct; |
48 container->container = ct; |
| 49 container->prev = NULL; |
49 container->prev = NULL; |
| 50 container->next = NULL; |
50 container->next = NULL; |
| 51 ct->container = container; |
51 ct->container = container; |
| 52 cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container); |
52 cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container); |
| 53 uic_object_push_container(obj, container); |
53 uic_object_push_container(obj, container); |
| 54 } |
54 } |
| 55 |
55 |
| |
56 /* ------------------------ margin helper ------------------------ */ |
| |
57 |
| |
58 QWidget* ui_widget_set_margin(QWidget *w, int left, int right, int top, int bottom) { |
| |
59 if((left | right | top | bottom) == 0) { |
| |
60 return w; |
| |
61 } |
| |
62 QWidget* wrapper = new QWidget; |
| |
63 QVBoxLayout* inner = new QVBoxLayout(wrapper); |
| |
64 inner->setContentsMargins(left, top, right, bottom); |
| |
65 inner->addWidget(w); |
| |
66 |
| |
67 // TODO: handle widget visibility changes |
| |
68 |
| |
69 return wrapper; |
| |
70 } |
| |
71 |
| 56 /* -------------------- UiBoxContainer -------------------- */ |
72 /* -------------------- UiBoxContainer -------------------- */ |
| 57 |
73 |
| 58 UiBoxContainer::UiBoxContainer(QBoxLayout* box) { |
74 UiBoxContainer::UiBoxContainer(QBoxLayout* box) { |
| 59 this->box = box; |
75 this->box = box; |
| |
76 this->direction = box->direction(); |
| 60 box->setContentsMargins(QMargins(0,0,0,0)); |
77 box->setContentsMargins(QMargins(0,0,0,0)); |
| 61 box->setSpacing(0); |
78 box->setSpacing(0); |
| 62 } |
79 } |
| 63 |
80 |
| 64 void UiBoxContainer::add(QWidget* widget, UiLayout& layout) { |
81 void UiBoxContainer::add(QWidget* widget, UiLayout& layout) { |
| 66 if(hasStretchedWidget && fill) { |
83 if(hasStretchedWidget && fill) { |
| 67 fill = false; |
84 fill = false; |
| 68 fprintf(stderr, "UiError: container has 2 filled widgets"); |
85 fprintf(stderr, "UiError: container has 2 filled widgets"); |
| 69 } |
86 } |
| 70 |
87 |
| |
88 uic_layout_setup_margin(&layout); |
| |
89 widget = ui_widget_set_margin(widget, layout.margin_left, layout.margin_right, layout.margin_top, layout.margin_bottom); |
| 71 box->addWidget(widget); |
90 box->addWidget(widget); |
| |
91 if(direction == Qt::LeftToRight) { |
| |
92 box->setAlignment(widget, Qt::AlignTop); |
| |
93 } |
| 72 |
94 |
| 73 if(!hasStretchedWidget) { |
95 if(!hasStretchedWidget) { |
| 74 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
96 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
| 75 box->removeItem(space); |
97 box->removeItem(space); |
| 76 box->addSpacerItem(newspace); |
98 box->addSpacerItem(newspace); |
| 90 QWidget *widget = new QWidget(); |
112 QWidget *widget = new QWidget(); |
| 91 QBoxLayout *box = new QBoxLayout(dir); |
113 QBoxLayout *box = new QBoxLayout(dir); |
| 92 widget->setLayout(box); |
114 widget->setLayout(box); |
| 93 ctn->add(widget, layout); |
115 ctn->add(widget, layout); |
| 94 |
116 |
| 95 ui_container_add(obj, new UiBoxContainer(box)); |
117 ui_obj_add_container(obj, new UiBoxContainer(box)); |
| 96 |
118 |
| 97 return widget; |
119 return widget; |
| 98 } |
120 } |
| 99 |
121 |
| 100 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
122 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
| 135 y++; |
157 y++; |
| 136 container->newline = false; |
158 container->newline = false; |
| 137 } |
159 } |
| 138 |
160 |
| 139 uic_layout_setup_expand_fill(&layout, def_hexpand, def_vexpand, def_hfill, def_vfill); |
161 uic_layout_setup_expand_fill(&layout, def_hexpand, def_vexpand, def_hfill, def_vfill); |
| |
162 uic_layout_setup_margin(&layout); |
| 140 |
163 |
| 141 if(layout.hexpand) { |
164 if(layout.hexpand) { |
| 142 col_expanding = true; |
165 col_expanding = true; |
| 143 } |
166 } |
| 144 if(layout.vexpand) { |
167 if(layout.vexpand) { |
| 161 } |
184 } |
| 162 |
185 |
| 163 int colspan = layout.colspan > 0 ? layout.colspan : 1; |
186 int colspan = layout.colspan > 0 ? layout.colspan : 1; |
| 164 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; |
187 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; |
| 165 |
188 |
| |
189 widget = ui_widget_set_margin(widget, layout.margin_left, layout.margin_right, layout.margin_top, layout.margin_bottom); |
| 166 grid->addWidget(widget, y, x, rowspan, colspan, alignment); |
190 grid->addWidget(widget, y, x, rowspan, colspan, alignment); |
| 167 |
191 |
| 168 if(x > max_x) { |
192 if(x > max_x) { |
| 169 max_x = x; |
193 max_x = x; |
| 170 } |
194 } |
| 199 QWidget *widget = new QWidget(); |
223 QWidget *widget = new QWidget(); |
| 200 QGridLayout *grid = new QGridLayout(); |
224 QGridLayout *grid = new QGridLayout(); |
| 201 widget->setLayout(grid); |
225 widget->setLayout(grid); |
| 202 ctn->add(widget, layout); |
226 ctn->add(widget, layout); |
| 203 |
227 |
| 204 ui_container_add(obj, new UiGridContainer( |
228 ui_obj_add_container(obj, new UiGridContainer( |
| 205 grid, |
229 grid, |
| 206 args->margin, |
230 args->margin, |
| 207 args->columnspacing, |
231 args->columnspacing, |
| 208 args->rowspacing, |
232 args->rowspacing, |
| 209 args->def_hexpand, |
233 args->def_hexpand, |
| 228 QWidget *widget = new QWidget(); |
252 QWidget *widget = new QWidget(); |
| 229 QBoxLayout *box = new QBoxLayout(QBoxLayout::TopToBottom); |
253 QBoxLayout *box = new QBoxLayout(QBoxLayout::TopToBottom); |
| 230 widget->setLayout(box); |
254 widget->setLayout(box); |
| 231 dock->setWidget(widget); |
255 dock->setWidget(widget); |
| 232 |
256 |
| 233 ui_container_add(obj, new UiBoxContainer(box)); |
257 ui_obj_add_container(obj, new UiBoxContainer(box)); |
| 234 |
258 |
| 235 return dock; |
259 return dock; |
| 236 } |
260 } |
| 237 |
261 |
| 238 /* -------------------- Container Helper Functions -------------------- */ |
262 /* -------------------- Container Helper Functions -------------------- */ |