ui/qt/container.cpp

changeset 108
77254bd6dccb
parent 103
6606616eca9f
child 109
c3dfcb8f0be7
equal deleted inserted replaced
107:b34bd1557c6c 108:77254bd6dccb
58 box->setSpacing(0); 58 box->setSpacing(0);
59 59
60 ui_reset_layout(layout); 60 ui_reset_layout(layout);
61 } 61 }
62 62
63 void UiBoxContainer::add(QWidget* widget, bool fill) { 63 void UiBoxContainer::add(QWidget* widget) {
64 if(layout.fill != UI_LAYOUT_UNDEFINED) { 64 bool fill = layout.fill;
65 fill = ui_lb2bool(layout.fill);
66 }
67
68 if(hasStretchedWidget && fill) { 65 if(hasStretchedWidget && fill) {
69 fill = false; 66 fill = false;
70 fprintf(stderr, "UiError: container has 2 filled widgets"); 67 fprintf(stderr, "UiError: container has 2 filled widgets");
71 } 68 }
72 69
73 box->addWidget(widget, fill); 70 box->addWidget(widget);
74 71
75 if(!hasStretchedWidget) { 72 if(!hasStretchedWidget) {
76 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); 73 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
77 box->removeItem(space); 74 box->removeItem(space);
78 box->addSpacerItem(newspace); 75 box->addSpacerItem(newspace);
84 } 81 }
85 ui_reset_layout(layout); 82 ui_reset_layout(layout);
86 current = widget; 83 current = widget;
87 } 84 }
88 85
89 UIWIDGET ui_box(UiObject *obj, UiContainerArgs args, QBoxLayout::Direction dir) { 86 UIWIDGET ui_box(UiObject *obj, UiContainerArgs *args, QBoxLayout::Direction dir) {
90 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); 87 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
91 UI_APPLY_LAYOUT(ctn->layout, args); 88 UI_APPLY_LAYOUT(ctn->layout, args);
92 89
93 QWidget *widget = new QWidget(); 90 QWidget *widget = new QWidget();
94 QBoxLayout *box = new QBoxLayout(dir); 91 QBoxLayout *box = new QBoxLayout(dir);
95 widget->setLayout(box); 92 widget->setLayout(box);
96 ctn->add(widget, true); 93 ctn->add(widget);
97 94
98 ui_container_add(obj, new UiBoxContainer(box)); 95 ui_container_add(obj, new UiBoxContainer(box));
99 96
100 return widget; 97 return widget;
101 } 98 }
102 99
103 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) { 100 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) {
104 return ui_box(obj, args, QBoxLayout::TopToBottom); 101 return ui_box(obj, args, QBoxLayout::TopToBottom);
105 } 102 }
106 103
107 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) { 104 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs *args) {
108 return ui_box(obj, args, QBoxLayout::LeftToRight); 105 return ui_box(obj, args, QBoxLayout::LeftToRight);
109 } 106 }
110 107
111 108
112 /* -------------------- UiGridContainer -------------------- */ 109 /* -------------------- UiGridContainer -------------------- */
131 grid->setHorizontalSpacing(columnspacing); 128 grid->setHorizontalSpacing(columnspacing);
132 grid->setVerticalSpacing(rowspacing); 129 grid->setVerticalSpacing(rowspacing);
133 ui_reset_layout(layout); 130 ui_reset_layout(layout);
134 } 131 }
135 132
136 void UiGridContainer::add(QWidget* widget, bool fill) { 133 void UiGridContainer::add(QWidget* widget) {
137 if(layout.newline) { 134 if(layout.newline) {
138 x = 0; 135 x = 0;
139 y++; 136 y++;
140 } 137 }
141 138
142 int hexpand = false; 139 bool fill = layout.fill;
143 int vexpand = false; 140 bool hexpand = false;
144 int hfill = false; 141 bool vexpand = false;
145 int vfill = false; 142 bool hfill = false;
143 bool vfill = false;
146 if(!layout.override_defaults) { 144 if(!layout.override_defaults) {
147 if(def_hexpand) { 145 if(def_hexpand) {
148 hexpand = true; 146 hexpand = true;
149 hfill = true; 147 hfill = true;
150 } else if(def_hfill) { 148 } else if(def_hfill) {
156 } else if(def_vfill) { 154 } else if(def_vfill) {
157 vfill = true; 155 vfill = true;
158 } 156 }
159 } 157 }
160 158
161 if(layout.fill != UI_LAYOUT_UNDEFINED) {
162 fill = ui_lb2bool(layout.fill);
163 }
164 if(layout.hexpand) { 159 if(layout.hexpand) {
165 hexpand = true; 160 hexpand = true;
166 //hfill = true; 161 //hfill = true;
167 } else if(layout.hfill) { 162 } else if(layout.hfill) {
168 hfill = true; 163 hfill = true;
231 grid->setRowStretch(y, 1); 226 grid->setRowStretch(y, 1);
232 grid->addItem(filler, y, 0, 1, 1, 0); 227 grid->addItem(filler, y, 0, 1, 1, 0);
233 } 228 }
234 } 229 }
235 230
236 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) { 231 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs *args) {
237 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); 232 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
238 UI_APPLY_LAYOUT(ctn->layout, args); 233 UI_APPLY_LAYOUT(ctn->layout, args);
239 234
240 QWidget *widget = new QWidget(); 235 QWidget *widget = new QWidget();
241 QGridLayout *grid = new QGridLayout(); 236 QGridLayout *grid = new QGridLayout();
242 widget->setLayout(grid); 237 widget->setLayout(grid);
243 ctn->add(widget, true); 238 ctn->add(widget);
244 239
245 ui_container_add(obj, new UiGridContainer( 240 ui_container_add(obj, new UiGridContainer(
246 grid, 241 grid,
247 args.margin, 242 args->margin,
248 args.columnspacing, 243 args->columnspacing,
249 args.rowspacing, 244 args->rowspacing,
250 args.def_hexpand, 245 args->def_hexpand,
251 args.def_vexpand, 246 args->def_vexpand,
252 args.def_hfill, 247 args->def_hfill,
253 args.def_vfill)); 248 args->def_vfill));
254 249
255 return widget; 250 return widget;
256 } 251 }
257 252
258 253

mercurial