ui/qt/container.h

changeset 112
c3f2f16fa4b8
parent 108
77254bd6dccb
equal deleted inserted replaced
111:81c4f73236a4 112:c3f2f16fa4b8
38 #include <QGridLayout> 38 #include <QGridLayout>
39 #include <QTabWidget> 39 #include <QTabWidget>
40 #include <QStackedWidget> 40 #include <QStackedWidget>
41 #include <QSplitter> 41 #include <QSplitter>
42 42
43 #define UI_APPLY_LAYOUT(layout, args) \
44 layout.fill = args->fill; \
45 layout.hexpand = args->hexpand; \
46 layout.vexpand = args->vexpand; \
47 layout.hfill = args->hfill; \
48 layout.vfill = args->vfill; \
49 layout.override_defaults = args->override_defaults; \
50 layout.colspan = args->colspan; \
51 layout.rowspan = args->rowspan
52
53 #define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout))
54 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
55 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
56
57 #define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container 43 #define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container
58 44
59 typedef enum UiLayoutBool { 45 struct UiContainerPrivate {
60 UI_LAYOUT_UNDEFINED = 0, 46 UIWIDGET current;
61 UI_LAYOUT_TRUE, 47 UiContainerX *container;
62 UI_LAYOUT_FALSE,
63 } UiLayoutBool;
64 48
65 typedef struct UiLayout UiLayout; 49 virtual void add(QWidget *widget, UiLayout& layout) = 0;
66 struct UiLayout {
67 UiBool fill;
68 UiBool newline;
69 char *label;
70 UiBool hexpand;
71 UiBool vexpand;
72 UiBool hfill;
73 UiBool vfill;
74 UiBool override_defaults;
75 int width;
76 int colspan;
77 int rowspan;
78 };
79
80 struct UiContainerPrivate {
81 UiLayout layout;
82 UIWIDGET current;
83
84 virtual void add(QWidget *widget) = 0;
85 virtual void end() {} 50 virtual void end() {}
86 }; 51 };
87 52
88 class UiBoxContainer : public UiContainerPrivate { 53 class UiBoxContainer : public UiContainerPrivate {
89 public: 54 public:
90 QBoxLayout *box; 55 QBoxLayout *box;
91 bool hasStretchedWidget = false; 56 bool hasStretchedWidget = false;
92 QSpacerItem *space; 57 QSpacerItem *space;
58 QBoxLayout::Direction direction;
93 59
94 UiBoxContainer(QBoxLayout *box); 60 UiBoxContainer(QBoxLayout *box);
95 61
96 virtual void add(QWidget *widget); 62 virtual void add(QWidget *widget, UiLayout& layout);
97 }; 63 };
98 64
99 class UiGridContainer : public UiContainerPrivate { 65 class UiGridContainer : public UiContainerPrivate {
100 public: 66 public:
101 QGridLayout *grid; 67 QGridLayout *grid;
118 bool def_hexpand, 84 bool def_hexpand,
119 bool def_vexpand, 85 bool def_vexpand,
120 bool def_hfill, 86 bool def_hfill,
121 bool def_vfill); 87 bool def_vfill);
122 88
123 virtual void add(QWidget *widget); 89 virtual void add(QWidget *widget, UiLayout& layout);
124 virtual void end(); 90 virtual void end();
125 }; 91 };
126 92
127 void ui_container_add(UiObject *obj, UiContainerPrivate *ct); 93 void ui_obj_add_container(UiObject *obj, UiContainerPrivate *ct);
94
95 QWidget* ui_widget_set_margin(QWidget *w, int left, int right, int top, int bottom);
128 96
129 97
130 #endif /* CONTAINER_H */ 98 #endif /* CONTAINER_H */
131 99

mercurial