ui/qt/container.cpp

changeset 519
8884c7fbe4cb
parent 516
4b31c74666d7
child 520
ea1bba55de44
equal deleted inserted replaced
518:45ed276ba7a4 519:8884c7fbe4cb
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
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"
32
33 #include <cx/mempool.h>
31 34
32 #include <QSpacerItem> 35 #include <QSpacerItem>
33 #include <QStackedWidget> 36 #include <QStackedWidget>
34 37
38 static void delete_container(UiContainerPrivate *ct) {
39 delete ct;
40 }
35 41
42 static void add_container(UiObject *obj, UiContainerPrivate *ct) {
43 UiContainerX *container = (UiContainerX*)ui_malloc(obj->ctx, sizeof(UiContainerX));
44 container->close = 0;
45 container->container = ct;
46 container->prev = NULL;
47 container->next = NULL;
48 cxMempoolRegister(obj->ctx->mp, ct, (cx_destructor_func)delete_container);
49 uic_object_push_container(obj, container);
50 }
51
52 /* -------------------- UiBoxContainer -------------------- */
53
54 UiBoxContainer::UiBoxContainer(QBoxLayout* box) {
55 this->box = box;
56 box->setContentsMargins(QMargins(0,0,0,0));
57 box->setSpacing(0);
58
59 ui_reset_layout(layout);
60 }
61
62 void UiBoxContainer::add(QWidget* widget, bool fill) {
63 if(layout.fill != UI_LAYOUT_UNDEFINED) {
64 fill = ui_lb2bool(layout.fill);
65 }
66
67 if(hasStretchedWidget && fill) {
68 fill = false;
69 fprintf(stderr, "UiError: container has 2 filled widgets");
70 }
71
72 box->addWidget(widget, fill);
73
74 if(!hasStretchedWidget) {
75 QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
76 box->removeItem(space);
77 box->addSpacerItem(newspace);
78 space = newspace;
79 }
80
81 if(fill) {
82 hasStretchedWidget = true;
83 }
84 ui_reset_layout(layout);
85 current = widget;
86 }
87
88 UIWIDGET ui_box(UiObject *obj, UiContainerArgs args, QBoxLayout::Direction dir) {
89 UiContainerPrivate *ctn = (UiContainerPrivate*)ui_obj_container(obj);
90 UI_APPLY_LAYOUT(ctn->layout, args);
91
92 QWidget *widget = new QWidget();
93 QBoxLayout *box = new QBoxLayout(dir);
94 widget->setLayout(box);
95 ctn->add(widget, true);
96
97
98
99 return widget;
100 }
101
102 UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args) {
103 return ui_box(obj, args, QBoxLayout::TopToBottom);
104 }
105
106 UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) {
107 return ui_box(obj, args, QBoxLayout::LeftToRight);
108 }

mercurial