Wed, 07 Jan 2015 20:11:36 +0100
added grid container (Qt)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/qt/container.cpp | file | annotate | diff | comparison | revisions | |
ui/qt/container.h | file | annotate | diff | comparison | revisions | |
ui/qt/window.cpp | file | annotate | diff | comparison | revisions |
--- a/application/main.c Wed Jan 07 17:25:33 2015 +0100 +++ b/application/main.c Wed Jan 07 20:11:36 2015 +0100 @@ -105,23 +105,15 @@ printf("create window\n"); UiObject *window = ui_window("Mod0", NULL); + ui_layout_fill(window, FALSE); + ui_grid(window); + ui_button(window, "Test1________________", action_button, NULL); + ui_button(window, "Test2", action_button, NULL); + ui_newline(window); ui_button(window, "Test1", action_button, NULL); ui_button(window, "Test2", action_button, NULL); - - ui_hbox(window); - - ui_layout_fill(window, FALSE); - ui_vbox(window); - ui_button(window, "A", NULL, NULL); - ui_button(window, "B", NULL, NULL); - ui_button(window, "C", NULL, NULL); ui_end(window); - ui_textarea_nv(window, "text"); - ui_end(window); - - ui_button(window, "Test4", action_button, NULL); - ui_show(window); ui_main();
--- a/ui/qt/container.cpp Wed Jan 07 17:25:33 2015 +0100 +++ b/ui/qt/container.cpp Wed Jan 07 20:11:36 2015 +0100 @@ -57,8 +57,7 @@ QSpacerItem *newspace = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); box->removeItem(space); box->addSpacerItem(newspace); - space = newspace; - + space = newspace; } if(fill) { @@ -91,6 +90,51 @@ +/* -------------------- UiGridContainer -------------------- */ + +UiGridContainer::UiGridContainer(QGridLayout* grid) { + this->grid = grid; + grid->setContentsMargins(QMargins(0,0,0,0)); + grid->setSpacing(0); + ui_reset_layout(layout); +} + +void UiGridContainer::add(QWidget* widget, bool fill) { + if(layout.newline) { + QSpacerItem *s = new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); + grid->addItem(s, y, x); + x = 0; + y++; + } + if(x == 0) { + if(space) { + grid->removeItem(space); + } + QSpacerItem *s = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); + grid->addItem(s, y+1, 0); + space = s; + } + + grid->addWidget(widget, y, x); + x++; + + ui_reset_layout(layout); +} + +UIWIDGET ui_grid(UiObject *obj) { + UiContainer *ct = uic_get_current_container(obj); + QWidget *widget = new QWidget(); + QGridLayout *grid = new QGridLayout(); + widget->setLayout(grid); + ct->add(widget, true); + + UiObject *newobj = uic_object_new(obj, widget); + newobj->container = new UiGridContainer(grid); + uic_obj_add(obj, newobj); + + return widget; +} + /* -------------------- layout functions -------------------- */ @@ -98,3 +142,8 @@ UiContainer *ct = uic_get_current_container(obj); ct->layout.fill = ui_bool2lb(fill); } + +void ui_newline(UiObject *obj) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.newline = TRUE; +}
--- a/ui/qt/container.h Wed Jan 07 17:25:33 2015 +0100 +++ b/ui/qt/container.h Wed Jan 07 20:11:36 2015 +0100 @@ -34,6 +34,7 @@ #include <string.h> #include <QBoxLayout> +#include <QGridLayout> #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE) #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE) @@ -50,6 +51,7 @@ struct UiLayout { UiLayoutBool fill; + bool newline; }; struct UiContainer { @@ -69,5 +71,17 @@ virtual void add(QWidget *widget, bool fill); }; +class UiGridContainer : public UiContainer { +public: + QGridLayout *grid; + int x = 0; + int y = 0; + QSpacerItem *space = NULL; + + UiGridContainer(QGridLayout *grid); + + virtual void add(QWidget *widget, bool fill); +}; + #endif /* CONTAINER_H */
--- a/ui/qt/window.cpp Wed Jan 07 17:25:33 2015 +0100 +++ b/ui/qt/window.cpp Wed Jan 07 20:11:36 2015 +0100 @@ -51,7 +51,6 @@ QToolBar *toolbar = ui_create_toolbar(obj); window->addToolBar(Qt::TopToolBarArea, toolbar); - //QBoxLayout *box = new QBoxLayout(QBoxLayout::TopToBottom); QBoxLayout *box = new QVBoxLayout(); QWidget *boxWidget = new QWidget(); boxWidget->setLayout(box);