ui/qt/container.cpp

changeset 525
878df45e6441
parent 522
bb0d05f45046
child 526
f6a6b0b08641
equal deleted inserted replaced
524:ce7a198b54b0 525:878df45e6441
32 32
33 #include <cx/mempool.h> 33 #include <cx/mempool.h>
34 34
35 #include <QSpacerItem> 35 #include <QSpacerItem>
36 #include <QStackedWidget> 36 #include <QStackedWidget>
37 #include <QLabel>
37 38
38 static void delete_container(UiContainerPrivate *ct) { 39 static void delete_container(UiContainerPrivate *ct) {
39 delete ct; 40 delete ct;
40 } 41 }
41 42
108 } 109 }
109 110
110 111
111 /* -------------------- UiGridContainer -------------------- */ 112 /* -------------------- UiGridContainer -------------------- */
112 113
113 UiGridContainer::UiGridContainer(QGridLayout* grid, int margin, int columnspacing, int rowspacing) { 114 UiGridContainer::UiGridContainer(
115 QGridLayout *grid,
116 int margin,
117 int columnspacing,
118 int rowspacing,
119 bool def_hexpand,
120 bool def_vexpand,
121 bool def_hfill,
122 bool def_vfill)
123 {
114 this->current = NULL; 124 this->current = NULL;
115 this->grid = grid; 125 this->grid = grid;
126 this->def_hexpand = def_hexpand;
127 this->def_vexpand = def_vexpand;
128 this->def_hfill = def_hfill;
129 this->def_vfill = def_vfill;
116 grid->setContentsMargins(QMargins(margin, margin, margin, margin)); 130 grid->setContentsMargins(QMargins(margin, margin, margin, margin));
117 grid->setHorizontalSpacing(columnspacing); 131 grid->setHorizontalSpacing(columnspacing);
118 grid->setVerticalSpacing(rowspacing); 132 grid->setVerticalSpacing(rowspacing);
119 ui_reset_layout(layout); 133 ui_reset_layout(layout);
120 } 134 }
123 if(layout.newline) { 137 if(layout.newline) {
124 x = 0; 138 x = 0;
125 y++; 139 y++;
126 } 140 }
127 141
128 Qt::Alignment alignment = Qt::AlignTop; 142 int hexpand = false;
129 grid->setColumnStretch(x, layout.hexpand ? 1 : 0); 143 int vexpand = false;
144 int hfill = false;
145 int vfill = false;
146 if(!layout.override_defaults) {
147 if(def_hexpand) {
148 hexpand = true;
149 hfill = true;
150 } else if(def_hfill) {
151 hfill = true;
152 }
153 if(def_vexpand) {
154 vexpand = true;
155 vfill = true;
156 } else if(def_vfill) {
157 vfill = true;
158 }
159 }
160
161 if(layout.fill != UI_LAYOUT_UNDEFINED) {
162 fill = ui_lb2bool(layout.fill);
163 }
164 if(layout.hexpand) {
165 hexpand = true;
166 //hfill = true;
167 } else if(layout.hfill) {
168 hfill = true;
169 }
130 if(layout.vexpand) { 170 if(layout.vexpand) {
171 vexpand = true;
172 //vfill = true;
173 } else if(layout.vfill) {
174 vfill = true;
175 }
176 if(fill) {
177 hfill = true;
178 vfill = true;
179 }
180
181 if(hexpand) {
182 col_expanding = true;
183 }
184 if(vexpand) {
185 row_expanding = true;
186 }
187
188 if(hexpand) {
189 grid->setColumnStretch(x, 1);
190 }
191 if(vexpand) {
131 grid->setRowStretch(y, 1); 192 grid->setRowStretch(y, 1);
132 alignment = 0; 193 }
133 } else { 194
134 grid->setRowStretch(y, 0); 195 Qt::Alignment alignment = 0;
196 if(!hfill) {
197 alignment = Qt::AlignLeft;
198 }
199 if(!vfill) {
200 alignment = Qt::AlignTop;
135 } 201 }
136 202
137 int colspan = layout.colspan > 0 ? layout.colspan : 1; 203 int colspan = layout.colspan > 0 ? layout.colspan : 1;
138 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1; 204 int rowspan = layout.rowspan > 0 ? layout.rowspan : 1;
139 205
140 grid->addWidget(widget, y, x, rowspan, colspan, alignment); 206 grid->addWidget(widget, y, x, rowspan, colspan, alignment);
207
208 if(x > max_x) {
209 max_x = x;
210 }
211 if(y > max_y) {
212 max_y = y;
213 }
214
141 x += colspan; 215 x += colspan;
142 216
143 ui_reset_layout(layout); 217 ui_reset_layout(layout);
144 current = widget; 218 current = widget;
219 }
220
221 void UiGridContainer::end() {
222 if(!col_expanding) {
223 QLabel *filler = new QLabel("");
224 x = max_x + 1;
225 grid->setColumnStretch(x, 1);
226 grid->addWidget(filler, 0, x, 1, 1, 0);
227 }
228 if(!row_expanding) {
229 QLabel *filler = new QLabel("");
230 y++;
231 grid->setRowStretch(y, 1);
232 grid->addWidget(filler, y, 0, 1, 1, 0);
233 }
145 } 234 }
146 235
147 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) { 236 UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
148 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj); 237 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
149 UI_APPLY_LAYOUT(ctn->layout, args); 238 UI_APPLY_LAYOUT(ctn->layout, args);
151 QWidget *widget = new QWidget(); 240 QWidget *widget = new QWidget();
152 QGridLayout *grid = new QGridLayout(); 241 QGridLayout *grid = new QGridLayout();
153 widget->setLayout(grid); 242 widget->setLayout(grid);
154 ctn->add(widget, true); 243 ctn->add(widget, true);
155 244
156 ui_container_add(obj, new UiGridContainer(grid, args.margin, args.columnspacing, args.rowspacing)); 245 ui_container_add(obj, new UiGridContainer(
246 grid,
247 args.margin,
248 args.columnspacing,
249 args.rowspacing,
250 args.def_hexpand,
251 args.def_vexpand,
252 args.def_hfill,
253 args.def_vfill));
157 254
158 return widget; 255 return widget;
159 } 256 }
160 257
161 258
166 obj->container_end->close = true; 263 obj->container_end->close = true;
167 } 264 }
168 265
169 int ui_container_finish(UiObject *obj) { 266 int ui_container_finish(UiObject *obj) {
170 if(obj->container_end->close) { 267 if(obj->container_end->close) {
268 UiContainerPrivate *ctn = (UiContainerPrivate*)obj->container_end->container;
269 ctn->end();
171 ui_end_new(obj); 270 ui_end_new(obj);
172 return 0; 271 return 0;
173 } 272 }
174 return 1; 273 return 1;
175 } 274 }

mercurial