ui/qt/container.h

changeset 103
6606616eca9f
parent 0
2483f517c562
child 108
77254bd6dccb
equal deleted inserted replaced
102:64ded9f6a6c6 103:6606616eca9f
28 28
29 #ifndef CONTAINER_H 29 #ifndef CONTAINER_H
30 #define CONTAINER_H 30 #define CONTAINER_H
31 31
32 #include "toolkit.h" 32 #include "toolkit.h"
33 #include "../ui/container.h"
33 #include "window.h" 34 #include "window.h"
34 35
35 #include <string.h> 36 #include <string.h>
36 #include <QBoxLayout> 37 #include <QBoxLayout>
37 #include <QGridLayout> 38 #include <QGridLayout>
38 #include <QTabWidget> 39 #include <QTabWidget>
39 #include <QStackedWidget> 40 #include <QStackedWidget>
40 #include <QSplitter> 41 #include <QSplitter>
41 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))
42 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE) 54 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
43 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE) 55 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
44 #define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout))
45 56
46 typedef struct UiLayout UiLayout; 57 #define ui_obj_container(obj) (UiContainerPrivate*)((UiContainerX*)obj->container_end)->container
47 58
48 enum UiLayoutBool { 59 typedef enum UiLayoutBool {
49 UI_LAYOUT_UNDEFINED = 0, 60 UI_LAYOUT_UNDEFINED = 0,
50 UI_LAYOUT_TRUE, 61 UI_LAYOUT_TRUE,
51 UI_LAYOUT_FALSE, 62 UI_LAYOUT_FALSE,
52 }; 63 } UiLayoutBool;
53 typedef enum UiLayoutBool UiLayoutBool;
54 64
65 typedef struct UiLayout UiLayout;
55 struct UiLayout { 66 struct UiLayout {
56 UiLayoutBool fill; 67 UiTri fill;
57 bool newline; 68 UiBool newline;
58 char *label; 69 char *label;
59 bool hexpand; 70 UiBool hexpand;
60 bool vexpand; 71 UiBool vexpand;
61 int gridwidth; 72 UiBool hfill;
73 UiBool vfill;
74 UiBool override_defaults;
75 int width;
76 int colspan;
77 int rowspan;
62 }; 78 };
63 79
64 struct UiContainer { 80 struct UiContainerPrivate {
65 UiLayout layout; 81 UiLayout layout;
66 UIWIDGET current; 82 UIWIDGET current;
67 QMenu *menu;
68 83
69 virtual void add(QWidget *widget, bool fill) = 0; 84 virtual void add(QWidget *widget, bool fill) = 0;
85 virtual void end() {}
70 }; 86 };
71 87
72 class UiBoxContainer : public UiContainer { 88 class UiBoxContainer : public UiContainerPrivate {
73 public: 89 public:
74 QBoxLayout *box; 90 QBoxLayout *box;
75 bool hasStretchedWidget = false; 91 bool hasStretchedWidget = false;
76 QSpacerItem *space; 92 QSpacerItem *space;
77 93
78 UiBoxContainer(QBoxLayout *box); 94 UiBoxContainer(QBoxLayout *box);
79 95
80 virtual void add(QWidget *widget, bool fill); 96 virtual void add(QWidget *widget, bool fill);
81 }; 97 };
82 98
83 class UiGridContainer : public UiContainer { 99 class UiGridContainer : public UiContainerPrivate {
84 public: 100 public:
85 QGridLayout *grid; 101 QGridLayout *grid;
86 int x = 0; 102 int x = 0;
87 int y = 0; 103 int y = 0;
104 bool def_hexpand;
105 bool def_vexpand;
106 bool def_hfill;
107 bool def_vfill;
108 bool col_expanding = false;
109 bool row_expanding = false;
110 int max_x;
111 int max_y;
88 112
89 UiGridContainer(QGridLayout *grid, int margin, int columnspacing, int rowspacing); 113 UiGridContainer(
114 QGridLayout *grid,
115 int margin,
116 int columnspacing,
117 int rowspacing,
118 bool def_hexpand,
119 bool def_vexpand,
120 bool def_hfill,
121 bool def_vfill);
90 122
91 virtual void add(QWidget *widget, bool fill); 123 virtual void add(QWidget *widget, bool fill);
124 virtual void end();
92 }; 125 };
93 126
94 class UiTabViewContainer : public UiContainer { 127 void ui_container_add(UiObject *obj, UiContainerPrivate *ct);
95 public:
96 QTabWidget *tabwidget;
97
98 UiTabViewContainer(QTabWidget *tabwidget);
99 virtual void add(QWidget *widget, bool fill);
100 };
101 128
102 class UiStackContainer : public UiContainer {
103 public:
104 QStackedWidget *stack;
105
106 UiStackContainer(QStackedWidget *stack);
107 virtual void add(QWidget *widget, bool fill);
108 };
109
110 class UiSidebarContainer : public UiContainer {
111 public:
112 QSplitter *splitter;
113
114 UiSidebarContainer(QSplitter *splitter);
115 virtual void add(QWidget *widget, bool fill);
116 };
117 129
118 #endif /* CONTAINER_H */ 130 #endif /* CONTAINER_H */
119 131

mercurial