| 27 */ |
27 */ |
| 28 |
28 |
| 29 #include <stdio.h> |
29 #include <stdio.h> |
| 30 #include "container.h" |
30 #include "container.h" |
| 31 #include "../common/object.h" |
31 #include "../common/object.h" |
| |
32 #include "../common/container.h" |
| 32 |
33 |
| 33 #include <cx/mempool.h> |
34 #include <cx/mempool.h> |
| 34 |
35 |
| 35 #include <QSpacerItem> |
36 #include <QSpacerItem> |
| 36 #include <QStackedWidget> |
37 #include <QStackedWidget> |
| 45 UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX)); |
46 UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX)); |
| 46 container->close = 0; |
47 container->close = 0; |
| 47 container->container = ct; |
48 container->container = ct; |
| 48 container->prev = NULL; |
49 container->prev = NULL; |
| 49 container->next = NULL; |
50 container->next = NULL; |
| |
51 ct->container = container; |
| 50 cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container); |
52 cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container); |
| 51 uic_object_push_container(obj, container); |
53 uic_object_push_container(obj, container); |
| 52 } |
54 } |
| 53 |
55 |
| 54 /* -------------------- UiBoxContainer -------------------- */ |
56 /* -------------------- UiBoxContainer -------------------- */ |
| 55 |
57 |
| 56 UiBoxContainer::UiBoxContainer(QBoxLayout* box) { |
58 UiBoxContainer::UiBoxContainer(QBoxLayout* box) { |
| 57 this->box = box; |
59 this->box = box; |
| 58 box->setContentsMargins(QMargins(0,0,0,0)); |
60 box->setContentsMargins(QMargins(0,0,0,0)); |
| 59 box->setSpacing(0); |
61 box->setSpacing(0); |
| 60 |
62 } |
| 61 ui_reset_layout(layout); |
63 |
| 62 } |
64 void UiBoxContainer::add(QWidget* widget, UiLayout& layout) { |
| 63 |
|
| 64 void UiBoxContainer::add(QWidget* widget) { |
|
| 65 bool fill = layout.fill; |
65 bool fill = layout.fill; |
| 66 if(hasStretchedWidget && fill) { |
66 if(hasStretchedWidget && fill) { |
| 67 fill = false; |
67 fill = false; |
| 68 fprintf(stderr, "UiError: container has 2 filled widgets"); |
68 fprintf(stderr, "UiError: container has 2 filled widgets"); |
| 69 } |
69 } |
| 78 } |
78 } |
| 79 |
79 |
| 80 if(fill) { |
80 if(fill) { |
| 81 hasStretchedWidget = true; |
81 hasStretchedWidget = true; |
| 82 } |
82 } |
| 83 ui_reset_layout(layout); |
|
| 84 current = widget; |
83 current = widget; |
| 85 } |
84 } |
| 86 |
85 |
| 87 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) { |
86 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) { |
| 88 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); |
87 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); |
| 89 UI_APPLY_LAYOUT(ctn->layout, args); |
88 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 90 |
89 |
| 91 QWidget *widget = new QWidget(); |
90 QWidget *widget = new QWidget(); |
| 92 QBoxLayout *box = new QBoxLayout(dir); |
91 QBoxLayout *box = new QBoxLayout(dir); |
| 93 widget->setLayout(box); |
92 widget->setLayout(box); |
| 94 ctn->add(widget); |
93 ctn->add(widget, layout); |
| 95 |
94 |
| 96 ui_container_add(obj, new UiBoxContainer(box)); |
95 ui_container_add(obj, new UiBoxContainer(box)); |
| 97 |
96 |
| 98 return widget; |
97 return widget; |
| 99 } |
98 } |
| 126 this->def_hfill = def_hfill; |
125 this->def_hfill = def_hfill; |
| 127 this->def_vfill = def_vfill; |
126 this->def_vfill = def_vfill; |
| 128 grid->setContentsMargins(QMargins(margin, margin, margin, margin)); |
127 grid->setContentsMargins(QMargins(margin, margin, margin, margin)); |
| 129 grid->setHorizontalSpacing(columnspacing); |
128 grid->setHorizontalSpacing(columnspacing); |
| 130 grid->setVerticalSpacing(rowspacing); |
129 grid->setVerticalSpacing(rowspacing); |
| 131 ui_reset_layout(layout); |
130 } |
| 132 } |
131 |
| 133 |
132 void UiGridContainer::add(QWidget* widget, UiLayout& layout) { |
| 134 void UiGridContainer::add(QWidget* widget) { |
133 if(container->newline) { |
| 135 if(layout.newline) { |
|
| 136 x = 0; |
134 x = 0; |
| 137 y++; |
135 y++; |
| 138 } |
136 container->newline = false; |
| 139 |
137 } |
| 140 bool fill = layout.fill; |
138 |
| 141 bool hexpand = false; |
139 uic_layout_setup_expand_fill(&layout, def_hexpand, def_vexpand, def_hfill, def_vfill); |
| 142 bool vexpand = false; |
|
| 143 bool hfill = false; |
|
| 144 bool vfill = false; |
|
| 145 if(!layout.override_defaults) { |
|
| 146 if(def_hexpand) { |
|
| 147 hexpand = true; |
|
| 148 hfill = true; |
|
| 149 } else if(def_hfill) { |
|
| 150 hfill = true; |
|
| 151 } |
|
| 152 if(def_vexpand) { |
|
| 153 vexpand = true; |
|
| 154 vfill = true; |
|
| 155 } else if(def_vfill) { |
|
| 156 vfill = true; |
|
| 157 } |
|
| 158 } |
|
| 159 |
140 |
| 160 if(layout.hexpand) { |
141 if(layout.hexpand) { |
| 161 hexpand = true; |
142 col_expanding = true; |
| 162 //hfill = true; |
|
| 163 } else if(layout.hfill) { |
|
| 164 hfill = true; |
|
| 165 } |
143 } |
| 166 if(layout.vexpand) { |
144 if(layout.vexpand) { |
| 167 vexpand = true; |
|
| 168 //vfill = true; |
|
| 169 } else if(layout.vfill) { |
|
| 170 vfill = true; |
|
| 171 } |
|
| 172 if(fill) { |
|
| 173 hfill = true; |
|
| 174 vfill = true; |
|
| 175 } |
|
| 176 |
|
| 177 if(hexpand) { |
|
| 178 col_expanding = true; |
|
| 179 } |
|
| 180 if(vexpand) { |
|
| 181 row_expanding = true; |
145 row_expanding = true; |
| 182 } |
146 } |
| 183 |
147 |
| 184 if(hexpand) { |
148 if(layout.hexpand) { |
| 185 grid->setColumnStretch(x, 1); |
149 grid->setColumnStretch(x, 1); |
| 186 } |
150 } |
| 187 if(vexpand) { |
151 if(layout.vexpand) { |
| 188 grid->setRowStretch(y, 1); |
152 grid->setRowStretch(y, 1); |
| 189 } |
153 } |
| 190 |
154 |
| 191 Qt::Alignment alignment = 0; |
155 Qt::Alignment alignment = 0; |
| 192 if(!hfill) { |
156 if(!layout.hfill) { |
| 193 alignment = Qt::AlignLeft; |
157 alignment = Qt::AlignLeft; |
| 194 } |
158 } |
| 195 if(!vfill) { |
159 if(!layout.vfill) { |
| 196 alignment = Qt::AlignTop; |
160 alignment = Qt::AlignTop; |
| 197 } |
161 } |
| 198 |
162 |
| 199 int colspan = layout.colspan > 0 ? layout.colspan : 1; |
163 int colspan = layout.colspan > 0 ? layout.colspan : 1; |
| 200 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; |
164 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; |
| 229 } |
192 } |
| 230 } |
193 } |
| 231 |
194 |
| 232 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
195 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) { |
| 233 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); |
196 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); |
| 234 UI_APPLY_LAYOUT(ctn->layout, args); |
197 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 235 |
198 |
| 236 QWidget *widget = new QWidget(); |
199 QWidget *widget = new QWidget(); |
| 237 QGridLayout *grid = new QGridLayout(); |
200 QGridLayout *grid = new QGridLayout(); |
| 238 widget->setLayout(grid); |
201 widget->setLayout(grid); |
| 239 ctn->add(widget); |
202 ctn->add(widget, layout); |
| 240 |
203 |
| 241 ui_container_add(obj, new UiGridContainer( |
204 ui_container_add(obj, new UiGridContainer( |
| 242 grid, |
205 grid, |
| 243 args->margin, |
206 args->margin, |
| 244 args->columnspacing, |
207 args->columnspacing, |